Sigmoda Python SDK for logging LLM events and OpenAI chat completions.
Project description
Sigmoda Python SDK
Sigmoda is an LLM observability and guardrails platform. This SDK gives you:
- A thin wrapper around OpenAI chat completions that measures latency, captures prompt/response/token usage, logs to Sigmoda, and returns the original OpenAI response.
- A
log_eventhelper to send custom LLM events (for other providers or bespoke flows).
Install
pip install sigmoda
Configure
Set keys via environment variables (recommended):
export SIGMODA_PROJECT_KEY="YOUR_SIGMODA_PROJECT_KEY"
export OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
# Optional (only if your Sigmoda setup requires it)
export SIGMODA_PROJECT_ID="YOUR_SIGMODA_PROJECT_ID"
# Optional
export SIGMODA_ENV="prod" # prod|stage|dev
export SIGMODA_API_URL="https://api.sigmoda.com"
export SIGMODA_DISABLED="0" # set to 1 to disable logging
export SIGMODA_DEBUG="0" # set to 1 for debug logs
export SIGMODA_SAMPLE_RATE="1.0" # 0.0 - 1.0
export SIGMODA_MAX_PAYLOAD_BYTES="100000"
import sigmoda
sigmoda.init(
# Reads env vars by default:
# - SIGMODA_PROJECT_KEY (required unless SIGMODA_DISABLED=1)
# - SIGMODA_PROJECT_ID (optional)
# - SIGMODA_ENV / SIGMODA_API_URL / SIGMODA_DISABLED / SIGMODA_DEBUG (optional)
# Privacy controls (optional)
# capture_content=False, # don't send prompt/response text
# redact=lambda s: "[REDACTED]", # redact prompt/response + string metadata values
)
Wrap OpenAI chat completions
resp = sigmoda.openai.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Draft a friendly greeting."}],
sigmoda_metadata={"route": "welcome-flow", "user_id": "123"},
)
# Use the OpenAI response as usual
print(resp.choices[0].message.content)
What happens:
- SDK times the call, reads token usage if present, and sends a best-effort log to Sigmoda (prompt/response text only if
capture_content=True). - Logging is fire-and-forget on a single background worker with a bounded queue; when full, events are dropped (never break your app).
- Network sends use short timeouts + small retries for transient errors.
- Tool call names (if any) are captured in
metadata["_sigmoda"]["tool_call_names"].
You can inspect drop/retry counters and flush on shutdown:
print(sigmoda.get_stats())
sigmoda.flush(timeout=2.0)
Streaming
Streaming is supported: if you pass stream=True, the SDK returns the OpenAI stream and logs an event once the stream is fully consumed.
Notes
- Metadata is sanitized (JSON-safe) and bounded by defaults (
max_metadata_items=50,max_metadata_bytes=8192). - Set
SIGMODA_DISABLED=1(ordisabled=True) to fully no-op logging. - In
SIGMODA_ENV=prod,capture_contentdefaults toFalse(no prompt/response text captured). Setcapture_content=Trueonly if you’re sure it’s safe. - Defaults:
timeout=2s,max_retries=2,max_queue_size=1000,sample_rate=1.0,max_payload_bytes=100000,max_prompt_chars=8000,max_response_chars=8000. - Use
sigmoda_metadata={...}for Sigmoda metadata; OpenAI’s ownmetadata=...parameter (if you pass it) is forwarded to OpenAI.
Troubleshooting
export SIGMODA_DEBUG=1
import sigmoda
print(sigmoda.get_stats()) # queue_size, dropped_queue_full, failed, retries, sent
Common issues:
SIGMODA_DISABLED=1set (no logs by design).- Wrong
SIGMODA_API_URL(checkfailed/retriescounters). - Missing
SIGMODA_PROJECT_KEY(init will raise unless disabled).
Log a custom event
sigmoda.log_event(
provider="my-llm",
model="alpha-1",
type="chat_completion",
prompt="Translate 'hello' to French.",
response="Bonjour",
tokens_in=4,
tokens_out=2,
duration_ms=85,
status="ok",
metadata={"route": "translator"},
)
Development
- Python 3.8+.
- Runtime deps:
requests,openai>=1,<2. - Tests:
pytest. Run locally with:
python3 -m venv .venv
. .venv/bin/activate
pip install -e ".[test]"
pytest
See MVP_CHECKLIST.md and DEV_NOTES.md for progress tracking.
Project details
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 sigmoda-0.1.2.tar.gz.
File metadata
- Download URL: sigmoda-0.1.2.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87a783f2fd8aa8e827b998dd75ea3d46acf82e0472def8bd8c7c1aaa0f7126ea
|
|
| MD5 |
29b25de669e4eabf4e8c7e520951328a
|
|
| BLAKE2b-256 |
a773ab48e086216d136225cb143c7192560733bd1dc5c4deaba860851894ab1b
|
Provenance
The following attestation bundles were made for sigmoda-0.1.2.tar.gz:
Publisher:
publish.yml on seljawhari/sigmoda-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sigmoda-0.1.2.tar.gz -
Subject digest:
87a783f2fd8aa8e827b998dd75ea3d46acf82e0472def8bd8c7c1aaa0f7126ea - Sigstore transparency entry: 763090301
- Sigstore integration time:
-
Permalink:
seljawhari/sigmoda-python@0352b072cf41358b86c98dbf7381f18398ef2be3 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/seljawhari
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0352b072cf41358b86c98dbf7381f18398ef2be3 -
Trigger Event:
push
-
Statement type:
File details
Details for the file sigmoda-0.1.2-py3-none-any.whl.
File metadata
- Download URL: sigmoda-0.1.2-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86f46a89b15927f597053044995b9a7d8ebf2f72b4ecf146621ef925381182fb
|
|
| MD5 |
75219f36b14d8d3dd0cf5b43bb695b66
|
|
| BLAKE2b-256 |
df11342291066738cedf4fcca98889f2d7d3fa353a9796be845f33fdee1b6265
|
Provenance
The following attestation bundles were made for sigmoda-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on seljawhari/sigmoda-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sigmoda-0.1.2-py3-none-any.whl -
Subject digest:
86f46a89b15927f597053044995b9a7d8ebf2f72b4ecf146621ef925381182fb - Sigstore transparency entry: 763090304
- Sigstore integration time:
-
Permalink:
seljawhari/sigmoda-python@0352b072cf41358b86c98dbf7381f18398ef2be3 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/seljawhari
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0352b072cf41358b86c98dbf7381f18398ef2be3 -
Trigger Event:
push
-
Statement type: