Skip to content

Commit bd9e40d

Browse files
authored
feat: full rewrite with async support, pydantic v2 and modern architecture (#72)
* feat(core): rewrite Capmonster client with Pydantic v2 and modern Python features - Replaced legacy procedural structure with fully typed class-based design - Introduced Pydantic v2 models with field validation, serialization, and aliasing - Implemented sync and async Capmonster clients using httpx - Added extensible BaseTaskPayload structure with abstract to_request() - Included validator and field_serializer usage for dynamic task behavior - Flattened proxy structure via smart task serialization - Applied frozen and immutable model config where applicable - Full support for Literal, Optional etc. - Some test cases prepared with pytest + pytest-asyncio - Ready for mkdocs documentation generation BREAKING CHANGE: API usage has completely changed from v3.2 to v4.0. All task creation methods now rely on structured payloads and typed clients. * build: migrate to PEP 621-compatible pyproject.toml and restructure project - Replaced setup.py and setup.cfg with pyproject.toml for a modern build system. Updated project structure to align with the src directory convention. Adjusted imports, examples, and documentation for the updated layout and dependency changes. * docs: remove old markdown and add structured API documentation Removed outdated CODE-OF-CONDUCT.md and README.md files. Introduced a detailed, structured API reference and examples using MkDocs format. Includes documentation for tasks, exceptions, error codes, and usage examples in both synchronous and asynchronous modes. * chore: remove outdated examples and improve the project structure * ci: add new tests and CI setup for capmonster tasks
1 parent ac2ba72 commit bd9e40d

File tree

121 files changed

+2741
-14088
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+2741
-14088
lines changed

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# .editorconfig
2+
root = true
3+
4+
[*]
5+
end_of_line = lf
6+
insert_final_newline = true

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,20 @@ assignees: alperensert
1010
**Describe the bug**
1111
A clear and concise description of what the bug is.
1212

13-
**To Reproduce**
14-
Steps to reproduce the behavior:
15-
1. Go to '...'
16-
2. Click on '....'
17-
3. Scroll down to '....'
18-
4. See error
19-
2013
**Expected behavior**
2114
A clear and concise description of what you expected to happen.
2215

2316
**Screenshots**
2417
If applicable, add screenshots to help explain your problem.
2518

2619
**Desktop (please complete the following information):**
27-
- OS: [e.g. iOS]
28-
- Browser [e.g. chrome, safari]
29-
- Version [e.g. 22]
20+
21+
- OS: [e.g. iOS]
22+
- Browser [e.g. chrome, safari]
23+
- Version [e.g. 22]
3024

3125
**Simplified error traceback (if you have)**
26+
3227
- Directory: [e.g main]
3328
- File: [e.g recaptcha_v2.py]
3429
- Line(s): [e.g 30, 66, 82]

.github/ISSUE_TEMPLATE/help-wanted.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ assignees: ''
88
---
99

1010
**Your purpose**
11-
Are you trying to pass a web site protection or can't find the required keys? Can't submit the captcha? Or something else.. Please explain it in here.
11+
Are you trying to pass website protection or can't find the required keys? Can't submit the captcha? Or something else.
12+
Please explain it in here.
1213

1314
**Highly required informations**
14-
- Web site url (where placed the captcha)
15+
16+
- Website url (where placed the captcha)
1517

1618
**Things you've tried**
1719
The followed way to solve your problem. Explain it briefly, like I changed ... to ... but it doesn't worked
1820

19-
**Do not forget**
20-
90% of help requests was about submitting captcha in web sites. In this cases, please take a look at to **examples**
21+
**Remember**
22+
90% of help requests were about submitting captcha in websites. In this case, please take a look at to **docs**.

.github/dependabot.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
version: 2
22
updates:
33
- package-ecosystem: "pip"
4-
directory: "/capmonster_python"
5-
schedule:
6-
interval: "daily"
7-
- package-ecosystem: "npm"
8-
directory: "/docs"
4+
directory: "/src/capmonster_python"
95
schedule:
106
interval: "weekly"
11-
ignore:
12-
- dependency-name: "*"

.github/workflows/ghpages.yml

Lines changed: 16 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
name: Deploy Gatsby Documentation to Pages
1+
name: Deploy MkDocs to GitHub Pages
22

33
on:
44
push:
5-
branches: ["master"]
5+
branches: [ "master" ]
66
paths:
77
- docs/**
88
workflow_dispatch:
99

1010
permissions:
11-
contents: read
11+
contents: write
1212
pages: write
1313
id-token: write
1414

@@ -22,67 +22,22 @@ defaults:
2222
working-directory: docs
2323

2424
jobs:
25-
build:
25+
deploy:
2626
runs-on: ubuntu-latest
27+
2728
steps:
28-
- name: Checkout
29+
- name: Checkout repository
2930
uses: actions/checkout@v3
30-
- name: Detect package manager
31-
id: detect-package-manager
32-
run: |
33-
if [ -f "yarn.lock" ]; then
34-
echo "manager=yarn" >> $GITHUB_OUTPUT
35-
echo "command=install" >> $GITHUB_OUTPUT
36-
echo "file=**/yarn.lock" >> $GITHUB_OUTPUT
37-
exit 0
38-
elif [ -f "package.json" ]; then
39-
echo "manager=npm" >> $GITHUB_OUTPUT
40-
echo "command=ci" >> $GITHUB_OUTPUT
41-
echo "file=**/package.json" >> $GITHUB_OUTPUT
42-
exit 0
43-
else
44-
echo "Unable to determine packager manager"
45-
exit 1
46-
fi
47-
- name: Setup Node
48-
uses: actions/setup-node@v3
49-
with:
50-
node-version: "18"
51-
cache: ${{ steps.detect-package-manager.outputs.manager }}
52-
cache-dependency-path: ${{ steps.detect-package-manager.outputs.file }}
53-
54-
- name: Setup Pages
55-
id: pages
56-
uses: actions/configure-pages@v2
57-
with:
58-
static_site_generator: gatsby
59-
- name: Restore cache
60-
uses: actions/cache@v3
31+
32+
- name: Set up Python
33+
uses: actions/setup-python@v4
6134
with:
62-
path: |
63-
public
64-
.cache
65-
key: ${{ runner.os }}-gatsby-build-${{ hashFiles('public') }}
66-
restore-keys: |
67-
${{ runner.os }}-gatsby-build-
35+
python-version: '3.10'
36+
6837
- name: Install dependencies
69-
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }}
70-
- name: Build with Gatsby
71-
env:
72-
PREFIX_PATHS: 'true'
73-
run: ${{ steps.detect-package-manager.outputs.manager }} run build
74-
- name: Upload artifact
75-
uses: actions/upload-pages-artifact@v1
76-
with:
77-
path: ./docs/public
38+
run: |
39+
pip install mkdocs mkdocs-material mkdocstrings[python]
7840
79-
deploy:
80-
environment:
81-
name: github-pages
82-
url: ${{ steps.deployment.outputs.page_url }}
83-
runs-on: ubuntu-latest
84-
needs: build
85-
steps:
86-
- name: Deploy to GitHub Pages
87-
id: deployment
88-
uses: actions/deploy-pages@v1
41+
- name: Build and deploy
42+
run: |
43+
mkdocs gh-deploy --force

