novelcaptcha 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- novelcaptcha-0.1.0/.gitignore +52 -0
- novelcaptcha-0.1.0/LICENSE +21 -0
- novelcaptcha-0.1.0/PKG-INFO +139 -0
- novelcaptcha-0.1.0/README.md +104 -0
- novelcaptcha-0.1.0/novelcaptcha/__init__.py +54 -0
- novelcaptcha-0.1.0/novelcaptcha/client.py +623 -0
- novelcaptcha-0.1.0/novelcaptcha/errors.py +60 -0
- novelcaptcha-0.1.0/novelcaptcha/fastapi.py +95 -0
- novelcaptcha-0.1.0/novelcaptcha/flask.py +100 -0
- novelcaptcha-0.1.0/novelcaptcha/types.py +75 -0
- novelcaptcha-0.1.0/pyproject.toml +59 -0
- novelcaptcha-0.1.0/tests/test_client.py +85 -0
- novelcaptcha-0.1.0/tests/test_retry.py +273 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
references/
|
|
4
|
+
|
|
5
|
+
# Build outputs
|
|
6
|
+
backend/app/static/api.js
|
|
7
|
+
backend/app/static/nld.js
|
|
8
|
+
backend/app/static/challenge.js
|
|
9
|
+
backend/app/static/wasm_exec.js
|
|
10
|
+
backend/app/static/captcha.wasm
|
|
11
|
+
|
|
12
|
+
# WASM build artifacts
|
|
13
|
+
# NOTE: widget/nld.wasm is NOT used. The real WASM is compiled by build-widget.mjs,
|
|
14
|
+
# AES-GCM encrypted, and embedded directly into nld-worker.js (EMBEDDED_WASM_CHUNKS).
|
|
15
|
+
# The output goes to backend/app/static/novel.wasm (used only for wasm-opt in prod).
|
|
16
|
+
widget/nld.wasm
|
|
17
|
+
widget/rust-core/target/
|
|
18
|
+
backend/app/static/novel.wasm
|
|
19
|
+
|
|
20
|
+
# Python
|
|
21
|
+
__pycache__/
|
|
22
|
+
*.py[cod]
|
|
23
|
+
*.pyo
|
|
24
|
+
.venv/
|
|
25
|
+
venv/
|
|
26
|
+
*.egg-info/
|
|
27
|
+
|
|
28
|
+
# Test artifacts
|
|
29
|
+
test-results/
|
|
30
|
+
artifacts/
|
|
31
|
+
|
|
32
|
+
# Misc
|
|
33
|
+
*.log
|
|
34
|
+
.DS_Store
|
|
35
|
+
Thumbs.db
|
|
36
|
+
certs/
|
|
37
|
+
.dual-graph/
|
|
38
|
+
tmp*/
|
|
39
|
+
backend/app/debug_signals/
|
|
40
|
+
|
|
41
|
+
# Operator-refreshed IP intelligence data (large; populated by
|
|
42
|
+
# tools/refresh_intel_data.py). The bundled `static/` bootstrap stays in git.
|
|
43
|
+
backend/app/services/intelligence/data/dynamic/
|
|
44
|
+
|
|
45
|
+
# Local planning artifacts (harness convention; never product)
|
|
46
|
+
local/
|
|
47
|
+
|
|
48
|
+
# Runtime/SDK logs and ephemeral telemetry directories
|
|
49
|
+
log/
|
|
50
|
+
|
|
51
|
+
# BrowserStack SDK + Playwright temp configs
|
|
52
|
+
*.temp.json
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) NovelCaptcha contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: novelcaptcha
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python server SDK for NovelCaptcha. Verify tokens and classify emails.
|
|
5
|
+
Project-URL: Homepage, https://github.com/novelfoss/captcha
|
|
6
|
+
Project-URL: Repository, https://github.com/novelfoss/captcha
|
|
7
|
+
Project-URL: Issues, https://github.com/novelfoss/captcha/issues
|
|
8
|
+
Author: NovelCaptcha
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: bot-detection,captcha,fraud,novelcaptcha,server-sdk
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
21
|
+
Classifier: Topic :: Security
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Requires-Dist: httpx>=0.24
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: mypy>=1.7; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-httpx>=0.26; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff>=0.4; extra == 'dev'
|
|
30
|
+
Provides-Extra: fastapi
|
|
31
|
+
Requires-Dist: fastapi>=0.100; extra == 'fastapi'
|
|
32
|
+
Provides-Extra: flask
|
|
33
|
+
Requires-Dist: flask>=2.3; extra == 'flask'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# novelcaptcha
|
|
37
|
+
|
|
38
|
+
Python server SDK for [NovelCaptcha](https://github.com/novelfoss/captcha). Sync + async clients, plus drop-in FastAPI and Flask middleware.
|
|
39
|
+
|
|
40
|
+
## Install
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install novelcaptcha
|
|
44
|
+
# with framework helpers:
|
|
45
|
+
pip install 'novelcaptcha[fastapi]'
|
|
46
|
+
pip install 'novelcaptcha[flask]'
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from novelcaptcha import NovelCaptcha
|
|
53
|
+
|
|
54
|
+
client = NovelCaptcha(
|
|
55
|
+
secret_key="sec_...",
|
|
56
|
+
base_url="http://localhost:3020", # omit for SaaS
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
result = client.verify(token, remote_ip="203.0.113.5")
|
|
60
|
+
if result.score < 0.5:
|
|
61
|
+
raise PermissionError("score too low")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Async
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from novelcaptcha import AsyncNovelCaptcha
|
|
68
|
+
|
|
69
|
+
async with AsyncNovelCaptcha(secret_key="sec_...") as client:
|
|
70
|
+
result = await client.verify(token)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## FastAPI
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
from fastapi import FastAPI, Depends
|
|
77
|
+
from novelcaptcha import AsyncNovelCaptcha
|
|
78
|
+
from novelcaptcha.fastapi import verify_captcha
|
|
79
|
+
|
|
80
|
+
app = FastAPI()
|
|
81
|
+
|
|
82
|
+
@app.on_event("startup")
|
|
83
|
+
async def on_startup():
|
|
84
|
+
app.state.novelcaptcha = AsyncNovelCaptcha(secret_key="sec_...")
|
|
85
|
+
|
|
86
|
+
@app.post("/login")
|
|
87
|
+
async def login(captcha = verify_captcha(token_field="captcha_token", min_score=0.5)):
|
|
88
|
+
# captcha is the VerifyResult — only reached when score >= 0.5
|
|
89
|
+
return {"visitor_id": captcha.visitor_id}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Flask
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from flask import Flask, request
|
|
96
|
+
from novelcaptcha import NovelCaptcha
|
|
97
|
+
from novelcaptcha.flask import novelcaptcha_required
|
|
98
|
+
|
|
99
|
+
app = Flask(__name__)
|
|
100
|
+
app.extensions["novelcaptcha"] = NovelCaptcha(secret_key="sec_...")
|
|
101
|
+
|
|
102
|
+
@app.post("/login")
|
|
103
|
+
@novelcaptcha_required(token_field="captcha_token", min_score=0.5)
|
|
104
|
+
def login():
|
|
105
|
+
result = request.novelcaptcha
|
|
106
|
+
return {"visitor_id": result.visitor_id}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## API
|
|
110
|
+
|
|
111
|
+
### `NovelCaptcha(secret_key, *, base_url=..., timeout=10.0)`
|
|
112
|
+
|
|
113
|
+
Sync client. `AsyncNovelCaptcha` has the same constructor signature.
|
|
114
|
+
|
|
115
|
+
### `client.verify(token, *, remote_ip=None) -> VerifyResult`
|
|
116
|
+
|
|
117
|
+
Fields: `score`, `trust_score`, `challenge_ts`, `hostname`, `action`, `note`, `context`, `visitor_id`, `visitor_confidence`, `visitor_decision`, `override_applied`.
|
|
118
|
+
|
|
119
|
+
### `client.classify_email(email, *, sitekey=None) -> EmailClassificationResult`
|
|
120
|
+
|
|
121
|
+
Fields: `classification` (`safe` / `privacy/alias` / `temp-mail`), `reasons`, `risk_score`.
|
|
122
|
+
|
|
123
|
+
## Errors
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
from novelcaptcha import (
|
|
127
|
+
NovelCaptchaError,
|
|
128
|
+
InvalidTokenError,
|
|
129
|
+
InvalidSecretError,
|
|
130
|
+
NetworkError,
|
|
131
|
+
TimeoutError,
|
|
132
|
+
)
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
All errors subclass `NovelCaptchaError`.
|
|
136
|
+
|
|
137
|
+
## License
|
|
138
|
+
|
|
139
|
+
MIT
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# novelcaptcha
|
|
2
|
+
|
|
3
|
+
Python server SDK for [NovelCaptcha](https://github.com/novelfoss/captcha). Sync + async clients, plus drop-in FastAPI and Flask middleware.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install novelcaptcha
|
|
9
|
+
# with framework helpers:
|
|
10
|
+
pip install 'novelcaptcha[fastapi]'
|
|
11
|
+
pip install 'novelcaptcha[flask]'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Quick start
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
from novelcaptcha import NovelCaptcha
|
|
18
|
+
|
|
19
|
+
client = NovelCaptcha(
|
|
20
|
+
secret_key="sec_...",
|
|
21
|
+
base_url="http://localhost:3020", # omit for SaaS
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
result = client.verify(token, remote_ip="203.0.113.5")
|
|
25
|
+
if result.score < 0.5:
|
|
26
|
+
raise PermissionError("score too low")
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Async
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from novelcaptcha import AsyncNovelCaptcha
|
|
33
|
+
|
|
34
|
+
async with AsyncNovelCaptcha(secret_key="sec_...") as client:
|
|
35
|
+
result = await client.verify(token)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## FastAPI
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from fastapi import FastAPI, Depends
|
|
42
|
+
from novelcaptcha import AsyncNovelCaptcha
|
|
43
|
+
from novelcaptcha.fastapi import verify_captcha
|
|
44
|
+
|
|
45
|
+
app = FastAPI()
|
|
46
|
+
|
|
47
|
+
@app.on_event("startup")
|
|
48
|
+
async def on_startup():
|
|
49
|
+
app.state.novelcaptcha = AsyncNovelCaptcha(secret_key="sec_...")
|
|
50
|
+
|
|
51
|
+
@app.post("/login")
|
|
52
|
+
async def login(captcha = verify_captcha(token_field="captcha_token", min_score=0.5)):
|
|
53
|
+
# captcha is the VerifyResult — only reached when score >= 0.5
|
|
54
|
+
return {"visitor_id": captcha.visitor_id}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Flask
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from flask import Flask, request
|
|
61
|
+
from novelcaptcha import NovelCaptcha
|
|
62
|
+
from novelcaptcha.flask import novelcaptcha_required
|
|
63
|
+
|
|
64
|
+
app = Flask(__name__)
|
|
65
|
+
app.extensions["novelcaptcha"] = NovelCaptcha(secret_key="sec_...")
|
|
66
|
+
|
|
67
|
+
@app.post("/login")
|
|
68
|
+
@novelcaptcha_required(token_field="captcha_token", min_score=0.5)
|
|
69
|
+
def login():
|
|
70
|
+
result = request.novelcaptcha
|
|
71
|
+
return {"visitor_id": result.visitor_id}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## API
|
|
75
|
+
|
|
76
|
+
### `NovelCaptcha(secret_key, *, base_url=..., timeout=10.0)`
|
|
77
|
+
|
|
78
|
+
Sync client. `AsyncNovelCaptcha` has the same constructor signature.
|
|
79
|
+
|
|
80
|
+
### `client.verify(token, *, remote_ip=None) -> VerifyResult`
|
|
81
|
+
|
|
82
|
+
Fields: `score`, `trust_score`, `challenge_ts`, `hostname`, `action`, `note`, `context`, `visitor_id`, `visitor_confidence`, `visitor_decision`, `override_applied`.
|
|
83
|
+
|
|
84
|
+
### `client.classify_email(email, *, sitekey=None) -> EmailClassificationResult`
|
|
85
|
+
|
|
86
|
+
Fields: `classification` (`safe` / `privacy/alias` / `temp-mail`), `reasons`, `risk_score`.
|
|
87
|
+
|
|
88
|
+
## Errors
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from novelcaptcha import (
|
|
92
|
+
NovelCaptchaError,
|
|
93
|
+
InvalidTokenError,
|
|
94
|
+
InvalidSecretError,
|
|
95
|
+
NetworkError,
|
|
96
|
+
TimeoutError,
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
All errors subclass `NovelCaptchaError`.
|
|
101
|
+
|
|
102
|
+
## License
|
|
103
|
+
|
|
104
|
+
MIT
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""NovelCaptcha Python SDK — verify tokens and classify emails.
|
|
2
|
+
|
|
3
|
+
Quick start:
|
|
4
|
+
|
|
5
|
+
from novelcaptcha import NovelCaptcha
|
|
6
|
+
|
|
7
|
+
client = NovelCaptcha(
|
|
8
|
+
secret_key="sec_...",
|
|
9
|
+
base_url="http://localhost:3020", # omit for SaaS
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
result = client.verify(token, remote_ip="203.0.113.5")
|
|
13
|
+
if result.score < 0.5:
|
|
14
|
+
# reject or step-up
|
|
15
|
+
...
|
|
16
|
+
"""
|
|
17
|
+
from .client import (
|
|
18
|
+
AsyncNovelCaptcha,
|
|
19
|
+
ErrorContext,
|
|
20
|
+
NovelCaptcha,
|
|
21
|
+
RequestContext,
|
|
22
|
+
RequestHooks,
|
|
23
|
+
ResponseContext,
|
|
24
|
+
RetryPolicy,
|
|
25
|
+
)
|
|
26
|
+
from .errors import (
|
|
27
|
+
InvalidSecretError,
|
|
28
|
+
InvalidTokenError,
|
|
29
|
+
NetworkError,
|
|
30
|
+
NovelCaptchaError,
|
|
31
|
+
TimeoutError,
|
|
32
|
+
)
|
|
33
|
+
from .types import ChallengeResult, EmailClassificationResult, VerifyResult
|
|
34
|
+
|
|
35
|
+
__version__ = "0.1.0"
|
|
36
|
+
|
|
37
|
+
__all__ = [
|
|
38
|
+
"AsyncNovelCaptcha",
|
|
39
|
+
"ChallengeResult",
|
|
40
|
+
"EmailClassificationResult",
|
|
41
|
+
"ErrorContext",
|
|
42
|
+
"InvalidSecretError",
|
|
43
|
+
"InvalidTokenError",
|
|
44
|
+
"NetworkError",
|
|
45
|
+
"NovelCaptcha",
|
|
46
|
+
"NovelCaptchaError",
|
|
47
|
+
"RequestContext",
|
|
48
|
+
"RequestHooks",
|
|
49
|
+
"ResponseContext",
|
|
50
|
+
"RetryPolicy",
|
|
51
|
+
"TimeoutError",
|
|
52
|
+
"VerifyResult",
|
|
53
|
+
"__version__",
|
|
54
|
+
]
|