Official Python SDK for the Paiment billing API
Project description
paiment (Python SDK)
Official Python SDK for the Paiment billing API.
npm users: install
@paiment/sdkinstead. This package is the Python equivalent.
Use it in your backend to register subscribers, report LLM usage, and manage plans.
Install
pip install paiment
Python 3.9+.
Setup
Get an API key from Settings → API Keys.
| Key format | Notes |
|---|---|
tenantId:workspaceId:secret |
Recommended |
tenantId:secret |
Pass workspace_id on the client |
from paiment import PaimentClient
client = PaimentClient(api_key="tenantId:workspaceId:secret")
# client = PaimentClient(api_key="...", base_url="http://localhost:5246")
Quick start
from paiment import PaimentClient
with PaimentClient(api_key="tenantId:workspaceId:secret") as client:
sub = client.subscriptions.create(
user_id="user_123",
plan_name="Pro",
price=2999,
currency="USD",
interval="monthly",
)
client.usage.report(
user_id="user_123",
input_tokens=1250,
output_tokens=340,
provider="openai",
model="gpt-4o",
plan_id=sub.plan_id,
)
client.subscriptions.end(sub.id)
Async
from paiment import AsyncPaimentClient
async with AsyncPaimentClient(api_key="tenantId:workspaceId:secret") as client:
sub = await client.subscriptions.create(
user_id="user_123",
plan_name="Pro",
price=2999,
currency="USD",
interval="monthly",
)
await client.usage.report(
user_id="user_123",
input_tokens=1250,
output_tokens=340,
provider="openai",
model="gpt-4o",
)
API reference
Subscriptions
| Method | Description |
|---|---|
create(user_id, plan_name, price, currency, interval, ...) |
New subscription |
list(user_id=..., status=...) |
List subscriptions |
get(subscription_id) |
Get by id |
update(subscription_id, data) |
Patch subscription |
end(subscription_id) |
Close subscription |
cancel(subscription_id) |
End immediately |
Users
| Method | Description |
|---|---|
create(user_id, plan_name, price, currency, interval, ...) |
User + subscription shortcut |
get(user_id) |
Get by your user id |
list(plan_name=..., page=..., limit=...) |
List users |
update(user_id, ...) |
Partial update |
delete(user_id) |
Delete user |
Usage
| Method | Description |
|---|---|
report(user_id, input_tokens, output_tokens, provider, model, ...) |
Record usage |
list(user_id=..., page=..., limit=...) |
List usage rows |
Plans
| Method | Description |
|---|---|
create(name, currency, list_price_cents=..., ...) |
Create plan |
list() / get(id) / update(id, ...) / delete(id) |
CRUD |
Fields
| Field | Meaning |
|---|---|
user_id |
Your identifier for the end-user |
plan_name |
Plan catalog name |
price |
Subscription price in cents |
list_price_cents |
Catalog list price on plans only |
Errors
from paiment import PaimentAuthError, PaimentNotFoundError, PaimentValidationError, PaimentError
| Class | HTTP status |
|---|---|
PaimentAuthError |
401 |
PaimentNotFoundError |
404 |
PaimentValidationError |
400 |
PaimentError |
other |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
paiment-0.2.0.tar.gz
(9.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
paiment-0.2.0-py3-none-any.whl
(10.9 kB
view details)
File details
Details for the file paiment-0.2.0.tar.gz.
File metadata
- Download URL: paiment-0.2.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e47c1a2d6f6c0e879f98b1913e4c99431b5099c5e88c0842e3c9fa81dad3a1e5
|
|
| MD5 |
fc4b54696118149d756bbc198f8b7a4b
|
|
| BLAKE2b-256 |
c20009a9663b1b2e42b077b2fd99a5100bb2a2f0908c7385e1c012bb4d5421d8
|
File details
Details for the file paiment-0.2.0-py3-none-any.whl.
File metadata
- Download URL: paiment-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21916d72c3781f492760b8bc22bb330385e0c19b779b3c27cc1fcf2d11cb4912
|
|
| MD5 |
73bec1153a5e6b0fd5966f423b753ebd
|
|
| BLAKE2b-256 |
8d876aed9b3e028a075dbd772c49da2d6bc1147863e06f8e2c6d67d795a58fb2
|