Skip to main content

open-spanner

Python client for the Open Spanner API.

Install from PyPI:

pip install open-spanner

Record usage for a meter that already exists:

from datetime import UTC, datetime
from uuid import uuid4

from open_spanner_client import AuthenticatedClient
from open_spanner_client.api.usages import create_usage
from open_spanner_client.models.usage_create_request import UsageCreateRequest
from open_spanner_client.retry import retry_usage_write

api_key = "..."

client = AuthenticatedClient(
    base_url="https://api.example.com",
    token=api_key,
    raise_on_unexpected_status=True,
)

request = UsageCreateRequest(
    idempotency_key=str(uuid4()),
    subject="org_123",
    meter="api_requests",
    quantity=1,
    timestamp=datetime.now(UTC).isoformat(),
)
response = retry_usage_write(lambda: create_usage.sync_detailed(client=client, body=request))
usage = response.parsed

print(usage.id)

retry_usage_write and retry_usage_write_async retry transport failures, 429, and temporary 5xx responses, and honor Retry-After.

Stream usage over gRPC:

from datetime import UTC, datetime

from open_spanner_client.stream import Event, RetryPolicy, StreamClient

client = StreamClient(
    "localhost:18090",
    "osp_...",
    retry_policy=RetryPolicy(
        max_attempts=3,
        on_retry=lambda event: print("retry", event.attempt, event.delay_seconds),
    ),
)
try:
    result = client.track_bulk(
        "batch-1",
        [
            Event(
                idempotency_key="usage-1",
                subject="org_123",
                meter="api_requests",
                quantity=1,
                timestamp=datetime.now(UTC),
                metadata={"endpoint": "/v1/orders", "status": 200},
            )
        ],
    )
finally:
    client.close()

print(result.accepted_count)

Retries are opt-in and apply to unary track and track_bulk calls. They honor google.rpc.RetryInfo and retry only overload, temporary unavailability, and deadline failures. Client streams are not replayed automatically; retry an uncertain stream through track_bulk with the original event idempotency keys.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

open_spanner-0.1.13.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

open_spanner-0.1.13-py3-none-any.whl (80.9 kB view details)

Uploaded Python 3

File details

Details for the file open_spanner-0.1.13.tar.gz.

File metadata

  • Download URL: open_spanner-0.1.13.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for open_spanner-0.1.13.tar.gz
Algorithm Hash digest
SHA256 755bfdf72f13c7765e18851d2254eaae9584ffbab9a209f788251b63fd9a01c3
MD5 440486da9605d6407733d2c9dfe097a0
BLAKE2b-256 6335e8689f73d23f77c234852206638637381b8a068dac72b0038c0467a60186

See more details on using hashes here.

Provenance

The following attestation bundles were made for open_spanner-0.1.13.tar.gz:

Publisher: publish-python-sdk.yml on ssubedir/open-spanner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file open_spanner-0.1.13-py3-none-any.whl.

File metadata

  • Download URL: open_spanner-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 80.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for open_spanner-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 9bd5055e515cf88563dc14fe23ff8d9f28666478b07f4f763729cc4d3d80c062
MD5 40bf8446f5c7c80541b19236a5cbfb45
BLAKE2b-256 fbdabe80e96a33feb3638f8c87d34979f8666ba8742058e8492ceec9494b0f5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for open_spanner-0.1.13-py3-none-any.whl:

Publisher: publish-python-sdk.yml on ssubedir/open-spanner

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.13 This release

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 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