solvapay-python 0.6.0__py3-none-any.whl

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,268 @@
1
+ Metadata-Version: 2.4
2
+ Name: solvapay-python
3
+ Version: 0.6.0
4
+ Summary: Community Python SDK for SolvaPay (agent-native payment rails)
5
+ Project-URL: Homepage, https://github.com/dhruv-sanan/solvapay-python
6
+ Project-URL: Issues, https://github.com/dhruv-sanan/solvapay-python/issues
7
+ Project-URL: Official TS SDK, https://github.com/solvapay/solvapay-sdk
8
+ Author: Dhruv Sanan
9
+ License: MIT
10
+ License-File: LICENSE
11
+ Keywords: agents,fintech,mcp,payments,solvapay
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.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: httpx>=0.27
22
+ Requires-Dist: pydantic>=2.5
23
+ Provides-Extra: fastapi
24
+ Requires-Dist: fastapi>=0.110; extra == 'fastapi'
25
+ Provides-Extra: langchain
26
+ Requires-Dist: langchain-core<0.4,>=0.3; extra == 'langchain'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # solvapay-python
30
+
31
+ Community Python SDK for [SolvaPay](https://solvapay.com) — payment rails for the agentic economy.
32
+
33
+ > **Status:** v0.5, community-maintained. Pending official adoption.
34
+ > Mirrors the most-used surface of [@solvapay/core](https://github.com/solvapay/solvapay-sdk).
35
+
36
+ Python is the dominant language for agent frameworks (LangChain, FastMCP, CrewAI, AutoGen). SolvaPay's official SDK is TypeScript-only. This SDK brings first-class Python support so agent developers can gate tools behind paywalls without switching ecosystems.
37
+
38
+ > 🎬 **New in v0.5:** Paywall state classifier (`paywall_state` module) and LangChain `monetize_tool` decorator — gate any LangChain tool behind a SolvaPay paywall with one line.
39
+ > **v0.4:** Async client (`AsyncSolvaPay`), lifecycle ops, typed webhook events.
40
+
41
+ ## Install
42
+
43
+ ```bash
44
+ pip install git+https://github.com/dhruv-sanan/solvapay-python
45
+ ```
46
+
47
+ ## Quickstart
48
+
49
+ **Sync:**
50
+ ```python
51
+ from solvapay import SolvaPay
52
+
53
+ sv = SolvaPay() # reads SOLVAPAY_SECRET_KEY from env
54
+
55
+ customer_ref = sv.ensure_customer("user_42", email="alice@example.com")
56
+ limits = sv.check_limits(customer_ref=customer_ref, product_ref="prd_0QKI8NHF")
57
+ if not limits.within_limits:
58
+ print("Upgrade needed:", limits.checkout_url)
59
+
60
+ session = sv.create_checkout_session(
61
+ customer_ref=customer_ref,
62
+ product_ref="prd_0QKI8NHF",
63
+ return_url="https://your-app.com/done",
64
+ )
65
+ print(session.checkout_url)
66
+ ```
67
+
68
+ **Async:**
69
+ ```python
70
+ import asyncio
71
+ from solvapay import AsyncSolvaPay
72
+
73
+ async def main() -> None:
74
+ async with AsyncSolvaPay() as sv:
75
+ customer_ref = await sv.ensure_customer("user_42", email="alice@example.com")
76
+ limits = await sv.check_limits(customer_ref=customer_ref, product_ref="prd_0QKI8NHF")
77
+ if not limits.within_limits:
78
+ print("Upgrade needed:", limits.checkout_url)
79
+ return
80
+ session = await sv.create_checkout_session(
81
+ customer_ref=customer_ref,
82
+ product_ref="prd_0QKI8NHF",
83
+ )
84
+ print(session.checkout_url)
85
+
86
+ asyncio.run(main())
87
+ ```
88
+
89
+ ## Ecosystem integrations
90
+
91
+ ### LangChain
92
+
93
+ Gate any LangChain tool with `monetize_tool`:
94
+
95
+ ```python
96
+ from solvapay.langchain import monetize_tool
97
+ from langchain_core.tools import Tool
98
+
99
+ raw = Tool.from_function(name="search", func=do_search, description="Search the web.")
100
+ paid = monetize_tool(raw, product="prd_0QKI8NHF")
101
+ ```
102
+
103
+ When the customer is over-limit the tool returns a structured dict with `checkout_url` — the agent surfaces it to the user instead of raising an exception.
104
+
105
+ ```bash
106
+ pip install solvapay-python[langchain]
107
+ ```
108
+
109
+ See [`examples/langchain-paywall/`](examples/langchain-paywall/) for a full agent example.
110
+
111
+ ### FastMCP
112
+
113
+ See [`examples/fastmcp-paywall/`](examples/fastmcp-paywall/) for a FastMCP server with two paywalled tools, ready to plug into Claude Desktop.
114
+
115
+ ### FastAPI
116
+
117
+ Use `webhook_router` to mount a verified webhook endpoint:
118
+
119
+ ```python
120
+ from solvapay.fastapi import webhook_router
121
+ app.include_router(webhook_router(secret=os.environ["SOLVAPAY_WEBHOOK_SECRET"], on_event=handle))
122
+ ```
123
+
124
+ ```bash
125
+ pip install solvapay-python[fastapi]
126
+ ```
127
+
128
+ ## Paywall state classifier
129
+
130
+ `solvapay.paywall_state` maps a `LimitResponse` to a structured recovery action:
131
+
132
+ ```python
133
+ from solvapay.paywall_state import decide
134
+
135
+ limits = sv.check_limits(customer_ref="cus_123", product_ref="prd_xyz")
136
+ if not limits.within_limits:
137
+ d = decide(limits)
138
+ print(d.state) # PaywallState.UPGRADE_REQUIRED
139
+ print(d.message) # "You don't have an active plan..."
140
+ print(d.recovery_tool) # "upgrade"
141
+ print(d.checkout_url) # "https://solvapay.com/c/..."
142
+ ```
143
+
144
+ ## Examples
145
+
146
+ | Path | What it shows |
147
+ |---|---|
148
+ | [`examples/fastmcp-paywall/`](examples/fastmcp-paywall/) | FastMCP server with two paywalled tools. Demo for `@paywall.require` + MCP. |
149
+ | [`examples/langchain-paywall/`](examples/langchain-paywall/) | LangChain agent with `monetize_tool`. Shows paywall response in agent trace. |
150
+
151
+ ## TS ↔ Python parity
152
+
153
+ ```typescript
154
+ // TypeScript (@solvapay/core)
155
+ const sv = createSolvaPay();
156
+ const session = await sv.createCheckoutSession({
157
+ customerRef: "cus_123",
158
+ productRef: "prd_0QKI8NHF",
159
+ });
160
+ ```
161
+
162
+ ```python
163
+ # Python (solvapay-python)
164
+ sv = SolvaPay()
165
+ session = sv.create_checkout_session(
166
+ customer_ref="cus_123",
167
+ product_ref="prd_0QKI8NHF",
168
+ )
169
+ ```
170
+
171
+ ## Supported methods
172
+
173
+ **Core:**
174
+
175
+ | Python | TypeScript equivalent | Description |
176
+ |---|---|---|
177
+ | `create_checkout_session` | `createCheckoutSession` | Hosted checkout URL |
178
+ | `ensure_customer` | `ensureCustomer` | Idempotent customer upsert |
179
+ | `get_customer` | `getCustomer` | Fetch customer by ref / email |
180
+ | `check_limits` | `checkLimits` | Usage / purchase limit check |
181
+ | `verify_webhook` | `verifyWebhook` | HMAC-SHA256 signature verification |
182
+
183
+ **Lifecycle (new in v0.4):**
184
+
185
+ | Python | Verb + path | Description |
186
+ |---|---|---|
187
+ | `track_usage` | `POST /v1/sdk/usages` | Record metered usage |
188
+ | `update_customer` | `PATCH /v1/sdk/customers/{ref}` | Update customer email / name |
189
+ | `get_customer_balance` | `GET /v1/sdk/customers/{ref}/balance` | Credit balance |
190
+ | `cancel_purchase` | `POST /v1/sdk/purchases/{ref}/cancel` | Cancel a subscription |
191
+ | `reactivate_purchase` | `POST /v1/sdk/purchases/{ref}/reactivate` | Reactivate cancelled purchase |
192
+
193
+ All methods available on both `SolvaPay` (sync) and `AsyncSolvaPay` (async).
194
+
195
+ ## Webhook handler (FastAPI)
196
+
197
+ ```python
198
+ from fastapi import FastAPI, HTTPException, Request
199
+ from solvapay import SolvaPayError
200
+ from solvapay.webhooks import verify_webhook
201
+ import os
202
+
203
+ app = FastAPI()
204
+
205
+ @app.post("/webhooks/solvapay")
206
+ async def handle_webhook(request: Request) -> dict:
207
+ body = (await request.body()).decode()
208
+ sig = request.headers.get("sv-signature", "")
209
+ try:
210
+ event = verify_webhook(
211
+ body=body,
212
+ signature=sig,
213
+ secret=os.environ["SOLVAPAY_WEBHOOK_SECRET"],
214
+ )
215
+ except SolvaPayError as exc:
216
+ raise HTTPException(401, str(exc))
217
+ # Option A: dict (default)
218
+ if event["type"] == "purchase.created":
219
+ ... # grant access
220
+
221
+ # Option B: typed discriminated union (new in v0.4)
222
+ from solvapay import WebhookEvent, PurchaseCreated
223
+ from pydantic import TypeAdapter
224
+ typed = TypeAdapter(WebhookEvent).validate_python(event)
225
+ if isinstance(typed, PurchaseCreated):
226
+ ... # typed access to typed.data, typed.id, etc.
227
+
228
+ return {"received": True}
229
+ ```
230
+
231
+ > **Important:** use `await request.body()` (raw bytes), not `await request.json()`.
232
+ > Re-serialising JSON changes whitespace and breaks the HMAC signature.
233
+
234
+ ## Environment variables
235
+
236
+ | Variable | Purpose |
237
+ |---|---|
238
+ | `SOLVAPAY_SECRET_KEY` | API secret key (required) |
239
+ | `SOLVAPAY_API_BASE_URL` | Override API base URL (optional) |
240
+ | `SOLVAPAY_WEBHOOK_SECRET` | Webhook signing secret (required for `verify_webhook`) |
241
+
242
+ ## Non-features
243
+
244
+ - **No retries** — add your own retry logic or use `tenacity`
245
+ - **No pagination** — not needed for current endpoints
246
+
247
+ ## Roadmap
248
+
249
+ - v0.1 — sync client, hosted checkout, customers, limits, webhooks ✅
250
+ - v0.2 — `@paywall.require` decorator, FastAPI webhook router ✅
251
+ - v0.3 — FastMCP paywall demo (`examples/fastmcp-paywall/`) ✅
252
+ - v0.4 — async client (`AsyncSolvaPay`), lifecycle ops, typed webhook events ✅
253
+ - v0.5 — paywall state classifier, LangChain `monetize_tool` decorator ✅
254
+
255
+ ## Contributing
256
+
257
+ ```bash
258
+ git clone https://github.com/dhruv-sanan/solvapay-python
259
+ cd solvapay-python
260
+ uv sync
261
+ uv run pytest
262
+ ```
263
+
264
+ Open a PR — all contributions welcome.
265
+
266
+ ## License
267
+
268
+ MIT
@@ -0,0 +1,17 @@
1
+ solvapay/__init__.py,sha256=2PuPBWa46SErGMyCW049H_QS9Nm3jbD-V4T7Be8jrRI,1365
2
+ solvapay/_async_client.py,sha256=I2n_g3vRz0E3NiSNfAqmIBoOmVvG3Otal8CqKQVUe3g,12448
3
+ solvapay/_config.py,sha256=yPU_GM77pXwPfIzuncuLRNv4322q5bB9qaawN3izEB8,606
4
+ solvapay/_http.py,sha256=8vY6oXD63cvsymWKb1Nfhzi9k5aco9DyfsxTa8a6OrQ,3026
5
+ solvapay/client.py,sha256=1GjzCVWzfntd7wvSE2ali7OPJrW0TSKtV2y9-aYtLOw,12352
6
+ solvapay/events.py,sha256=m2VLrbLLJpiPfuTryNSL2hB6pHfq4YO0a9kjhT4hniY,1844
7
+ solvapay/exceptions.py,sha256=PLWXtAo8UsBqxScqq2AnWANNRFlzryq2vljt_SnB1jw,511
8
+ solvapay/fastapi.py,sha256=vouWqbc_Yurdg8dIZ7zhO4-J_QxpYnyNgwyLHgDEoHs,2125
9
+ solvapay/langchain.py,sha256=VOrze5-7COE4--kn8JqbyrmwhWwv3XwN3Ol3YMpffgc,2353
10
+ solvapay/models.py,sha256=fsc0fmyTJ124WwbD3g-mGXGHvbepoID-hyNigXNU0Rg,5588
11
+ solvapay/paywall.py,sha256=b52EW8TuJla6jPB0L_uAYTcigEuJgW4xg5fpn-zyE2Q,4678
12
+ solvapay/paywall_state.py,sha256=dHLXru3FlT8YJUIOhr3QOjHF7tzrDMF7t0C_ML1n86Y,4773
13
+ solvapay/webhooks.py,sha256=6EuoISjJzrKEUIoNpt__l2FnJvQR4T7XnT7fzOFHl5U,2738
14
+ solvapay_python-0.6.0.dist-info/METADATA,sha256=xzZfbeCcKzJMf6eD51GfJK5xJSyF6ad6meERW7rMxco,8721
15
+ solvapay_python-0.6.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
16
+ solvapay_python-0.6.0.dist-info/licenses/LICENSE,sha256=wJURmEXLdSdApQdHG-RCwBoZVka1Oux8zNrLxGC30S8,1068
17
+ solvapay_python-0.6.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dhruv Sanan
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
13
+ all 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
21
+ THE SOFTWARE.