Orb Billing Python SDK

4.55.0 · active · verified Mon Apr 13

The orb-billing library is the official Python client SDK for accessing the Orb REST API, which provides a modern pricing platform for subscription and usage-based billing. It offers both synchronous and asynchronous clients, built on `httpx`, with type definitions for request parameters and response fields. Currently, at version 4.55.0, the SDK is in beta and receives frequent updates, often with new features and API changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize both the synchronous `Orb` and asynchronous `AsyncOrb` clients, authenticate using an API key from an environment variable, and create a new customer. It includes an optional configuration for using `aiohttp` with the async client.

import os
import asyncio
from orb import Orb, AsyncOrb

# --- Synchronous Client Example ---

# It's recommended to set your API key as an environment variable: ORB_API_KEY
# For example: os.environ['ORB_API_KEY'] = 'YOUR_ORB_API_KEY'

def sync_example():
    client = Orb(
        api_key=os.environ.get("ORB_API_KEY", ""),
    )
    try:
        customer = client.customers.create(
            email="example-sync@withorb.com",
            name="Sync Test Customer",
        )
        print(f"Synchronous Customer created: {customer.id}")
    except Exception as e:
        print(f"Synchronous client error: {e}")

# --- Asynchronous Client Example ---

async def async_example():
    async with AsyncOrb(
        api_key=os.environ.get("ORB_API_KEY", ""),
        # http_client=DefaultAioHttpClient(), # Uncomment to use aiohttp
    ) as client:
        try:
            customer = await client.customers.create(
                email="example-async@withorb.com",
                name="Async Test Customer",
            )
            print(f"Asynchronous Customer created: {customer.id}")
        except Exception as e:
            print(f"Asynchronous client error: {e}")

if __name__ == "__main__":
    sync_example()
    asyncio.run(async_example())

view raw JSON →