audr-sink-chargebee
Status: alpha. The record model tracks AUDR v1.0.0 and is stable; the Python API may change in minor releases before 1.0.
The Chargebee sink for AUDR. Delivers audr.AUDR record
batches to a site's usage-ingest batch endpoint.
pip install audr-sink-chargebee
import asyncio
import audr
from audr_sink_chargebee import ChargebeeSink
# A full record; construction is documented in the core SDK README:
# https://github.com/openaudr/audr/blob/main/adapters/core/python/README.md
# Chargebee additionally requires attribution.subscription_id.
record = audr.AUDR(...)
async def main() -> None:
sink = ChargebeeSink(site="acme", api_key="cb_live_...")
async with audr.Client(
sink,
emitter=audr.Emitter(component="harness", name="my-harness", version="1.4.0"),
) as client:
result = client.record(record)
assert result.queued, result.issues
asyncio.run(main())
Every record requires an emitter. Pass emitter= to the Client as above and it is
stamped onto any record that arrives without one; a record that reaches validation
with no emitter is rejected with a /emitter issue and never sent.
Configure the sink with site and api_key. Pass them explicitly or set CHARGEBEE_SITE
and CHARGEBEE_API_KEY; explicit values take precedence, and api_key is always required.
Credentials belong to the sink and never appear in logs, errors, or repr().
The sink sends each batch to https://{site}.{ingest_domain}/api/v2/batch/usage_events.
ingest_domaindefaults toingest.chargebee.com, the Chargebee batch ingest domain.- Override the domain with
ingest_domain=orCHARGEBEE_INGEST_DOMAIN, for example to target a test environment. - For a host that is not a
{site}subdomain of the ingest domain, set the full origin withingest_url=orCHARGEBEE_INGEST_URL. This is mutually exclusive withsiteandingest_domain.
Routing and delivery
- Chargebee routes on
attribution.subscription_id. A record with nosubscription_idis never sent;deliver()returns it as aRejectedRecord(record_id, "missing_subscription_id"). record_idis used as Chargebee'sdeduplication_idandtiming.event_time(as milliseconds) becomesusage_timestamp.- AUDR records are nested; Chargebee's ingest API accepts scalar properties
only, so the sink flattens every field to reversible names such as
usage_llm_input_tokens. The default separator is_; it is configurable viaseparator=and must be one or more underscores, since Chargebee property names may only contain letters, digits, and underscores. - A batch is sent as one request. If Chargebee refuses it as too large it
answers
413anddeliver()fails the whole batch withdetail="payload_too_large", dropping every record in it; send fewer records per request withClient(batch_max_size=...). That bounds the record count, not the byte size — a single record too large on its own cannot be delivered. - When a
207response body contains a failed event that cannot be matched back to a record in the batch (an unrecognized or duplicateddeduplication_id), every non-rejected record in that batch is conservatively reported asunknownrather than assumed accepted;record_idmakes a replay idempotent. close()is idempotent.
Each HTTP response becomes one audr.BatchResult:
| Response | Outcome | detail |
|---|---|---|
202, 207 |
ACCEPTED; rejected and unknown name individual records |
|
401 |
PERMANENT_FAILURE |
auth |
413 |
PERMANENT_FAILURE |
payload_too_large |
other 4xx |
PERMANENT_FAILURE |
http_<status> |
429, 5xx, network error |
RETRYABLE_FAILURE, once RetryPolicy is exhausted |
Data handling
This sink flattens and forwards every field of the record, including
attribution.labels and any x_* extension, to your Chargebee site. Delivery is
verbatim, and no downstream component re-checks the record. attribution.labels
MUST NOT contain PII and resource.key_name is a label, never key material — see
the security policy for
the full rules. Enforce them where the record is built — that is the last point at
which they can be enforced.
Retry, transport and flattening
Delivery behaviour is tuned on the constructor, alongside the site and api_key
described above:
from audr_sink_chargebee import ChargebeeSink, HttpTransportConfig, RetryPolicy
sink = ChargebeeSink(
site="acme",
api_key="...",
retry=RetryPolicy(max_attempts=3),
http=HttpTransportConfig(read_timeout=10.0),
separator="_",
)
Contributing
Contributions are welcome — see
CONTRIBUTING.md.
Licensed under Apache-2.0.
Metadata
Release files for audr-sink-chargebee 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| audr_sink_chargebee-0.1.0.tar.gz | 17.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| audr_sink_chargebee-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 38.8 kB
Release files / audr_sink_chargebee-0.1.0.tar.gz
| Download URL | audr_sink_chargebee-0.1.0.tar.gz |
|---|---|
| Size | 17.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
681077a9b44a702d92b7b31e76ad50598f1317b69c558003790788aa1cdcf2ce
|
|
BLAKE2b-256 checksum How to use checksums |
37fccf965c779891753d53cee969505d3c58ba96f570c659a0176395aa9fc958
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.0
|
Release files / audr_sink_chargebee-0.1.0-py3-none-any.whl
| Download URL | audr_sink_chargebee-0.1.0-py3-none-any.whl |
|---|---|
| Size | 21.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b28cc6f77e2aaf96b3d4ef1e4964ec1652198748dd5c42655caf83e5db7f60c5
|
|
BLAKE2b-256 checksum How to use checksums |
a556f5c58aaaff840f9a76e2388a15d9b660002351b7e8443034ccd388b8c246
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.0
|