compass-wallet-usage
Centralized wallet usage module (Python) for multi-agent Compass systems.
What this module provides
- Per-user, per-IST-day usage recording (
total_tokens, request count, optionalagent_idsplit) - Daily quota enforcement from env (
WALLET_DAILY_TOKEN_LIMIT) - Pluggable storage backends:
InMemoryWalletStorage(dev/tests)FirestoreWalletStorage(prod)
- ADK callback factory (
record_tokens_after_model) for Geminiusage_metadata - Built-in ADK user-id resolver (
resolve_user_id) for common callback context shapes - Optional FastAPI router exposing wallet status + record routes
Install (local repo)
pip install -e .
Quick start
from wallet import WalletService
from storage import InMemoryWalletStorage
wallet = WalletService(InMemoryWalletStorage())
wallet.record("user-123", 210, agent_id="mktg_banner_agent")
print(wallet.status("user-123"))
Quota
Set in host service env:
WALLET_DAILY_TOKEN_LIMIT=9000
Then call before model request:
wallet.enforce_daily_quota_if_configured(user_id)
ADK callback usage
from adk_callbacks import record_tokens_after_model
after_model_callback = record_tokens_after_model(
wallet=wallet,
agent_id="mktg_banner_agent",
)
record_tokens_after_model defaults to resolve_user_id, which checks:
callback_context.state["user_id" | "uid" | "firebase_uid" | "user_email"]- then
callback_context.user_id/callback_context.uid - fallback:
"unknown-user"
Optional FastAPI routes
from fastapi import FastAPI
from api import build_wallet_router
app = FastAPI()
app.include_router(build_wallet_router(wallet))
Routes:
GET /wallet/status?user_id=...POST /wallet/record
Notes
- This module is intentionally standalone and not integrated into other repos yet.
- Firestore backend requires
google-cloud-firestoreand ADC/service credentials.
Metadata
Release files for compass-wallet-usage 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 | Provenance | Actions |
|---|---|---|---|---|
| compass_wallet_usage-0.1.0.tar.gz | 6.8 kB | Without provenance | Details for compass_wallet_usage-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| compass_wallet_usage-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for compass_wallet_usage-0.1.0-py3-none-any.whl |
Total release size: 16.4 kB
Release files / compass_wallet_usage-0.1.0.tar.gz
| Download URL | compass_wallet_usage-0.1.0.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6a8c0323e5f6eb9d30929e5f8c488250bd9d55eb0a88b364f3bf57e63c14ef0
|
|
BLAKE2b-256 checksum How to use checksums |
27b49c40a66192af1e3d9004fb3603ece97896efe6033722fba4d8a017b6ec5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Release files / compass_wallet_usage-0.1.0-py3-none-any.whl
| Download URL | compass_wallet_usage-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1d8e0ee04b52fb35593239948a159c6e6489afa65e23a90c85dceda14d5df69f
|
|
BLAKE2b-256 checksum How to use checksums |
0e0cf4c77b7e0b6f0ea11360d9502c6a789ebb1f018cdf49502e26a2d48cc212
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.11
|
Security for compass-wallet-usage 0.1.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.