DSPy observability and deployment SDK for cmpnd
Project description
cmpnd
DSPy observability and deployment SDK for cmpnd.
Automatically trace your DSPy programs with one line of code, and deploy them with one more.
Installation
pip install cmpnd
Quick Start
import cmpnd
# Configure with your API key
cmpnd.configure(api_key="ct_xxx", project="my-project")
# Enable automatic DSPy instrumentation
cmpnd.auto_instrument()
# Your DSPy code is now automatically traced!
import dspy
lm = dspy.LM("openai/gpt-4o-mini")
dspy.configure(lm=lm)
cot = dspy.ChainOfThought("question -> answer")
result = cot(question="What is DSPy?")
# Trace is automatically sent to cmpnd
Configuration
Using environment variables
export CMPND_API_KEY="ct_your_api_key"
export CMPND_ENDPOINT="https://platform.cmpnd.ai" # optional
import cmpnd
cmpnd.configure() # Reads from environment
cmpnd.auto_instrument()
Configuration options
cmpnd.configure(
api_key="ct_xxx", # Required: API key
endpoint="https://platform.cmpnd.ai", # Optional: Backend URL
project="my-project", # Optional: Project name
batch_size=100, # Optional: Batch size for export
flush_interval_seconds=5.0, # Optional: Flush interval
capture_inputs=True, # Optional: Capture function inputs
capture_outputs=True, # Optional: Capture function outputs
default_tags={"env": "prod"}, # Optional: Tags for all traces
)
Deployment
Deploy a DSPy module to the cmpnd platform for server-side execution:
import cmpnd
import dspy
cmpnd.configure(api_key="ct_xxx")
lm = dspy.LM("groq/llama-3.1-8b-instant", temperature=0.0, max_tokens=16384)
dspy.configure(lm=lm)
module = dspy.Predict("question -> answer")
deployment_id = cmpnd.deploy(module)
The SDK packages the module's source code into a ZIP, uploads it to the platform, and polls until the server-side parser finishes. Returns a deployment_id for future use with cmpnd.execute() (coming soon).
With a metric (for optimization)
def accuracy(example, pred, trace=None):
return example.answer == pred.answer
deployment_id = cmpnd.deploy(module, metric=accuracy)
Options
cmpnd.deploy(
module, # Required: a DSPy module
metric=None, # Optional: metric callable for optimization support
timeout=300, # Optional: seconds to wait for parsing (default 300)
)
How it works
- The SDK generates source code from the live module (LM config, signature, types)
POST /api/v1/deploymentscreates a deployment and returns a presigned S3 upload URL- The source ZIP is uploaded directly to S3
- The server-side parser extracts the program and LM configuration
- The SDK polls until status is
ready, then returns thedeployment_id
The deployed program's LM model string (e.g. groq/llama-3.1-8b-instant) and configuration (temperature, max_tokens) are extracted automatically from the source.
Custom Spans
Add custom spans to trace non-DSPy code:
Using the decorator
from cmpnd import trace, SpanType
@trace(name="fetch_documents", span_type=SpanType.RETRIEVE)
def fetch_documents(query: str) -> list[str]:
# Your retrieval logic
return documents
Using the context manager
from cmpnd import start_span, SpanType
def run_pipeline(query: str):
with start_span("vector_search", span_type=SpanType.RETRIEVE) as span:
span.set_attribute("index", "my-faiss-index")
docs = search(query)
span.set_outputs({"doc_count": len(docs)})
return generate(query, docs)
What Gets Traced
The SDK automatically captures:
Module Execution
- Module type (Predict, ChainOfThought, ReAct, etc.)
- Signature name and instructions
- Input/output field names
- Demo count
LM Calls
- Model name and provider
- Token usage (prompt, completion, total)
- Request/response content
Adapters
- Format and parse operations
- Input/output transformations
Tools
- Tool name and description
- Invocation inputs/outputs
Evaluations
- Evaluation scores
- Program being evaluated
Span Types
Available span types for categorization:
SpanType.MODULE- Generic DSPy moduleSpanType.PREDICT- Predict moduleSpanType.CHAIN_OF_THOUGHT- ChainOfThought moduleSpanType.REACT- ReAct agentSpanType.RETRIEVE- Retrieval operationsSpanType.LM_CALL- Language model callsSpanType.ADAPTER_FORMAT- Adapter formattingSpanType.ADAPTER_PARSE- Adapter parsingSpanType.TOOL- Tool invocationsSpanType.EVALUATION- Evaluation runs
API Reference
cmpnd.configure()
Initialize the SDK with your API key and options.
cmpnd.auto_instrument()
Automatically register the callback with DSPy.
cmpnd.CmpndCallback
The callback class for manual registration:
import dspy
import cmpnd
cmpnd.configure(api_key="ct_xxx")
dspy.configure(callbacks=[cmpnd.CmpndCallback()])
cmpnd.deploy()
Deploy a DSPy module to the cmpnd platform. Returns the deployment_id.
cmpnd.trace()
Decorator for custom traced functions.
cmpnd.start_span()
Context manager for custom spans.
cmpnd.get_current_trace()
Get the current trace (if any).
cmpnd.get_current_span()
Get the current span (if any).
cmpnd.shutdown_exporter()
Gracefully shutdown the background exporter.
License
MIT
Project details
Release history Release notifications | RSS feed
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 cmpnd-0.2.0.tar.gz.
File metadata
- Download URL: cmpnd-0.2.0.tar.gz
- Upload date:
- Size: 423.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
186ccd36df9e1e65c086fb89adeb1edbb55cce0152212bf67ee424cbbd84e637
|
|
| MD5 |
87b35e008390d6a7720bec7275b3496a
|
|
| BLAKE2b-256 |
6e472c37b3dd747d55871317f21c8e6ba39b2d736be74cd1d01a74b17642eb9c
|
Provenance
The following attestation bundles were made for cmpnd-0.2.0.tar.gz:
Publisher:
release-sdk.yml on cmpnd-ai/cmpnd-platform
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cmpnd-0.2.0.tar.gz -
Subject digest:
186ccd36df9e1e65c086fb89adeb1edbb55cce0152212bf67ee424cbbd84e637 - Sigstore transparency entry: 1462228023
- Sigstore integration time:
-
Permalink:
cmpnd-ai/cmpnd-platform@61094b2af1d3afb1f8f3b71835cb50308d0b5605 -
Branch / Tag:
refs/tags/sdk-v0.2.0 - Owner: https://github.com/cmpnd-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-sdk.yml@61094b2af1d3afb1f8f3b71835cb50308d0b5605 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cmpnd-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cmpnd-0.2.0-py3-none-any.whl
- Upload date:
- Size: 90.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8df699074849255ffb63353370ab61ff03f785aa8985ddfef4dca575cdece68d
|
|
| MD5 |
81addf9772d3a7323a4af3031035a222
|
|
| BLAKE2b-256 |
23961a7635466561cbe77e1f57227b2c0c9632335e0e9c8d864bd04b0968cb3a
|
Provenance
The following attestation bundles were made for cmpnd-0.2.0-py3-none-any.whl:
Publisher:
release-sdk.yml on cmpnd-ai/cmpnd-platform
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cmpnd-0.2.0-py3-none-any.whl -
Subject digest:
8df699074849255ffb63353370ab61ff03f785aa8985ddfef4dca575cdece68d - Sigstore transparency entry: 1462228035
- Sigstore integration time:
-
Permalink:
cmpnd-ai/cmpnd-platform@61094b2af1d3afb1f8f3b71835cb50308d0b5605 -
Branch / Tag:
refs/tags/sdk-v0.2.0 - Owner: https://github.com/cmpnd-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-sdk.yml@61094b2af1d3afb1f8f3b71835cb50308d0b5605 -
Trigger Event:
push
-
Statement type: