Juntai Usage
juntai-usage is the only producer library for canonical Juntai usage events.
It creates validated juntai.usage/v1 records, derives retry-stable identifiers,
and emits dedicated OpenTelemetry log events through the application's configured
local SDK and Collector sidecar.
The package contains no database driver, service runtime, ingestion endpoint, ledger, query, pricing, calculation, domain, or deployment code. Durable acceptance remains the responsibility of JuntaiUsageCostService; a successful local report means only that the configured OpenTelemetry SDK accepted the log record.
Producer example
from datetime import UTC, datetime
from decimal import Decimal
from juntai.usage import (
UsageContext,
UsageEvent,
UsageReporter,
stable_usage_event_id,
)
source_id = "axiom-execution:exec-42:attempt-1:completed"
event = UsageEvent(
event_id=stable_usage_event_id(
producer_id="axiom.driver",
source_id=source_id,
meter="axiom.execution.cpu_time",
part="total",
),
context=UsageContext(
tenant_id="tenant-7",
service_namespace="juntai.axiom",
service_name="driver",
application_id="app-9",
workflow_id="workflow-3",
execution_id="exec-42",
),
meter="axiom.execution.cpu_time",
quantity=Decimal("18.250"),
unit="s",
occurred_at=datetime.now(UTC),
source_id=source_id,
)
result = UsageReporter.from_otel().report(event)
if not result.enqueued:
service_health.record_usage_reporting_failure(result.error_code)
Configure the process OpenTelemetry LoggerProvider with matching
service.namespace and service.name resource attributes and export OTLP over
HTTP/protobuf only to the local Collector sidecar. Re-reporting the same event is
safe because its identifier and encoded payload remain stable. Do not use a
timestamp or random value as source_id.
Validation and meter definitions
UsageEvent accepts only Decimal quantities and normalizes them to a finite,
non-negative canonical string without exponent notation. Timestamps are
timezone-aware and normalized to UTC. UsageMeter can validate a locally known
published definition's accepted units and required application, workflow, or
execution attribution before emission. The service meter catalog remains the
authority.
The canonical JSON contract is
contracts/usage-event.v1.schema.json.
Deterministic valid and invalid fixtures are under fixtures.
Migration from the legacy Observability metric-window convention is documented
in docs/migration-from-observability.md.
Local gates
uv sync --dev
uv run ruff format --check .
uv run ruff check .
uv run pytest
uv run python -m build
The integration suite uses the real OpenTelemetry SDK and in-memory exporter to verify emitted log records and resource attribution. It deliberately does not claim central Collector or ledger durability.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file juntai_usage-1.0.0.tar.gz.
File metadata
- Download URL: juntai_usage-1.0.0.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb0bd52d46816853ef32e2aa28a93a326381bf3b41eb8338bba9aa290994e32f
|
|
| MD5 |
5102083f9a736a93336b106b8464c9a3
|
|
| BLAKE2b-256 |
86b22416d4d2903335cb48f7f393d693163d041b674a004f39af833ec648e065
|
Provenance
The following attestation bundles were made for juntai_usage-1.0.0.tar.gz:
Publisher:
publish-python.yml on zephytiju/JuntaiUsage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
juntai_usage-1.0.0.tar.gz -
Subject digest:
fb0bd52d46816853ef32e2aa28a93a326381bf3b41eb8338bba9aa290994e32f - Sigstore transparency entry: 2457813938
- Sigstore integration time:
-
Permalink:
zephytiju/JuntaiUsage@95a8df981207ac8b129f804bbeef5c9d87ef7753 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/zephytiju
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@95a8df981207ac8b129f804bbeef5c9d87ef7753 -
Trigger Event:
release
-
Statement type:
File details
Details for the file juntai_usage-1.0.0-py3-none-any.whl.
File metadata
- Download URL: juntai_usage-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0fd30957ab3a524a5bbf879f8c2a2e49753f8573d07d16e982861adc86df9f6
|
|
| MD5 |
6d487020e0e84f7fe74ec169f15f8670
|
|
| BLAKE2b-256 |
ec39cbc9c8ac7f193829681aab01fab69ab9beebeff1e21c4ca0edce25134794
|
Provenance
The following attestation bundles were made for juntai_usage-1.0.0-py3-none-any.whl:
Publisher:
publish-python.yml on zephytiju/JuntaiUsage
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
juntai_usage-1.0.0-py3-none-any.whl -
Subject digest:
c0fd30957ab3a524a5bbf879f8c2a2e49753f8573d07d16e982861adc86df9f6 - Sigstore transparency entry: 2457814041
- Sigstore integration time:
-
Permalink:
zephytiju/JuntaiUsage@95a8df981207ac8b129f804bbeef5c9d87ef7753 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/zephytiju
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@95a8df981207ac8b129f804bbeef5c9d87ef7753 -
Trigger Event:
release
-
Statement type: