Skip to main content

paiment (Python SDK)

Official Python SDK for the Paiment billing API.

npm users: install @paiment/sdk instead. 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",
        external_plan_id="price_pro",
        plan_name="Pro",  # optional naming hint
        price=2999,
        currency="USD",
        interval="monthly",
    )

    client.usage.report(
        user_id="user_123",
        input_tokens=1250,
        output_tokens=340,
        provider="openai",
        model="gpt-4o",
        external_plan_id="price_pro",
    )

    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",
        external_plan_id="price_pro",
        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",
        external_plan_id="price_pro",
    )

API reference

Subscriptions

Method Description
create(user_id, external_plan_id, price, currency, interval, plan_name=...) 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, external_plan_id, price, currency, interval, plan_name=...) 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(..., external_plan_id=...) Record usage
list(user_id=..., page=..., limit=...) List usage rows

Plans

Method Description
create(name, currency, external_plan_id, list_price_cents=...) Create plan
list() / get(id) / update(id, ...) / delete(id) CRUD

Fields

Field Meaning
user_id Your identifier for the end-user
external_plan_id Your plan key (required on plans, subscriptions, users, usage)
plan_name Optional display name; naming hint when auto-creating a plan
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

Changelog

0.3.0

  • Client plan key is external_plan_id (required on usage, subscriptions, users, plans)
  • Removed write-path plan_id; internal ids remain server-owned
  • plan_name is an optional naming hint for auto-created plans
  • Removed nested usage-based / fixed price fields from plan APIs

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.3.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

paiment-0.3.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file paiment-0.3.0.tar.gz.

File metadata

  • Download URL: paiment-0.3.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

Hashes for paiment-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a79b6d46216fd24376d08cd07ad801f3f4933de22eb884cd6d156539a0d5ddd7
MD5 8905c6c6dcebfb6aa401d5dbffc151bf
BLAKE2b-256 2f561f267ddb234b33e60a8751c16d193123ace7b406574c66fe4b417c3ff079

See more details on using hashes here.

File details

Details for the file paiment-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: paiment-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for paiment-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5dcfec0a9c9e2147e5729f4fd5b34f55f06d853ef3debd2f8452d8c942e8c89
MD5 8182439dfe75ff5d1fc2a8d88e5495b8
BLAKE2b-256 43bac91315271cb2b1c70676d4c2ff964204e4464f637fb60fa38ab3343603cc

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page