Skip to main content

nodii-usage

Python port of @nodii/usage (S08-39, LIB-EVT-22): the STOP check, the meter and the one usage-metered payload. A producer never holds a price and never names a payer.

from nodii_usage import OtherUnit, UsageConfig, define_usage

usage = define_usage(
    UsageConfig(
        source_service="nodii-geo-service",
        topic_prefix="geo",
        outbox_table="geo_outbox",
        platform_tenant_id=platform_tenant_id,
        pool=pool,  # asyncpg.Pool
        slice_keys=("geo.geocode_lookup.google",),
        projection_ready=lambda: snapshot_drained,
    )
)

decision = await usage.check_stop(tenant_id, "geo.geocode_lookup.google")
if decision.status != "allowed":
    ...  # `unavailable` is a refusal too: retry later, or suppress a broadcast

async with conn.transaction():
    await usage.meter(conn, OtherUnit(...))
  • check_stop fails closed: any failure returns status="unavailable", it never raises.
  • apply_usage_denial is the one write path. SetUsageControl, the event and the snapshot all go through it, and the highest source version wins.
  • define_usage_denial_replica gives the replica spec; run get_usage_migration_sql() for the projection and marker tables.

platform_tenant_id is required, and define_usage raises missing_fact unless it is PLATFORM_TENANT_ID (ENTA-37). A unit with no message object whose tenant_id is the Platform tenant meters with payer platform, charge class free:platform_own and ₹0 (S08-2.1), even if it names a free rule. A message unit keeps the payer and charge class from nodii_notify (S08-2). No caller can name that class: platform_own is not a registered free rule.

keys_gen.py is generated; never edit it.

uv run pytest python/usage/tests/

Known limit: widening the slice

The projection stores only the denials inside the service's slice, and one version of a tenant's denials is applied once. A service that adds a key to its slice therefore reads that key as allowed, for a tenant already denied on it, until tenant-service emits that tenant's next version. A redelivery or a snapshot of the same version does not rewrite the row. Because the digest covers only the slice (so the SetUsageControl RPC, which carries only the target's slice, and the event, which carries every denial, agree at one version), a same-version redelivery that the wider slice now sees more of is read as a payload mismatch and quarantined, and so is every later replay of that version; the row is unchanged, and the tenant's next version applies normally. The fix is an open question on STANDARDIZATIONS-AUDIT-19.

Upgrading from 0.2.0

Rows written before this release hold a digest of the whole message, while this release digests only the slice. Run the one-time repair once, as its own migration, after the rollout: get_usage_digest_repair_sql() returns an idempotent UPDATE that rewrites every row's digest from its stored denials (P-16). Without it, a tenant whose stored row came from a message with a denial outside the slice has every same-version replay quarantined as a payload mismatch until its next version; the stored denials stay correct either way. The repair rebuilds each digest from the row's stored denials, which are the slice the service used when the row was written. It assumes the slice has not changed since: if the service has narrowed its slice, a same-version replay still mismatches and is quarantined until the tenant's next version. Run it once the rollout has finished and no 0.2.0 consumer is still applying (a 0.2.0 pod that writes after the repair puts a whole-message digest back; the repair is idempotent, so re-running it after the rollout is safe). Run it as the table owner or nodii_owner, as migrations are: the projection has RLS, and a service role with no tenant set sees no rows, so the UPDATE would touch nothing. Check that the affected row count equals the table's row count.

Metadata

Release files for nodii-usage 0.5.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 nodii-usage 0.5.0
File Size Uploaded Provenance Actions
nodii_usage-0.5.0.tar.gz 23.8 kB Without provenance Details for nodii_usage-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nodii-usage 0.5.0
File Interpreter ABI Platform Actions
nodii_usage-0.5.0-py3-none-any.whl Python 3 none any Details for nodii_usage-0.5.0-py3-none-any.whl

Total release size: 40.6 kB

Release files / nodii_usage-0.5.0.tar.gz

Download URL nodii_usage-0.5.0.tar.gz
Size 23.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f1e20f7a9f3d1f4fd72ff23f0b3d6a5f0612d3569442ac302957370ca15f7d3d
BLAKE2b-256 checksum
How to use checksums
8fdbf23daa51f7af3ec7799a02dc78313ca77889e781bdbdb6ed648e54086086
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Amazon Linux","version":"2023","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / nodii_usage-0.5.0-py3-none-any.whl

Download URL nodii_usage-0.5.0-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
219e5576f2bf8e8cb8455d6c490200ed2dacf8bbc8279ac09fd531615fec750e
BLAKE2b-256 checksum
How to use checksums
b76557266a9f74f99c2fcdc2c22f1aafd4b2b054086e96046486629ffd4f1930
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Amazon Linux","version":"2023","id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for nodii-usage 0.5.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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