Skip to main content

coding-sh (Python SDK)

PyPI version MIT license CI status

coding.sh · Docs · Production guide · Source

Send LLM calls, traces and tool spans from any Python service to a coding.sh server (coding.sh serve). Stdlib only, Python 3.9+.

pip install coding-sh
export CODING_SH_URL=https://obs.example.com CODING_SH_INGEST_KEY=csh_ik_...
import coding_sh
from openai import OpenAI

client = coding_sh.observe(OpenAI())   # also AsyncOpenAI, Anthropic, AsyncAnthropic

That's it: every chat.completions.create, responses.create and messages.create / messages.stream call (sync, async and streaming) becomes an llm.call with tokens, model, latency, time to first token, stop reason and tool calls. The server prices it.

Without CODING_SH_URL the SDK does nothing. It never changes return values, errors or stream semantics, and never raises into your app. The one exception is coding_sh.weights_delta(), a pure helper you call on purpose: it raises ValueError on bad input.

Traces, tools and conversations

with coding_sh.trace("support-reply", session_id=conversation_id, user_id=user.id, input=question) as t:
    with coding_sh.span("tool", "lookup_order", input={"id": 42}) as s:
        s.set_output(orders.get(42))
    reply = client.chat.completions.create(model="gpt-4o-mini", messages=msgs)
    t.set_output(reply.choices[0].message.content)
  • Each top-level trace() (or untraced call) is its own session. Pass session_id (or wrap code in coding_sh.with_session(id)) to make each trace a turn of one conversation.
  • trace and span are context managers (with / async with) and decorators. A decorated span("tool", ...) records the call's arguments as input and its return value as output.
  • span("step", name) records a generic step.
  • Context follows contextvars, so it crosses await and asyncio tasks. Work handed to a thread pool starts untraced unless you run it in a copy of the context, one per task: pool.submit(contextvars.copy_context().run, fn, *args).

LLM gateways

Point the client at a gateway and each call records which one it went through, and the request id the gateway's lookup API takes, so coding.sh gateway enrich can add the billed cost and coding.sh sessions --flag gateway:<name> finds the sessions. Detected: Vercel AI Gateway, OpenRouter, LiteLLM, Cloudflare AI Gateway, Portkey, Helicone, Requesty, Ramp Router (router.com), TrueFoundry, Kong, Bifrost and Martian, by base URL (a self-hosted gateway by its URL env var, e.g. LITELLM_PROXY_API_BASE), by response header (cf-aig-log-id, helicone-id, x-litellm-call-id, x-portkey-trace-id, …) or by response id (gen_…, gen-…, rqsty-…). observe() adds a response hook to the client's HTTP client that reads headers only, and only for calls it records. Details.

client = coding_sh.observe(OpenAI(base_url="https://gateway.ai.cloudflare.com/v1/<account>/<gateway>/compat"))

Delivery

One daemon thread sends batches (up to 500 events or 4 MiB, gzip) to POST /v1/ingest. It retries 429, 5xx and network errors, at most 5 attempts, with stable event ids, so retries never duplicate. Before a retry it waits as long as Retry-After says (seconds or a date, at most 60 s), otherwise 1, 2, 4 ... s up to 30 s.

400/401/403 drop the batch with one warning. A full queue drops new events and counts them. An atexit flush is bounded to 2 s. When it or shutdown() runs out of time, it warns once, with the number of events not sent, and drops them.

coding_sh.flush(timeout=5)     # e.g. at the end of a script, a job or a serverless handler
coding_sh.shutdown()           # flush, then stop
coding_sh.stats()              # {"queued", "sent", "dropped", "failed"}

Config

coding_sh.init(url=, key=, service=, capture=, flush_interval_ms=1000, max_batch=500, max_queue=10000, disabled=, debug=) is optional; arguments override env vars.

Env Meaning
CODING_SH_URL Server base URL. A URL that ends in /v1/ingest or /v1/traces works too. Unset = SDK off.
CODING_SH_INGEST_KEY csh_ik_... ingest key. It decides the project.
CODING_SH_SERVICE (or OTEL_SERVICE_NAME) Service name; becomes the session's agent id.
CODING_SH_CAPTURE_MODE full (default) or metadata (no message text or tool I/O).
CODING_SH_DISABLED=1 Turn the SDK off.
CODING_SH_DEBUG=1 Log transport details (never keys or bodies).

OpenTelemetry

Already emitting gen_ai spans? Point OTel at the server instead (no SDK needed), or let the helper do the setup:

from coding_sh.otel import configure, otel_env
configure(service="checkout-api")   # TracerProvider + OTLP/HTTP exporter + Bearer key
env = otel_env()                    # OTEL_EXPORTER_OTLP_* vars for a subprocess

pip install 'coding-sh[otel]'. configure() uses the standard OTEL_EXPORTER_OTLP_* env vars when set, else CODING_SH_URL / CODING_SH_INGEST_KEY, and stamps gen_ai.conversation.id from the current with_session / trace(session_id=...). Inside trace(), a span that would start a trace of its own gets the open trace() or span() as parent instead, so each model call is a step of the trace's one turn, not a turn of its own.

Tests

python3 -m unittest discover -s tests -t tests

The provider tests use fake clients and always run. Tests against the real openai, anthropic and OpenTelemetry packages, and the mypy typing check, run when those are installed (pip install '.[otel,openai,anthropic]' mypy). With CODING_SH_SDK_REQUIRE_ALL=1, as in CI and npm run gate, they fail instead of skipping when a package is missing.

Metadata

Release files for coding-sh 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coding-sh 0.1.5
File Size Uploaded Provenance Actions
coding_sh-0.1.5.tar.gz 36.6 kB With provenance Details for coding_sh-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for coding-sh 0.1.5
File Interpreter ABI Platform Actions
coding_sh-0.1.5-py3-none-any.whl Python 3 none any Details for coding_sh-0.1.5-py3-none-any.whl

Total release size: 74.1 kB

Release files / coding_sh-0.1.5.tar.gz

Download URL coding_sh-0.1.5.tar.gz
Size 36.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8bd4233982d6774f0facc2de66aab7aed4ac46ad59c53e87f31a4228d9866571
BLAKE2b-256 checksum
How to use checksums
df48f83942af9c39aed43290b55b3ce0c3a9b7ca4bdf461971462a63d6638a2c
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 Nov 28, 2026.

Transparency log

Release files / coding_sh-0.1.5-py3-none-any.whl

Download URL coding_sh-0.1.5-py3-none-any.whl
Size 37.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da457d6587cac61d0ee22f4df8121da42f3f7f4aa2ba2666295630d8489f6fd7
BLAKE2b-256 checksum
How to use checksums
8dc0d2be49532c50e23e6a5a52ae3fed477c85d0a11b8e5c28353998008c578a
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 Nov 28, 2026.

Transparency log

Security for coding-sh 0.1.5

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for coding_sh-0.1.5.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 Nov 28, 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.

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