spaps 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.
Files changed (51) hide show
  1. spaps-0.1.0/.gitignore +130 -0
  2. spaps-0.1.0/CHANGELOG.md +12 -0
  3. spaps-0.1.0/FULL_CHECKLIST.md +66 -0
  4. spaps-0.1.0/LICENSE +22 -0
  5. spaps-0.1.0/PKG-INFO +181 -0
  6. spaps-0.1.0/README.md +126 -0
  7. spaps-0.1.0/TDD_PLAN.md +103 -0
  8. spaps-0.1.0/TODO.md +39 -0
  9. spaps-0.1.0/docs/RELEASE_CHECKLIST.md +25 -0
  10. spaps-0.1.0/pyproject.toml +76 -0
  11. spaps-0.1.0/scripts/manage_version.py +156 -0
  12. spaps-0.1.0/src/spaps_client/__init__.py +163 -0
  13. spaps-0.1.0/src/spaps_client/async_client.py +214 -0
  14. spaps-0.1.0/src/spaps_client/auth.py +411 -0
  15. spaps-0.1.0/src/spaps_client/auth_async.py +251 -0
  16. spaps-0.1.0/src/spaps_client/client.py +213 -0
  17. spaps-0.1.0/src/spaps_client/config.py +77 -0
  18. spaps-0.1.0/src/spaps_client/crypto.py +282 -0
  19. spaps-0.1.0/src/spaps_client/crypto_async.py +135 -0
  20. spaps-0.1.0/src/spaps_client/http.py +171 -0
  21. spaps-0.1.0/src/spaps_client/http_async.py +85 -0
  22. spaps-0.1.0/src/spaps_client/metrics.py +56 -0
  23. spaps-0.1.0/src/spaps_client/metrics_async.py +47 -0
  24. spaps-0.1.0/src/spaps_client/payments.py +410 -0
  25. spaps-0.1.0/src/spaps_client/payments_async.py +246 -0
  26. spaps-0.1.0/src/spaps_client/py.typed +0 -0
  27. spaps-0.1.0/src/spaps_client/secure_messages.py +172 -0
  28. spaps-0.1.0/src/spaps_client/secure_messages_async.py +105 -0
  29. spaps-0.1.0/src/spaps_client/sessions.py +267 -0
  30. spaps-0.1.0/src/spaps_client/sessions_async.py +152 -0
  31. spaps-0.1.0/src/spaps_client/storage.py +145 -0
  32. spaps-0.1.0/src/spaps_client/usage.py +266 -0
  33. spaps-0.1.0/src/spaps_client/usage_async.py +140 -0
  34. spaps-0.1.0/src/spaps_client/whitelist.py +269 -0
  35. spaps-0.1.0/src/spaps_client/whitelist_async.py +199 -0
  36. spaps-0.1.0/tests/conftest.py +8 -0
  37. spaps-0.1.0/tests/integration/test_build.py +52 -0
  38. spaps-0.1.0/tests/integration/test_smoke.py +69 -0
  39. spaps-0.1.0/tests/unit/test_async_client.py +118 -0
  40. spaps-0.1.0/tests/unit/test_auth.py +419 -0
  41. spaps-0.1.0/tests/unit/test_client.py +127 -0
  42. spaps-0.1.0/tests/unit/test_config.py +51 -0
  43. spaps-0.1.0/tests/unit/test_http.py +69 -0
  44. spaps-0.1.0/tests/unit/test_metadata.py +32 -0
  45. spaps-0.1.0/tests/unit/test_metrics.py +71 -0
  46. spaps-0.1.0/tests/unit/test_payments.py +608 -0
  47. spaps-0.1.0/tests/unit/test_secure_messages.py +127 -0
  48. spaps-0.1.0/tests/unit/test_sessions.py +285 -0
  49. spaps-0.1.0/tests/unit/test_storage.py +39 -0
  50. spaps-0.1.0/tests/unit/test_usage.py +205 -0
  51. spaps-0.1.0/tests/unit/test_whitelist.py +175 -0