.github/workflows/publish.yml

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,37 @@ name: Publish Python Package 🐍
22

33
on:
44
release:
5-
types: [published]
5+
types: [ published ]
66

77
jobs:
88
deploy:
9-
109
runs-on: ubuntu-latest
1110

1211
steps:
13-
- uses: actions/checkout@v3
14-
- name: Set up Python
15-
uses: actions/setup-python@v3
16-
with:
17-
python-version: "3.9"
18-
19-
- name: Install setup dependencies
20-
run: make setup_dependencies
21-
22-
- name: Install dependencies
23-
run: make build
24-
25-
- name: Build package
26-
run: python -m build
27-
28-
- name: Publish package to TestPYPI
29-
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
30-
with:
31-
user: __token__
32-
password: ${{ secrets.TEST_PYPI_TOKEN }}
33-
repository_url: https://test.pypi.org/legacy/
34-
35-
- name: Publish package to PYPI
36-
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
37-
with:
38-
user: __token__
39-
password: ${{ secrets.PYPI_TOKEN }}
12+
- uses: actions/checkout@v3
13+
- name: Set up Python
14+
uses: actions/setup-python@v3
15+
with:
16+
python-version: "3.10"
17+
18+
- name: Install setup dependencies
19+
run: make setup_dependencies
20+
21+
- name: Install dependencies
22+
run: make build
23+
24+
- name: Build package
25+
run: python -m build
26+
27+
- name: Publish package to TestPYPI
28+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
29+
with:
30+
user: __token__
31+
password: ${{ secrets.TEST_PYPI_TOKEN }}
32+
repository_url: https://test.pypi.org/legacy/
33+
34+
- name: Publish package to PYPI
35+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
36+
with:
37+
user: __token__
38+
password: ${{ secrets.PYPI_TOKEN }}

.github/workflows/tests.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Run Pytest Tests
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
paths:
7+
- "tests/**"
8+
- ".github/workflows/test.yml"
9+
- "**.py"
10+
pull_request:
11+
branches: [ "master" ]
12+
workflow_dispatch:
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
18+
env:
19+
API_KEY: ${{ secrets.API_KEY }}
20+
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v3
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: '3.10'
29+
30+
- name: Install dependencies
31+
run: |
32+
pip install -r requirements.txt
33+
pip install pytest
34+
35+
- name: Run tests
36+
run: |
37+
pytest tests/

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
**/.cache
44
**/node_modules
55
**/.DS_Store
6-
**/.venv
6+
**/.venv
7+
**/site
8+
**/dist
9+
**/*.egg-info

CODE-OF-CONDUCT.md

Lines changed: 0 additions & 51 deletions
This file was deleted.

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,5 @@ install_pkg:
1111
python -m pip install --upgrade pip wheel
1212
pip install .
1313

14-
test:
15-
python -m unittest -v tests/test_tasks.py
16-
1714
setup_dependencies:
1815
pip install setuptools_scm wheel

0 commit comments

Comments
 (0)