Skip to main content

FlexPrice Python SDK

Type-safe Python client for the FlexPrice API: billing, metering, and subscription management for SaaS and usage-based products.

Requirements

  • Python 3.10+

Installation

pip install flexprice

With uv or poetry:

uv add flexprice
# or
poetry add flexprice

Runnable samples are in the examples/ directory.

Quick start

Initialize the client with your server URL and API key, then ingest an event:

from flexprice import Flexprice

# Always include /v1 in the base URL; no trailing space or slash.
with Flexprice(
    server_url="https://us.api.flexprice.io/v1",
    api_key_auth="YOUR_API_KEY",
) as flexprice:
    # Ingest an event
    result = flexprice.events.ingest_event(
        request={
            "event_name": "Sample Event",
            "external_customer_id": "customer-123",
            "properties": {"source": "python_app", "environment": "test"},
            "source": "python_app",
        }
    )
    print(result)

Async usage

The same client supports async when used as an async context manager:

import asyncio
from flexprice import Flexprice

async def main():
    async with Flexprice(
        server_url="https://us.api.flexprice.io/v1",
        api_key_auth="YOUR_API_KEY",
    ) as flexprice:
        result = await flexprice.events.ingest_event_async(
            request={
                "event_name": "Sample Event",
                "external_customer_id": "customer-123",
                "properties": {"source": "python_async", "environment": "test"},
                "source": "python_async",
            }
        )
        print(result)

asyncio.run(main())

Authentication

  • Pass your API key as api_key_auth when creating the client. The SDK sends it in the x-api-key header.
  • Prefer environment variables (e.g. FLEXPRICE_API_KEY) and load them in code; get keys from your FlexPrice dashboard or docs.

Error handling

API errors are raised as exceptions. Catch them and inspect the response as needed:

try:
    with Flexprice(server_url="...", api_key_auth="...") as flexprice:
        result = flexprice.events.ingest_event(request={...})
except Exception as e:
    print(f"Error: {e}")
    # Inspect status code and body if available on the exception

See the API docs for error formats and status codes.

Features

  • Full API coverage (customers, plans, events, invoices, payments, entitlements, etc.)
  • Sync and async support
  • Type-safe request/response models (Pydantic)
  • Built-in retries and error handling

For a full list of operations, see the API reference and the examples in this repo.

Troubleshooting

  • Missing or invalid API key: Ensure api_key_auth is set (or set FLEXPRICE_API_KEY and pass it in). Keys are for server-side use only.
  • Wrong server URL: Use https://us.api.flexprice.io/v1. Always include /v1; no trailing space or slash.
  • 4xx/5xx on ingest: Event ingest returns 202 Accepted; for errors, check request fields (event_name, external_customer_id, properties, source) against the API docs.

Documentation

Metadata

Release files for flexprice-py 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flexprice-py 2.0.2
File Size Uploaded
flexprice_py-2.0.2.tar.gz 220.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for flexprice-py 2.0.2
File Interpreter ABI Platform
flexprice_py-2.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 743.1 kB

Release files / flexprice_py-2.0.2.tar.gz

Download URL flexprice_py-2.0.2.tar.gz
Size 220.7 kB
Tags Source
SHA-256 checksum
How to use checksums
3adf4c9bee4e1ab2510d3c29944f5f14e2b73184faeaeedceb2554e556e3200c
BLAKE2b-256 checksum
How to use checksums
8fe0e7ca9cca06af18b31292709e87e798487230f2d041b732abaf1a180247f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / flexprice_py-2.0.2-py3-none-any.whl

Download URL flexprice_py-2.0.2-py3-none-any.whl
Size 522.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bf5a6bece0c8b5812037ca295c55bd8c168868e35eaef14f61ffd4215ff8a41
BLAKE2b-256 checksum
How to use checksums
7120fd420ea15ff20510381568eeb68fef92e9cbfab778f8257ad8c96a51d2d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release history Release notifications | RSS feed

This release

2.0.2 This release

2 release files

2.0.1

2 release files

2.0.0

2 release files

0.0.58

2 release files

0.0.57

2 release files

0.0.56

2 release files

0.0.55

2 release files

0.0.52

2 release files

0.0.50

2 release files

0.0.47

2 release files

0.0.46

2 release files

0.0.45

2 release files

0.0.44

2 release files

0.0.43

2 release files

0.0.42

2 release files

0.0.41

2 release 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