spaps-0.1.0/.gitignore ADDED
@@ -0,0 +1,130 @@
1
+ # Dependencies
2
+ node_modules/
3
+ *.log
4
+ npm-debug.log*
5
+ yarn-debug.log*
6
+ yarn-error.log*
7
+ lerna-debug.log*
8
+
9
+ # Testing
10
+ coverage/
11
+ *.lcov
12
+ .nyc_output
13
+
14
+ # Production builds
15
+ dist/
16
+ build/
17
+ out/
18
+ *.tsbuildinfo
19
+
20
+ # Environment files
21
+ .env
22
+ .env.*
23
+ *.env
24
+ **/.env
25
+ **/.env.*
26
+ .env.development
27
+ .env.production
28
+ .env.staging
29
+ .env.deploy
30
+ .env.local
31
+ .env.development.local
32
+ .env.test.local
33
+ .env.production.local
34
+ # Allow committed templates/examples
35
+ !*.env.example
36
+ !*.env.sample
37
+ !*.env.template
38
+ !**/.env.example
39
+ !**/.env.sample
40
+ !**/.env.template
41
+ !**/.env.*.example
42
+ !**/.env.*.sample
43
+ !**/.env.*.template
44
+ !**/*.env.example
45
+ !**/*.env.sample
46
+ !**/*.env.template
47
+
48
+ # IDE
49
+ .vscode/
50
+ .idea/
51
+ *.swp
52
+ *.swo
53
+ *.swn
54
+ .DS_Store
55
+
56
+ # Debug
57
+ debug.log
58
+ *.log
59
+
60
+ # Temporary files
61
+ tmp/
62
+ temp/
63
+ *.tmp
64
+
65
+ # Package manager files
66
+ .pnp.*
67
+ .yarn/*
68
+ !.yarn/patches
69
+ !.yarn/plugins
70
+ !.yarn/releases
71
+ !.yarn/sdks
72
+ !.yarn/versions
73
+
74
+ # Next.js specific
75
+ .next/
76
+ next-env.d.ts
77
+ .vercel/
78
+
79
+ # Example projects - ignore build artifacts
80
+ examples/**/.next/
81
+ examples/**/node_modules/
82
+ examples/**/dist/
83
+ examples/**/build/
84
+ examples/**/*.log
85
+ examples/**/.env
86
+ examples/**/.env.local
87
+
88
+ # MCP/Sweetpotato docs build
89
+ mcp-sweetpotato-docs/node_modules/
90
+ mcp-sweetpotato-docs/dist/
91
+ mcp-sweetpotato-docs/build/
92
+ mcp-sweetpotato-docs/.next/
93
+
94
+ # Large test files
95
+ *.jpg
96
+ *.jpeg
97
+ *.png
98
+ *.gif
99
+ *.bmp
100
+ *.mp4
101
+ *.mov
102
+ *.avi
103
+ *.zip
104
+ *.tar
105
+ *.gz
106
+ *.rar
107
+
108
+ # Database files
109
+ *.sqlite
110
+ *.sqlite3
111
+ *.db
112
+
113
+ # OS files
114
+ Thumbs.db
115
+ Desktop.ini
116
+
117
+ # Backup files
118
+ *.bak
119
+ *.backup
120
+ *.old
121
+
122
+ # Test output
123
+ test-results/
124
+ playwright-report/
125
+ playwright/.cache/
126
+
127
+ # Lock files that shouldn't be committed for libraries
128
+ # (keep package-lock.json for applications)
129
+ # yarn.lock
130
+ # pnpm-lock.yaml*.tgz
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 - 2025-02-14
4
+
5
+ - First public release on PyPI under the name `spaps`.
6
+ - Adds synchronous and asynchronous clients mirroring the TypeScript SDK, including
7
+ sessions, payments (crypto included), usage, whitelist, secure messages, and metrics helpers.
8
+ - Provides configurable retry/backoff handling, structured logging hooks, and token storage
9
+ abstractions (in-memory & file-backed).
10
+ - Ships lint (`ruff`), type checking (`mypy`), coverage enforcement, and integration smoke
11
+ tests wired into the release workflow.
12
+ - Updates documentation with Python quickstart examples and a dedicated backend guide.
@@ -0,0 +1,66 @@
1
+ # Python Client Completion Checklist
2
+
3
+ ## Feature Parity
4
+ - [x] Auth: email/password login & signup helpers
5
+ - [x] Auth: magic link flow
6
+ - [x] Auth: logout & token revocation
7
+ - [x] Auth: whitelist queries/mutations
8
+ - [x] Sessions: list sessions
9
+ - [x] Sessions: touch session endpoint
10
+ - [x] Sessions: delete session / revoke
11
+ - [x] Payments: usage balance/history endpoints
12
+ - [x] Payments: update payment method
13
+ - [x] Payments: Stripe checkout (existing)
14
+ - [x] Payments: Stripe payment intent (existing)
15
+ - [x] Payments: wallet deposit/status (existing)
16
+ - [x] Payments: subscription details/cancel (existing)
17
+ - [x] Payments: crypto invoices (create/get/reconcile)
18
+ - [x] Payments: crypto webhooks signature helper
19
+ - [x] Usage API: feature list/record/history wrappers
20
+ - [x] Admin: secure messages routes
21
+ - [x] Admin: whitelist management
22
+ - [x] Admin: metrics endpoints
23
+ - [ ] Docs/search/openapi utilities (if applicable)
24
+
25
+ ## SDK Ergonomics
26
+ - [x] Token storage abstraction (file/memory/extensible)
27
+ - [x] Retry/backoff policy with configurable strategy
28
+ - [x] Logging hooks & structured errors
29
+ - [x] Async client variants (optional dependency)
30
+ - [x] Type hints/completion for all public APIs
31
+ - [x] Rich README with quickstart & API reference
32
+ - [ ] CHANGELOG.md with semantic version entries
33
+
34
+ ## Testing & Quality
35
+ - [x] Integration smoke tests using mock server
36
+ - [x] Coverage tracking / threshold enforcement
37
+ - [x] Type checking (mypy or pyright)
38
+ - [x] Lint/format (ruff or black) configuration
39
+ - [x] Twine check in release flow
40
+ - [x] CI matrix for Python 3.9-3.12
41
+
42
+ ## Documentation Sync
43
+ - [x] Update SDK_QUICKSTART with Python section
44
+ - [x] Add dedicated guide `docs/guides/python-backend.md`
45
+ - [x] Ensure API docs link to Python examples (in progress)
46
+ - [x] Update docs/manifest entries for all endpoints
47
+ - [x] Reference Python client in AGENTS documentation
48
+
49
+ ## Automation & CI/CD
50
+ - [x] Add `prepush` hook entry for `npm run test:python-client`
51
+ - [x] Add npm scripts for build/release (`build:python-client`, `publish:python-client`)
52
+ - [x] GitHub Actions workflow for lint/test/build (`.github/workflows/python-client.yml`)
53
+ - [x] Release workflow with PyPI token (manual trigger)
54
+ - [ ] Dependabot/Renovate rules for Python deps (optional)
55
+ - [ ] Release checklist enforced (link in docs)
56
+
57
+ ## Release Readiness
58
+ - [ ] Decide package registry (PyPI vs internal)
59
+ - [ ] Configure credentials/secrets for publishing
60
+ - [ ] Version compatibility policy with backend
61
+ - [ ] Beta release announcement plan
62
+ - [ ] Support channel / issue templates updated
63
+
64
+ ## Post-Launch
65
+ - [ ] Monitor downloads/errors
66
+ - [ ] Collect feedback for next iteration
spaps-0.1.0/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Sweet Potato Team
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.
22
+
spaps-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,181 @@
1
+ Metadata-Version: 2.4
2
+ Name: spaps
3
+ Version: 0.1.0
4
+ Summary: Sweet Potato Authentication & Payment Service Python client
5
+ Project-URL: Homepage, https://api.sweetpotato.dev
6
+ Project-URL: Repository, https://github.com/sweet-potato/spaps
7
+ Author-email: Sweet Potato Team <support@sweetpotato.dev>
8
+ License: MIT License
9
+
10
+ Copyright (c) 2025 Sweet Potato Team
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ of this software and associated documentation files (the "Software"), to deal
14
+ in the Software without restriction, including without limitation the rights
15
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
+ copies of the Software, and to permit persons to whom the Software is
17
+ furnished to do so, subject to the following conditions:
18
+
19
+ The above copyright notice and this permission notice shall be included in all
20
+ copies or substantial portions of the Software.
21
+
22
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
+ SOFTWARE.
29
+
30
+ License-File: LICENSE
31
+ Keywords: authentication,payments,spaps,sweet-potato
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: License :: OSI Approved :: MIT License
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Programming Language :: Python :: 3 :: Only
36
+ Classifier: Programming Language :: Python :: 3.9
37
+ Classifier: Programming Language :: Python :: 3.10
38
+ Classifier: Programming Language :: Python :: 3.11
39
+ Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
41
+ Requires-Python: >=3.9
42
+ Requires-Dist: httpx<0.28.0,>=0.27.0
43
+ Requires-Dist: pydantic<3.0.0,>=2.7.0
44
+ Provides-Extra: dev
45
+ Requires-Dist: build<2.0.0,>=1.2.1; extra == 'dev'
46
+ Requires-Dist: httpx<0.28.0,>=0.27.0; extra == 'dev'
47
+ Requires-Dist: mypy<2.0.0,>=1.10.0; extra == 'dev'
48
+ Requires-Dist: pydantic<3.0.0,>=2.7.0; extra == 'dev'
49
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
50
+ Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
51
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
52
+ Requires-Dist: respx<0.23.0,>=0.22.0; extra == 'dev'
53
+ Requires-Dist: ruff<1.0.0,>=0.5.5; extra == 'dev'
54
+ Description-Content-Type: text/markdown
55
+
56
+ ---
57
+ id: spaps-python-sdk
58
+ title: Sweet Potato Python Client
59
+ category: sdk
60
+ tags:
61
+ - sdk
62
+ - python
63
+ - client
64
+ ai_summary: |
65
+ Explains installation, configuration, and usage patterns for the spaps Python
66
+ SDK, including environment setup, async support, and integration guidance for
67
+ backend services.
68
+ last_updated: 2025-02-14
69
+ ---
70
+
71
+ # Sweet Potato Python Client
72
+
73
+ > Python SDK for the Sweet Potato Authentication & Payment Service (SPAPS).
74
+
75
+ This package is under active development. Follow the TDD plan in `TDD_PLAN.md`
76
+ to track progress and upcoming milestones.
77
+
78
+ ## Installation
79
+
80
+ Install from PyPI:
81
+
82
+ ```bash
83
+ pip install spaps
84
+ ```
85
+
86
+ For local development inside this repository:
87
+
88
+ ```bash
89
+ pip install -e .[dev]
90
+ ```
91
+
92
+ ## Development
93
+
94
+ ```bash
95
+ pytest
96
+ ```
97
+
98
+ ### Available clients
99
+
100
+ - `AuthClient` – wallet, email/password, and magic link flows
101
+ - `SessionsClient` – current session, validation, listing, revocation
102
+ - `PaymentsClient` – checkout sessions, wallet deposits, crypto invoices
103
+ - `UsageClient` – feature usage snapshots, recording, aggregated history
104
+ - `SecureMessagesClient` – encrypted message creation and retrieval
105
+ - `MetricsClient` – health and metrics convenience helpers
106
+
107
+ ### Quickstart
108
+
109
+ ```python
110
+ from spaps_client import SpapsClient
111
+
112
+ spaps = SpapsClient(base_url="http://localhost:3300", api_key="test_key_local_dev_only")
113
+
114
+ # Authenticate (tokens are persisted automatically)
115
+ spaps.auth.sign_in_with_password(email="user@example.com", password="Secret123!")
116
+
117
+ # Call downstream services using the stored access token
118
+ current = spaps.sessions.get_current_session()
119
+ print(current.session_id)
120
+
121
+ checkout = spaps.payments.create_checkout_session(
122
+ price_id="price_123",
123
+ mode="subscription",
124
+ success_url="https://example.com/success",
125
+ cancel_url="https://example.com/cancel",
126
+ )
127
+ print(checkout.checkout_url)
128
+
129
+ spaps.close()
130
+ ```
131
+
132
+ Configure retry/backoff and structured logging when constructing the client:
133
+
134
+ ```python
135
+ from spaps_client import SpapsClient, RetryConfig, default_logging_hooks
136
+
137
+ spaps = SpapsClient(
138
+ base_url="http://localhost:3300",
139
+ api_key="test_key_local_dev_only",
140
+ retry_config=RetryConfig(max_attempts=4, backoff_factor=0.2),
141
+ logging_hooks=default_logging_hooks(),
142
+ )
143
+ ```
144
+
145
+ ### Async Quickstart
146
+
147
+ ```python
148
+ import asyncio
149
+ from spaps_client import AsyncSpapsClient
150
+
151
+ async def main():
152
+ client = AsyncSpapsClient(base_url="http://localhost:3300", api_key="test_key_local_dev_only")
153
+ try:
154
+ await client.auth.sign_in_with_password(email="user@example.com", password="Secret123!")
155
+ current = await client.sessions.list_sessions()
156
+ print(len(current.sessions))
157
+ finally:
158
+ await client.aclose()
159
+
160
+ asyncio.run(main())
161
+ ```
162
+
163
+ ### Useful Scripts
164
+
165
+ ```bash
166
+ npm run test:python-client # run pytest from repo root
167
+ npm run lint:python-client # ruff linting
168
+ npm run typecheck:python-client # mypy type checking
169
+ npm run build:python-client # build wheel/sdist and run twine check
170
+ npm run publish:python-client # build and upload via twine (requires PYPI_TOKEN)
171
+ ```
172
+
173
+ Refer to `docs/RELEASE_CHECKLIST.md` for the full release process.
174
+
175
+ Refer to the repository root documentation for integration details.
176
+
177
+ ## Documentation
178
+
179
+ - [Quickstart (Python section)](../../docs/getting-started/quickstart.md#python-example---using-spaps)
180
+ - [Python Backend Integration Guide](../../docs/guides/python-backend.md)
181
+ - API references under `docs/api/` include Python usage snippets for sessions, payments, usage, whitelist, and secure messages.
spaps-0.1.0/README.md ADDED
@@ -0,0 +1,126 @@
1
+ ---
2
+ id: spaps-python-sdk
3
+ title: Sweet Potato Python Client
4
+ category: sdk
5
+ tags:
6
+ - sdk
7
+ - python
8
+ - client
9
+ ai_summary: |
10
+ Explains installation, configuration, and usage patterns for the spaps Python
11
+ SDK, including environment setup, async support, and integration guidance for
12
+ backend services.
13
+ last_updated: 2025-02-14
14
+ ---
15
+
16
+ # Sweet Potato Python Client
17
+
18
+ > Python SDK for the Sweet Potato Authentication & Payment Service (SPAPS).
19
+
20
+ This package is under active development. Follow the TDD plan in `TDD_PLAN.md`
21
+ to track progress and upcoming milestones.
22
+
23
+ ## Installation
24
+
25
+ Install from PyPI:
26
+
27
+ ```bash
28
+ pip install spaps
29
+ ```
30
+
31
+ For local development inside this repository:
32
+
33
+ ```bash
34
+ pip install -e .[dev]
35
+ ```
36
+
37
+ ## Development
38
+
39
+ ```bash
40
+ pytest
41
+ ```
42
+
43
+ ### Available clients
44
+
45
+ - `AuthClient` – wallet, email/password, and magic link flows
46
+ - `SessionsClient` – current session, validation, listing, revocation
47
+ - `PaymentsClient` – checkout sessions, wallet deposits, crypto invoices
48
+ - `UsageClient` – feature usage snapshots, recording, aggregated history
49
+ - `SecureMessagesClient` – encrypted message creation and retrieval
50
+ - `MetricsClient` – health and metrics convenience helpers
51
+
52
+ ### Quickstart
53
+
54
+ ```python
55
+ from spaps_client import SpapsClient
56
+
57
+ spaps = SpapsClient(base_url="http://localhost:3300", api_key="test_key_local_dev_only")
58
+
59
+ # Authenticate (tokens are persisted automatically)
60
+ spaps.auth.sign_in_with_password(email="user@example.com", password="Secret123!")
61
+
62
+ # Call downstream services using the stored access token
63
+ current = spaps.sessions.get_current_session()
64
+ print(current.session_id)
65
+
66
+ checkout = spaps.payments.create_checkout_session(
67
+ price_id="price_123",
68
+ mode="subscription",
69
+ success_url="https://example.com/success",
70
+ cancel_url="https://example.com/cancel",
71
+ )
72
+ print(checkout.checkout_url)
73
+
74
+ spaps.close()
75
+ ```
76
+
77
+ Configure retry/backoff and structured logging when constructing the client:
78
+
79
+ ```python
80
+ from spaps_client import SpapsClient, RetryConfig, default_logging_hooks
81
+
82
+ spaps = SpapsClient(
83
+ base_url="http://localhost:3300",
84
+ api_key="test_key_local_dev_only",
85
+ retry_config=RetryConfig(max_attempts=4, backoff_factor=0.2),
86
+ logging_hooks=default_logging_hooks(),
87
+ )
88
+ ```
89
+
90
+ ### Async Quickstart
91
+
92
+ ```python
93
+ import asyncio
94
+ from spaps_client import AsyncSpapsClient
95
+
96
+ async def main():
97
+ client = AsyncSpapsClient(base_url="http://localhost:3300", api_key="test_key_local_dev_only")
98
+ try:
99
+ await client.auth.sign_in_with_password(email="user@example.com", password="Secret123!")
100
+ current = await client.sessions.list_sessions()
101
+ print(len(current.sessions))
102
+ finally:
103
+ await client.aclose()
104
+
105
+ asyncio.run(main())
106
+ ```
107
+
108
+ ### Useful Scripts
109
+
110
+ ```bash
111
+ npm run test:python-client # run pytest from repo root
112
+ npm run lint:python-client # ruff linting
113
+ npm run typecheck:python-client # mypy type checking
114
+ npm run build:python-client # build wheel/sdist and run twine check
115
+ npm run publish:python-client # build and upload via twine (requires PYPI_TOKEN)
116
+ ```
117
+
118
+ Refer to `docs/RELEASE_CHECKLIST.md` for the full release process.
119
+
120
+ Refer to the repository root documentation for integration details.
121
+
122
+ ## Documentation
123
+
124
+ - [Quickstart (Python section)](../../docs/getting-started/quickstart.md#python-example---using-spaps)
125
+ - [Python Backend Integration Guide](../../docs/guides/python-backend.md)
126
+ - API references under `docs/api/` include Python usage snippets for sessions, payments, usage, whitelist, and secure messages.
@@ -0,0 +1,103 @@
1
+ # Sweet Potato Python Client – TDD Plan
2
+
3
+ ## Objectives
4
+ - Deliver a first-party Python package that mirrors the developer experience of the JavaScript `spaps-sdk`, optimized for backend/server use.
5
+ - Ship production-ready wheels (PyPI-compatible) with type hints, deterministic tests, and docs that stay aligned with SPAPS API changes.
6
+ - Follow SPAPS workflow: tests first, minimal implementation, docs/manifest updates.
7
+
8
+ ## Target Package Layout
9
+ ```
10
+ packages/python-client/
11
+ ├── pyproject.toml # Build metadata (PEP 621), poetry/pdm backend TBD
12
+ ├── README.md # Usage, examples, API docs
13
+ ├── src/
14
+ │ └── spaps_client/
15
+ │ ├── __init__.py
16
+ │ ├── config.py # Env + settings management
17
+ │ ├── http.py # HTTP client abstraction (requests/httpx)
18
+ │ ├── auth.py # Token lifecycle helpers
19
+ │ ├── sessions.py # Session validation helpers
20
+ │ ├── payments/ # Future Stripe/crypto modules
21
+ │ └── errors.py # Rich exceptions mapped from SPAPS error payloads
22
+ ├── tests/
23
+ │ ├── conftest.py
24
+ │ ├── fixtures/ # Shared mocks (responses/httpx respx)
25
+ │ ├── unit/
26
+ │ └── integration/
27
+ └── docs/
28
+ └── python-client.md # Mirrors JS SDK quickstart, with “Related Internals”
29
+ ```
30
+
31
+ ## Tooling Decisions (to validate with TDD)
32
+ - **HTTP**: `httpx` (sync + async) for flexible usage. Mock with `respx`.
33
+ - **Serialization**: `pydantic` models for typed responses & validation.
34
+ - **Testing**: `pytest` with `pytest-asyncio`, `respx`, and `pytest-cov`.
35
+ - **Packaging**: `pyproject.toml` + `hatchling` (lightweight) or `poetry` backend.
36
+ - **CI hooks**: ensure compatibility with existing npm scripts (`npm run verify:deps`, `npm run docs:validate-all`).
37
+
38
+ ## Milestones & TDD Steps
39
+
40
+ ### Milestone 0 – Scaffolding Tests
41
+ 1. Write failing tests asserting package metadata exists (`pyproject.toml`, version exposed in `spaps_client.__version__`).
42
+ 2. Add failing doc-validation test ensuring README code snippets compile (use doctest/pytest).
43
+
44
+ ### Milestone 1 – Auth Token Lifecycle
45
+ - **Tests first**:
46
+ - `tests/unit/test_auth_nonce.py`: expects `AuthClient.request_nonce` to POST `/api/auth/nonce` with API key headers and return nonce/message/expiry.
47
+ - `tests/unit/test_auth_verify.py`: ensures `verify_wallet` sends signature payload, handles success/failure, raises custom exceptions on 4xx/5xx.
48
+ - `tests/unit/test_auth_refresh.py`: covers refresh flow and token storage abstraction.
49
+ - Mock HTTP responses via `respx` fixtures; assert request payloads match SPAPS API schemas (see `src/routes/auth.ts` & `docs/api/wallet-authentication.md`).
50
+ - **Implementation**: minimal code to satisfy tests; introduce data models (`NonceResponse`, `TokenPair`).
51
+ - **Docs**: update `docs/api/wallet-authentication.md` “Related Internals” with Python package reference once tests pass.
52
+
53
+ ### Milestone 2 – Session Validation
54
+ - Tests:
55
+ - `tests/unit/test_sessions_validate.py`: `SessionsClient.validate()` hitting `/api/sessions/validate`; returns structured session metadata.
56
+ - `tests/unit/test_sessions_current.py`: ensures caching of current session call and error translation.
57
+ - Negative tests for expired/invalid JWT (anticipate `401` with `INVALID_SESSION` code).
58
+ - Implementation: add module sto stub for session operations.
59
+ - Docs: extend `docs/api/sessions.md` with Python snippets; update `docs/manifest.json` entries for `/api/sessions/*` to include new tests.
60
+
61
+ ### Milestone 3 – Configuration & Environment
62
+ - Tests:
63
+ - `tests/unit/test_config.py`: default API URL/key from env (`SPAPS_API_URL`, `SPAPS_API_KEY`), fallback to local defaults.
64
+ - `tests/unit/test_http_client.py`: HTTP timeout, retry/backoff configuration.
65
+ - Implementation: config objects, HTTP wrapper (sync), optional async variant (guarded by extra dependency `httpx[http2]`).
66
+ - Docs: add Python-specific environment guidance to `.env.example` (commented) & new doc page `docs/guides/python-backend.md`.
67
+
68
+ ### Milestone 4 – Packaging & Distribution
69
+ - Tests:
70
+ - `tests/integration/test_build.py`: invokes `python -m build` (or backend equivalent) and asserts wheel/sdist produced in `dist/`.
71
+ - `tests/integration/test_installation.py`: installs built wheel into temp venv to ensure imports succeed.
72
+ - Implementation: finalize `pyproject.toml`, include license classifiers, add `__version__`.
73
+ - Docs: README badges, release checklist in `docs/AGENTS_CC.md`.
74
+
75
+ ### Milestone 5 – Optional Features
76
+ - Payments (Stripe, crypto), admin methods, usage tracking—mirror JavaScript SDK priorities. Each feature enters with:
77
+ - Route-level tests hitting recorded JSON fixtures.
78
+ - Error regression tests (403, rate limits).
79
+ - Docs updates (API refs + manifest).
80
+
81
+ ## Testing Strategy
82
+ - Run targeted suites via `pytest tests/unit` within package.
83
+ - Add npm script wrapper (`"test:python-client": "cd packages/python-client && pytest -q"` ) so CI integrates seamlessly.
84
+ - Ensure no live network calls: respx strictly intercepts HTTPX; add guard test (`respx.assert_all_called()`).
85
+ - For crypto/webhook features, snapshot expected request bodies (JSON fixtures under `tests/fixtures`).
86
+
87
+ ## Documentation & Manifest Updates
88
+ - When features land, update:
89
+ - `docs/manifest.json`: add Python client tests under relevant endpoints.
90
+ - `docs/api/*`: include “Python Backend Example” sections.
91
+ - `SDK_QUICKSTART.md`: cross-link to new Python Quickstart.
92
+ - Maintain changelog (`packages/python-client/CHANGELOG.md`) aligned with releases.
93
+
94
+ ## Outstanding Questions / Follow-ups
95
+ 1. Packaging backend: prefer `hatchling` (minimal) vs `poetry`? Decide before Milestone 0 tests.
96
+ 2. Async support: ship in v0.1 or defer?
97
+ 3. Token storage interface: simple return dict vs pluggable storage (Redis, DB). Align with backend needs.
98
+ 4. Release automation: integrate with existing release scripts (`scripts/`) or add GitHub workflow?
99
+
100
+ ## Next Steps
101
+ 1. Confirm tooling choices (httpx, hatchling) with project maintainers.
102
+ 2. Create initial test scaffolding (Milestone 0) and fail CI intentionally to drive implementation.
103
+ 3. Schedule documentation tasks to coincide with feature milestones so manifest stays accurate.
spaps-0.1.0/TODO.md ADDED
@@ -0,0 +1,39 @@
1
+ # Python Client TODO
2
+
3
+ ## Milestone 0 – Scaffolding
4
+ - [x] Confirm packaging backend choice (`hatchling`) and document rationale
5
+ - [x] Add initial failing metadata tests (`pyproject` presence, `__version__` export)
6
+ - [x] Implement minimal scaffolding to satisfy metadata tests (pyproject, version module)
7
+
8
+ ## Milestone 1 – Auth Token Lifecycle
9
+ - [x] Design response models for nonce/token flows (pydantic)
10
+ - [x] Add failing auth tests (`request_nonce`, `verify_wallet`, `refresh_tokens`)
11
+ - [x] Implement auth client to satisfy tests using `httpx`
12
+ - [x] Document Python auth flow examples in `docs/api/wallet-authentication.md`
13
+
14
+ ## Milestone 2 – Session Validation
15
+ - [x] Add failing session validation tests (`validate`, `current`)
16
+ - [x] Implement sessions module with structured responses
17
+ - [x] Update Sessions docs and manifest entries with Python references
18
+
19
+ ## Milestone 3 – Configuration & Environment
20
+ - [x] Add failing config tests (env defaults, timeouts, retries)
21
+ - [x] Implement configuration module and HTTP client abstraction
22
+ - [x] Extend `.env.example` tips + add new Python backend doc
23
+
24
+ ## Milestone 4 – Packaging & Distribution
25
+ - [x] Add build/install integration tests (`python -m build`, temp venv)
26
+ - [x] Finalize metadata (classifiers, dependencies, extras)
27
+ - [x] Draft release checklist in docs
28
+
29
+ ## Milestone 5 – Payments & Usage
30
+ - [x] Identify priority routes (Stripe checkout, balance, usage reporting)
31
+ - [x] Add failing tests for `PaymentsClient.create_checkout_session`
32
+ - [x] Add failing tests for balance/usage endpoints
33
+ - [x] Implement payments client with models & error handling
34
+ - [x] Update payments docs/manifest with Python references
35
+
36
+ ## Ongoing
37
+ - [ ] Keep changelog up to date (`packages/python-client/CHANGELOG.md`)
38
+ - [ ] Wire pytest command into repo scripts/CI
39
+ - [ ] Align SDK and Python docs for every new feature