Python

The official Python client for the Bias API. It is fully type-hinted, ships with both synchronous and asynchronous clients, and is generated from the Bias OpenAPI specification.

Installation

pip install biaspay

Requires Python 3.9 or later.

Usage

Construct a client with your API key and call resource methods directly. Models are returned as fully typed objects.

from biaspay import Bias

client = Bias(api_key="sk_...")  # or set the BIAS_API_KEY environment variable

customer = client.customers.create(name="Acme", email="acme@example.com")
print(customer.id, customer.email)

If you omit api_key, the client reads it from the BIAS_API_KEY environment variable.

Pagination

List methods return a page object. Iterate a single page, or use auto_paging_iter() to walk every page transparently — the SDK fetches subsequent pages for you using the cursor.

# One page.
page = client.customers.list(limit=100)
for customer in page.data:
    ...

# Every page, fetched lazily.
for customer in client.customers.list().auto_paging_iter():
    ...

A page exposes data (the items on that page) and has_more (whether more pages exist).

Pass expand to inline related objects instead of receiving bare IDs. See expansion for the full list of expandable fields.

payment = client.payments.retrieve("pay_123", expand=["customer"])
payment.customer  # a Customer model, not just an id

Streaming events

The events resource can return a long-lived stream of events instead of a single page. Iterate it to process events as they arrive.

for event in client.events.stream(filters={"type": "customer.created"}):
    customer = event.state
    print(f"New customer: {customer.name}")

The async client exposes the same method as an async iterator:

async for event in client.events.stream(filters={"type": "customer.created"}):
    ...

See the event streaming guide for more.

Error handling

Non-2xx responses raise typed exceptions. Every SDK exception derives from biaspay.BiasError, so you can catch broadly or narrow to a specific error type.

from biaspay import InvalidRequestError, RateLimitError

try:
    client.payments.create(amount=-1)
except InvalidRequestError as e:
    print(e.code, e.param, e.message, e.status_code, e.request_id)

The full exception hierarchy:

ExceptionRaised when
BiasErrorBase class for all SDK exceptions.
APIErrorThe API returned an error response.
InvalidRequestErrorThe request was malformed or failed validation (400/422).
AuthenticationErrorThe API key is missing or invalid (401).
PaymentErrorA payment was declined or could not be processed.
IdempotencyErrorAn idempotency key was reused with a different request.
RateLimitErrorToo many requests (429).
ServerErrorThe API returned a 5xx response.
APIConnectionErrorThe request could not reach the API.
APITimeoutErrorThe request timed out.

Async

AsyncBias mirrors Bias exactly, with awaited methods. Use it as an async context manager so the underlying HTTP client is closed cleanly.

import asyncio
from biaspay import AsyncBias

async def main():
    async with AsyncBias(api_key="sk_...") as client:
        customer = await client.customers.create(name="Acme")
        async for c in client.customers.list().auto_paging_iter():
            ...

asyncio.run(main())

Configuration

client = Bias(
    api_key="sk_...",
    base_url="https://api.biaspay.com",
    timeout=30.0,        # seconds
    max_retries=1,       # retried on 429 / 5xx / connection errors
    default_headers={"x-app": "my-app"},
)

To reuse connection pools or customize transport, inject your own httpx.Client (or httpx.AsyncClient for AsyncBias):

import httpx

client = Bias(api_key="sk_...", http_client=httpx.Client(proxies="http://localhost:8080"))