Skip to main content

spanrail

Python SDK for Spanrail, a self-hosted LLM observability platform. No dependencies; Python 3.9 or newer.

pip install spanrail

The import name is spanrail; the client class is Spanrail, because it talks to a Spanrail server.

Send a trace

from openai import OpenAI
from spanrail import Spanrail

tw = Spanrail("pk-...", "sk-...", base_url="http://localhost:3000")
client = OpenAI()

trace = tw.trace("support-chat", user_id="u_123", tags=["prod"])

messages = [{"role": "user", "content": "Where is my order?"}]
with trace.generation("answer", model="gpt-4o-mini", input=messages) as gen:
    reply = client.chat.completions.create(model="gpt-4o-mini", messages=messages)
    gen.end(
        output=reply.choices[0].message.content,
        usage={"input": reply.usage.prompt_tokens, "output": reply.usage.completion_tokens},
    )

trace.score("helpful", 1)

Create the key pair under a project's settings in the dashboard. Events are queued and sent from a background thread, and flushed when the program exits. Call tw.flush() first if you need them sent now, for example at the end of a serverless handler.

Behaviour worth knowing

  • It never raises into your app. If Spanrail is down, a batch is retried a few times and then dropped. tw.sent and tw.dropped count both. A full queue (max_queue, default 10,000) drops new events the same way.
  • Unknown is not zero. Fields you leave out are not sent. Usage and cost appear only if you pass them.
  • Errors are recorded for you. If code inside with trace.span(...) or with trace.generation(...) raises, the observation is ended with level ERROR and the exception as its status message, and the exception still propagates.
  • Spans and generations nest: span.generation(...), span.span(...). event(...) records a point in time.
  • tw.get_prompt("name", label="production") fetches a versioned prompt.

Options

Spanrail(public_key, secret_key, base_url="http://localhost:3000", flush_at=20, flush_interval=2.0, max_queue=10000, timeout=10.0, retries=3)

Licence

MIT.

Metadata

Release files for spanrail 0.1.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 spanrail 0.1.0
File Size Uploaded Provenance
spanrail-0.1.0.tar.gz 7.9 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for spanrail 0.1.0
File Interpreter ABI Platform
spanrail-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / spanrail-0.1.0.tar.gz

Download URL spanrail-0.1.0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0e43608dcb4628d556cf864b99d0fc29d035fc4ebbb62d3a93dffa7f1d205056
BLAKE2b-256 checksum
How to use checksums
d239676683a154d9774753355ddfc9787d0aeffc8373297f49659bdd3d53c3be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 27, 2026.

Transparency log

Release files / spanrail-0.1.0-py3-none-any.whl

Download URL spanrail-0.1.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
92b9914a7783c2123617fccc269b7bd81152bcf8c4e444258c4903d84ded124b
BLAKE2b-256 checksum
How to use checksums
2e3c462d8588166043f443e7eb4097144d2f980949c9c42964cb9f81a5c7aff6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 27, 2026.

Transparency log

Security for spanrail 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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spanrail-0.1.0.tar.gz

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 27, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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