imrobot 0.8.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.
@@ -0,0 +1,24 @@
1
+ node_modules/
2
+ dist/
3
+ *.tsbuildinfo
4
+ .DS_Store
5
+ .env
6
+ .env.local
7
+ coverage/
8
+ *.log
9
+
10
+ .vercel
11
+
12
+ # Claude Code artifacts
13
+ .claude-mem.md
14
+ leo-agents/
15
+
16
+ # Vitest temp files
17
+ vitest.config.ts.timestamp-*
18
+
19
+ # Python
20
+ __pycache__/
21
+ *.pyc
22
+ .pytest_cache/
23
+ python/dist/
24
+ *.egg-info/
imrobot-0.8.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 imrobot 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.
imrobot-0.8.0/PKG-INFO ADDED
@@ -0,0 +1,157 @@
1
+ Metadata-Version: 2.5
2
+ Name: imrobot
3
+ Version: 0.8.0
4
+ Summary: Reverse-CAPTCHA for AI agents — Python SDK (solver, verifier, FastAPI middleware, LangChain/CrewAI/AutoGPT-friendly).
5
+ Project-URL: Homepage, https://imrobot.vercel.app
6
+ Project-URL: Repository, https://github.com/leopechnicki/im_robot
7
+ Project-URL: Issues, https://github.com/leopechnicki/im_robot/issues
8
+ Project-URL: Changelog, https://github.com/leopechnicki/im_robot/releases
9
+ Author-email: Leo Pechnicki <leopsantos@hotmail.com>
10
+ License: MIT
11
+ License-File: LICENSE
12
+ Keywords: agent,ai,autogpt,bot,captcha,crewai,crypto,fastapi,hmac,invisible,jwt,langchain,middleware,proof-of-agent,reverse-captcha,robot,verification
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Internet :: WWW/HTTP
24
+ Classifier: Topic :: Security
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Classifier: Typing :: Typed
27
+ Requires-Python: >=3.9
28
+ Provides-Extra: dev
29
+ Requires-Dist: fastapi>=0.100.0; extra == 'dev'
30
+ Requires-Dist: httpx>=0.27; extra == 'dev'
31
+ Requires-Dist: mypy>=1.10; extra == 'dev'
32
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
33
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
34
+ Requires-Dist: pytest>=8.0; extra == 'dev'
35
+ Requires-Dist: ruff>=0.5; extra == 'dev'
36
+ Requires-Dist: starlette>=0.27; extra == 'dev'
37
+ Provides-Extra: fastapi
38
+ Requires-Dist: fastapi>=0.100.0; extra == 'fastapi'
39
+ Requires-Dist: starlette>=0.27.0; extra == 'fastapi'
40
+ Description-Content-Type: text/markdown
41
+
42
+ # imrobot (Python)
43
+
44
+ **Reverse-CAPTCHA that verifies AI agents and robots, not humans — Python SDK.**
45
+
46
+ [![PyPI](https://img.shields.io/pypi/v/imrobot?style=flat-square&color=f59e0b)](https://pypi.org/project/imrobot/)
47
+ [![Python](https://img.shields.io/pypi/pyversions/imrobot?style=flat-square)](https://pypi.org/project/imrobot/)
48
+ [![License: MIT](https://img.shields.io/badge/license-MIT-f59e0b?style=flat-square)](../LICENSE)
49
+
50
+ Companion package to the JavaScript [imrobot](https://www.npmjs.com/package/imrobot) SDK. Produces byte-identical challenge outputs so a Python client can solve JS-issued challenges and vice-versa. Zero required dependencies for the solver + verifier; FastAPI is an optional extra.
51
+
52
+ ## Install
53
+
54
+ ```bash
55
+ pip install imrobot # solver + verifier + JWT (zero deps)
56
+ pip install "imrobot[fastapi]" # + FastAPI middleware
57
+ ```
58
+
59
+ ## Quick start — AI agent (LangChain / CrewAI / AutoGPT / any Python bot)
60
+
61
+ ```python
62
+ import httpx
63
+ from imrobot import solve_challenge
64
+
65
+ # 1. Fetch challenge
66
+ resp = httpx.get("https://example.com/imrobot/challenge")
67
+ challenge = resp.json()
68
+
69
+ # 2. Solve it
70
+ answer = solve_challenge(challenge)
71
+
72
+ # 3. Get your proof token
73
+ resp = httpx.post(
74
+ "https://example.com/imrobot/verify",
75
+ json={"challenge": challenge, "answer": answer},
76
+ )
77
+ proof_token = resp.json()["proofToken"]
78
+
79
+ # 4. Use the token on protected routes
80
+ httpx.get(
81
+ "https://example.com/api/agent-data",
82
+ headers={"X-Agent-Proof": proof_token},
83
+ )
84
+ ```
85
+
86
+ ## Quick start — FastAPI server
87
+
88
+ ```python
89
+ import os
90
+ from fastapi import Depends, FastAPI
91
+ from imrobot.fastapi import create_imrobot_router, require_agent
92
+
93
+ app = FastAPI()
94
+ secret = os.environ["IMROBOT_SECRET"] # min 16 chars
95
+
96
+ # Mount /imrobot/challenge + /imrobot/verify
97
+ app.include_router(create_imrobot_router(secret=secret), prefix="/imrobot")
98
+
99
+ # Protect a route
100
+ @app.get("/api/agent-data", dependencies=[Depends(require_agent(secret=secret))])
101
+ async def agent_only():
102
+ return {"secret": "only bots see this"}
103
+ ```
104
+
105
+ ## API surface
106
+
107
+ ### `imrobot`
108
+
109
+ | Function | Purpose |
110
+ |---|---|
111
+ | `solve_challenge(challenge)` | Compute the answer for a challenge (agent-side) |
112
+ | `execute_operation(input, op)` | Run one operation directly |
113
+ | `execute_pipeline(seed, pipeline)` | Run a full pipeline |
114
+ | `fnv1a(text)` | 32-bit FNV-1a hash — deterministic, 8 hex chars |
115
+ | `ImRobotVerifier(secret, ...)` | Server-side challenge generator + verifier |
116
+ | `ProofTokenIssuer(secret, ...)` | JWT (HS256) proof token issue/verify |
117
+ | `InMemoryReplayGuard(capacity)` | Bounded replay-attack guard |
118
+ | `hmac_sign(secret, message)` | HMAC-SHA256 hex (matches JS `hmacSign`) |
119
+ | `hmac_verify(secret, message, sig)` | Constant-time HMAC verify |
120
+
121
+ ### `imrobot.fastapi`
122
+
123
+ | Function | Purpose |
124
+ |---|---|
125
+ | `create_imrobot_router(secret=..., ...)` | Returns an `APIRouter` with GET `/challenge` + POST `/verify` |
126
+ | `require_agent(secret=..., ...)` | Returns a FastAPI dependency that enforces the `X-Agent-Proof` header |
127
+
128
+ ## Interoperability
129
+
130
+ The Python and JS SDKs share the exact same wire format:
131
+
132
+ - **FNV-1a** — bit-for-bit identical output (matches JS `Math.imul` semantics).
133
+ - **HMAC-SHA256** — 64-char lowercase hex.
134
+ - **Base64url** — RFC 4648 §5, no padding.
135
+ - **JWT** — RFC 7519 HS256, standard claims + namespaced `imr` claim.
136
+ - **Challenge JSON** — same field names (camelCase for wire compatibility with JS: `visibleSeed`, `expiresAt`, `hmac`, `pipeline`).
137
+
138
+ The `tests/test_interop.py` suite pins known JS reference outputs so any drift breaks CI.
139
+
140
+ ## Naming note — `sha256_hash`
141
+
142
+ The operation `{ "op": "sha256_hash" }` is a **deprecated alias for `fnv1a_cascade`** (8 rounds of FNV-1a → 64 hex chars). It is **not** SHA-256. Kept for wire-format compatibility; new challenges use `fnv1a_cascade` or `hash_chain`. The Python SDK emits a `DeprecationWarning` when the alias is executed. See the main `README.md` for full context.
143
+
144
+ ## Development
145
+
146
+ ```bash
147
+ git clone https://github.com/leopechnicki/im_robot
148
+ cd im_robot/python
149
+ pip install -e ".[dev]"
150
+ pytest
151
+ ruff check src tests
152
+ mypy src
153
+ ```
154
+
155
+ ## License
156
+
157
+ MIT © Leo Pechnicki
@@ -0,0 +1,116 @@
1
+ # imrobot (Python)
2
+
3
+ **Reverse-CAPTCHA that verifies AI agents and robots, not humans — Python SDK.**
4
+
5
+ [![PyPI](https://img.shields.io/pypi/v/imrobot?style=flat-square&color=f59e0b)](https://pypi.org/project/imrobot/)
6
+ [![Python](https://img.shields.io/pypi/pyversions/imrobot?style=flat-square)](https://pypi.org/project/imrobot/)
7
+ [![License: MIT](https://img.shields.io/badge/license-MIT-f59e0b?style=flat-square)](../LICENSE)
8
+
9
+ Companion package to the JavaScript [imrobot](https://www.npmjs.com/package/imrobot) SDK. Produces byte-identical challenge outputs so a Python client can solve JS-issued challenges and vice-versa. Zero required dependencies for the solver + verifier; FastAPI is an optional extra.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ pip install imrobot # solver + verifier + JWT (zero deps)
15
+ pip install "imrobot[fastapi]" # + FastAPI middleware
16
+ ```
17
+
18
+ ## Quick start — AI agent (LangChain / CrewAI / AutoGPT / any Python bot)
19
+
20
+ ```python
21
+ import httpx
22
+ from imrobot import solve_challenge
23
+
24
+ # 1. Fetch challenge
25
+ resp = httpx.get("https://example.com/imrobot/challenge")
26
+ challenge = resp.json()
27
+
28
+ # 2. Solve it
29
+ answer = solve_challenge(challenge)
30
+
31
+ # 3. Get your proof token
32
+ resp = httpx.post(
33
+ "https://example.com/imrobot/verify",
34
+ json={"challenge": challenge, "answer": answer},
35
+ )
36
+ proof_token = resp.json()["proofToken"]
37
+
38
+ # 4. Use the token on protected routes
39
+ httpx.get(
40
+ "https://example.com/api/agent-data",
41
+ headers={"X-Agent-Proof": proof_token},
42
+ )
43
+ ```
44
+
45
+ ## Quick start — FastAPI server
46
+
47
+ ```python
48
+ import os
49
+ from fastapi import Depends, FastAPI
50
+ from imrobot.fastapi import create_imrobot_router, require_agent
51
+
52
+ app = FastAPI()
53
+ secret = os.environ["IMROBOT_SECRET"] # min 16 chars
54
+
55
+ # Mount /imrobot/challenge + /imrobot/verify
56
+ app.include_router(create_imrobot_router(secret=secret), prefix="/imrobot")
57
+
58
+ # Protect a route
59
+ @app.get("/api/agent-data", dependencies=[Depends(require_agent(secret=secret))])
60
+ async def agent_only():
61
+ return {"secret": "only bots see this"}
62
+ ```
63
+
64
+ ## API surface
65
+
66
+ ### `imrobot`
67
+
68
+ | Function | Purpose |
69
+ |---|---|
70
+ | `solve_challenge(challenge)` | Compute the answer for a challenge (agent-side) |
71
+ | `execute_operation(input, op)` | Run one operation directly |
72
+ | `execute_pipeline(seed, pipeline)` | Run a full pipeline |
73
+ | `fnv1a(text)` | 32-bit FNV-1a hash — deterministic, 8 hex chars |
74
+ | `ImRobotVerifier(secret, ...)` | Server-side challenge generator + verifier |
75
+ | `ProofTokenIssuer(secret, ...)` | JWT (HS256) proof token issue/verify |
76
+ | `InMemoryReplayGuard(capacity)` | Bounded replay-attack guard |
77
+ | `hmac_sign(secret, message)` | HMAC-SHA256 hex (matches JS `hmacSign`) |
78
+ | `hmac_verify(secret, message, sig)` | Constant-time HMAC verify |
79
+
80
+ ### `imrobot.fastapi`
81
+
82
+ | Function | Purpose |
83
+ |---|---|
84
+ | `create_imrobot_router(secret=..., ...)` | Returns an `APIRouter` with GET `/challenge` + POST `/verify` |
85
+ | `require_agent(secret=..., ...)` | Returns a FastAPI dependency that enforces the `X-Agent-Proof` header |
86
+
87
+ ## Interoperability
88
+
89
+ The Python and JS SDKs share the exact same wire format:
90
+
91
+ - **FNV-1a** — bit-for-bit identical output (matches JS `Math.imul` semantics).
92
+ - **HMAC-SHA256** — 64-char lowercase hex.
93
+ - **Base64url** — RFC 4648 §5, no padding.
94
+ - **JWT** — RFC 7519 HS256, standard claims + namespaced `imr` claim.
95
+ - **Challenge JSON** — same field names (camelCase for wire compatibility with JS: `visibleSeed`, `expiresAt`, `hmac`, `pipeline`).
96
+
97
+ The `tests/test_interop.py` suite pins known JS reference outputs so any drift breaks CI.
98
+
99
+ ## Naming note — `sha256_hash`
100
+
101
+ The operation `{ "op": "sha256_hash" }` is a **deprecated alias for `fnv1a_cascade`** (8 rounds of FNV-1a → 64 hex chars). It is **not** SHA-256. Kept for wire-format compatibility; new challenges use `fnv1a_cascade` or `hash_chain`. The Python SDK emits a `DeprecationWarning` when the alias is executed. See the main `README.md` for full context.
102
+
103
+ ## Development
104
+
105
+ ```bash
106
+ git clone https://github.com/leopechnicki/im_robot
107
+ cd im_robot/python
108
+ pip install -e ".[dev]"
109
+ pytest
110
+ ruff check src tests
111
+ mypy src
112
+ ```
113
+
114
+ ## License
115
+
116
+ MIT © Leo Pechnicki
@@ -0,0 +1,110 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.24"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "imrobot"
7
+ version = "0.8.0"
8
+ description = "Reverse-CAPTCHA for AI agents — Python SDK (solver, verifier, FastAPI middleware, LangChain/CrewAI/AutoGPT-friendly)."
9
+ readme = "README.md"
10
+ license = { text = "MIT" }
11
+ authors = [
12
+ { name = "Leo Pechnicki", email = "leopsantos@hotmail.com" },
13
+ ]
14
+ keywords = [
15
+ "captcha", "reverse-captcha", "bot", "robot", "ai", "agent", "verification",
16
+ "hmac", "jwt", "proof-of-agent", "middleware", "fastapi", "langchain", "crewai",
17
+ "autogpt", "invisible", "crypto",
18
+ ]
19
+ classifiers = [
20
+ "Development Status :: 4 - Beta",
21
+ "Intended Audience :: Developers",
22
+ "License :: OSI Approved :: MIT License",
23
+ "Operating System :: OS Independent",
24
+ "Programming Language :: Python :: 3",
25
+ "Programming Language :: Python :: 3.9",
26
+ "Programming Language :: Python :: 3.10",
27
+ "Programming Language :: Python :: 3.11",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3.13",
30
+ "Topic :: Internet :: WWW/HTTP",
31
+ "Topic :: Security",
32
+ "Topic :: Software Development :: Libraries :: Python Modules",
33
+ "Typing :: Typed",
34
+ ]
35
+ requires-python = ">=3.9"
36
+ dependencies = []
37
+
38
+ [project.optional-dependencies]
39
+ fastapi = ["fastapi>=0.100.0", "starlette>=0.27.0"]
40
+ dev = [
41
+ "pytest>=8.0",
42
+ "pytest-asyncio>=0.23",
43
+ "pytest-cov>=5.0",
44
+ "fastapi>=0.100.0",
45
+ "httpx>=0.27",
46
+ "starlette>=0.27",
47
+ "ruff>=0.5",
48
+ "mypy>=1.10",
49
+ ]
50
+
51
+ [project.urls]
52
+ Homepage = "https://imrobot.vercel.app"
53
+ Repository = "https://github.com/leopechnicki/im_robot"
54
+ Issues = "https://github.com/leopechnicki/im_robot/issues"
55
+ Changelog = "https://github.com/leopechnicki/im_robot/releases"
56
+
57
+ [tool.hatch.build.targets.wheel]
58
+ packages = ["src/imrobot"]
59
+
60
+ [tool.hatch.build.targets.sdist]
61
+ include = ["src/imrobot", "README.md", "LICENSE"]
62
+
63
+ [tool.pytest.ini_options]
64
+ testpaths = ["tests"]
65
+ asyncio_mode = "auto"
66
+ addopts = "-ra --strict-markers"
67
+
68
+ [tool.coverage.run]
69
+ source = ["src/imrobot"]
70
+ branch = true
71
+
72
+ [tool.coverage.report]
73
+ exclude_lines = [
74
+ "pragma: no cover",
75
+ "raise NotImplementedError",
76
+ "if TYPE_CHECKING:",
77
+ "@overload",
78
+ ]
79
+
80
+ [tool.ruff]
81
+ line-length = 100
82
+ target-version = "py39"
83
+
84
+ [tool.ruff.lint]
85
+ select = ["E", "F", "I", "B", "SIM"]
86
+ # We support Python 3.9 so cannot use PEP 604 union / Optional syntax (X | Y).
87
+ # We also alias imported classes with capitalized names in closures for readability
88
+ # — that's not a naming smell in our style, so N806 is disabled.
89
+ ignore = [
90
+ "E501", # line length handled by formatter
91
+ "E402", # tests use pytest.importorskip before other imports (intentional)
92
+ "B008", # FastAPI depends-in-defaults is idiomatic
93
+ ]
94
+
95
+ [tool.ruff.lint.per-file-ignores]
96
+ "tests/*" = ["E402", "B008"]
97
+
98
+ [tool.mypy]
99
+ # mypy dropped Python 3.9 support in v1.15+, but we still support Python 3.9
100
+ # at runtime (the SDK doesn't use any 3.10+ features). We tell mypy to
101
+ # analyze against 3.10 so newer mypy versions work — runtime remains 3.9-safe.
102
+ python_version = "3.10"
103
+ warn_return_any = false
104
+ warn_unused_configs = true
105
+ warn_unused_ignores = false
106
+ # We use dict-based structural typing for wire compatibility with JS; strict
107
+ # mode would require overwrought TypedDict overloads for every operation
108
+ # variant. The tests catch what strict typing would.
109
+ strict = false
110
+ ignore_missing_imports = true
@@ -0,0 +1,83 @@
1
+ """
2
+ imrobot — Reverse-CAPTCHA that verifies AI agents (Python SDK).
3
+
4
+ Public API — mirrors the JavaScript SDK's ``imrobot`` and ``imrobot/server`` surfaces.
5
+
6
+ Solver (client side, for LangChain / CrewAI / AutoGPT / any AI agent):
7
+
8
+ >>> from imrobot import solve_challenge
9
+ >>> import httpx
10
+ >>> challenge = httpx.get("https://example.com/imrobot/challenge").json()
11
+ >>> answer = solve_challenge(challenge)
12
+ >>> httpx.post("https://example.com/imrobot/verify",
13
+ ... json={"challenge": challenge, "answer": answer})
14
+
15
+ Verifier (server side):
16
+
17
+ >>> from imrobot import ImRobotVerifier
18
+ >>> verifier = ImRobotVerifier(secret="a-32-char-server-secret-string")
19
+ >>> signed = await verifier.generate()
20
+ >>> result = await verifier.verify(signed, answer)
21
+
22
+ Proof tokens (RFC 7519 JWT, HS256):
23
+
24
+ >>> from imrobot import ProofTokenIssuer
25
+ >>> issuer = ProofTokenIssuer(secret="...")
26
+ >>> token = await issuer.issue(agent_id="agent_1", challenge_id=signed["id"],
27
+ ... difficulty="medium", solve_time_ms=42, suspicious=False)
28
+
29
+ FastAPI middleware — see ``imrobot.fastapi``.
30
+ """
31
+
32
+ from ._version import __version__
33
+ from .core import (
34
+ Challenge,
35
+ Difficulty,
36
+ Operation,
37
+ SignedChallenge,
38
+ execute_operation,
39
+ execute_pipeline,
40
+ fnv1a,
41
+ format_operation,
42
+ format_pipeline,
43
+ solve_challenge,
44
+ )
45
+ from .server import (
46
+ AgentProofToken,
47
+ ChallengeReplayGuard,
48
+ ImRobotVerifier,
49
+ InMemoryReplayGuard,
50
+ ProofTokenIssuer,
51
+ ProofTokenVerifyResult,
52
+ VerifyResult,
53
+ hmac_sign,
54
+ hmac_verify,
55
+ sha256_hex,
56
+ )
57
+
58
+ __all__ = [
59
+ "__version__",
60
+ # core types
61
+ "Challenge",
62
+ "Difficulty",
63
+ "Operation",
64
+ "SignedChallenge",
65
+ # core functions
66
+ "execute_operation",
67
+ "execute_pipeline",
68
+ "fnv1a",
69
+ "format_operation",
70
+ "format_pipeline",
71
+ "solve_challenge",
72
+ # server
73
+ "AgentProofToken",
74
+ "ChallengeReplayGuard",
75
+ "ImRobotVerifier",
76
+ "InMemoryReplayGuard",
77
+ "ProofTokenIssuer",
78
+ "ProofTokenVerifyResult",
79
+ "VerifyResult",
80
+ "hmac_sign",
81
+ "hmac_verify",
82
+ "sha256_hex",
83
+ ]
@@ -0,0 +1,3 @@
1
+ """Single source of truth for the package version (mirrors package.json for the JS SDK)."""
2
+
3
+ __version__ = "0.8.0"