Skip to main content

Python Client SDK for the FlexPrice API.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flexprice_py-2.0.1.tar.gz (208.1 kB view details)

Uploaded Source

Built Distribution

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

flexprice_py-2.0.1-py3-none-any.whl (510.2 kB view details)

Uploaded Python 3

File details

Details for the file flexprice_py-2.0.1.tar.gz.

File metadata

  • Download URL: flexprice_py-2.0.1.tar.gz
  • Upload date:
  • Size: 208.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for flexprice_py-2.0.1.tar.gz
Algorithm Hash digest
SHA256 18f30d82edf1727cfb2d1c3e93c5e717ceed4587e76f23309f8014ade08da3b2
MD5 bdd8b6d3eb2f69a57144ea099ae55237
BLAKE2b-256 7984047238c9b837677212ebc1c8b38b3ffbae6c478709ca6a3cdd3c42e10154

See more details on using hashes here.

File details

Details for the file flexprice_py-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: flexprice_py-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 510.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for flexprice_py-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f4ad1b12bfffc738530b1fd7550d6f95de0d4da4058daa3095b2f53e137650fc
MD5 e5147f632cda74d443a694ca83b1bb2d
BLAKE2b-256 753c05d3b62088864ed71046f9a996f38d4d808d0d5afdfe1137c5630b2cd461

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page