Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 1.2.2 instead.
Reason given by maintainers: Yanked release '1.0.0'

aforo-graphql-metering

Meter every GraphQL operation with AST-accurate complexity scoring — one Aforo event per query/mutation, via a Strawberry extension or an ASGI middleware that works with any GraphQL server.

Version: 1.0.0 · Apache-2.0 · Changelog · User guide

Install

Intended public install:

pip install aforo-graphql-metering
# integrations (pick what you use):
pip install "aforo-graphql-metering[strawberry]"
pip install "aforo-graphql-metering[graphene]"
pip install "aforo-graphql-metering[ariadne]"
pip install "aforo-graphql-metering[httpx]"     # faster HTTP flush than stdlib urllib

Not yet on PyPI — install from source for now:

git clone https://github.com/aforoai/SDKs.git
cd SDKs/aforo-metering-sdks/python-graphql     # folder holding setup.py
pip install -e .
pip install -e ".[strawberry]"            # or [graphene] / [ariadne] / [httpx]

The one required dependency is graphql-core>=3.2 — the SDK parses the operation document itself to score complexity. Without it, record() is a no-op.

Quickstart — Strawberry

Best when you run a Strawberry schema and want per-operation billing without touching resolvers.

import os, strawberry
from aforo_graphql_metering import AforoGraphQlBilling, strawberry_extension

billing = AforoGraphQlBilling(
    tenant_id="tenant_acme",
    product_id="prod_graphql_gateway",
    api_key=os.environ["AFORO_API_KEY"],
    ingestor_url="https://api.aforo.ai",
    schema_version="v2.1",
)

schema = strawberry.Schema(query=Query, extensions=[strawberry_extension(billing)])

Quickstart — ASGI middleware (any GraphQL server)

from starlette.applications import Starlette
from aforo_graphql_metering import AforoGraphQlBilling, asgi_middleware

billing = AforoGraphQlBilling(
    tenant_id="tenant_acme",
    product_id="prod_graphql_gateway",
    api_key=os.environ["AFORO_API_KEY"],
    ingestor_url="https://api.aforo.ai",
)
app = Starlette(routes=[...])
app = asgi_middleware(billing, path="/graphql")(app)   # only intercepts /graphql

Works with Ariadne, graphql-core HTTP, Graphene-ASGI, and custom ASGI GraphQL servers. Each metered operation produces one graphql_api.operations event POSTed to https://api.aforo.ai/v1/ingest/batch with X-API-Key: <api_key> and X-Tenant-Id: <tenant_id>.

⚠ Events are sent to the ingestor's /v1/ingest/batch path as {"events": [...]}, at most 1000 events per request (larger buffers are split). Set ingestor_url to the host only — the SDK appends the path. Use https://api.aforo.ai.

tenant_id is fixed from your config and sent as a header — never read from a caller-controlled value. The default customer-ID extractor reads x-customer-id from request headers (or the Strawberry context); operations with no resolvable customer ID are not metered.

Configuration

Constructor arguments for AforoGraphQlBilling(...):

Option Type Default What it does
tenant_id str — (required) Aforo tenant; sent as X-Tenant-Id.
product_id str — (required) Product the operations bill against.
api_key str — (required) Aforo API key, sent to the ingestor as X-API-Key.
ingestor_url str — (required) Host; /v1/ingest/batch is appended.
schema_version str? None Stamped on each event for versioned-schema reporting.
flush_interval_sec float 5.0 Background flush cadence (a daemon thread runs from construction).
flush_count int 50 Buffer size that triggers an immediate flush.
on_error Callable[[Exception], None]? logs Called on permanent batch failure, and with the ingestor's errors[].message when it rejects events.
product_type str "GRAPHQL_API" Top-level productType sent on every event (trimmed and upper-cased; values the SDK does not know are passed through). Override per event with record(..., product_type=...).
customer_id_extractor Callable[[Any], str?]? reads x-customer-id Resolve the billed customer from the request/context.
complexity_scorer Callable[[doc, op_name], (int, int)]? field_count + 5 × max_depth Returns (complexity, field_count).

Retry is fixed at 3 attempts (1s / 2s backoff between them); 408 and 5xx are retried, 429 waits for Retry-After (capped at 60 s), and any other 4xx is not retried.

Walk me through it

Install → wire the extension → run a query → confirm the event in Aforo, step by step, is in USER_GUIDE.md.

What this doesn't cover

It meters operations, not individual resolver fields or DataLoader batches — one event per top-level operation, with complexity/field counts as attributes. It doesn't enforce a complexity budget or reject expensive queries; that's a gateway/server concern. GraphQL subscriptions over WebSocket aren't covered here — use aforo-ws-metering. Pricing and metric mapping are in the Aforo console.

Metadata

Release files for aforo-graphql-metering 1.0.0

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

Source distribution (sdist)

Source distribution for aforo-graphql-metering 1.0.0
File Size Uploaded
aforo_graphql_metering-1.0.0.tar.gz 18.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aforo-graphql-metering 1.0.0
File Interpreter ABI Platform
aforo_graphql_metering-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.1 kB

Release files / aforo_graphql_metering-1.0.0.tar.gz

Download URL aforo_graphql_metering-1.0.0.tar.gz
Size 18.2 kB
Tags Source
SHA-256 checksum
How to use checksums
2df910a1869620abe79bbf16ff8d7c6fc9f3f89472516a27a98b29d6daa5c2fe
BLAKE2b-256 checksum
How to use checksums
447c32ed9832477d60371759dd108d1603504023d087595f10a2e68f79d2fc89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release files / aforo_graphql_metering-1.0.0-py3-none-any.whl

Download URL aforo_graphql_metering-1.0.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
77e9112df2b7e4e996870742d66fd087f1c44cfb127135e39f49ecb74a108385
BLAKE2b-256 checksum
How to use checksums
995a84cfe4ec20e4371df3aa789f87499c69aaa0e7c0803cb2411ed853f89796
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 1, 2026.

Transparency log

Release history Release notifications | RSS feed

1.2.2

2 release files

This release

1.0.0 This release

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