Skip to main content

datagol-lens

Python SDK for DataGOL Lens: traces, token usage, cost and budgets for LLM applications. Wrap your Anthropic or OpenAI client, or attach a LangChain callback, and every call shows up in Lens as a trace with its spans.

pip install datagol-lens
pip install "datagol-lens[langchain]"   # for the LangChain / LangGraph handler

Configure

Variable Description
DATAGOL_LENS_API_URL Your Lens backend URL (default http://localhost:8000)
DATAGOL_LENS_API_KEY A project API key (dgl_...), created in Lens for the project you trace into

Both can also be passed to DatagolLensClient(api_url=..., api_key=...).

Trace one call per request

import anthropic
from datagol_lens import DatagolLensClient

sdk = DatagolLensClient()
client = sdk.wrap(anthropic.Anthropic(), project_id="<project-id>", name="support-bot")

resp = client.messages.create(
    model="claude-haiku-4-5-20251001",
    messages=[{"role": "user", "content": "What is Python?"}],
    max_tokens=200,
)

The same works for openai.OpenAI().

Trace a multi-step run

from datagol_lens import DatagolLensClient, TraceContext

sdk = DatagolLensClient()

with TraceContext(sdk, "<project-id>", name="research-agent",
                  session_id="sess-abc", user_id="user-123") as ctx:
    llm = ctx.wrap(anthropic.Anthropic())      # each call becomes a span
    resp = llm.messages.create(model="claude-haiku-4-5-20251001", max_tokens=300,
                               messages=[{"role": "user", "content": "Summarize recent AI news"}])
    ctx.add_span(name="vector_search", span_type="retriever",
                 input={"query": "AI news"}, output={"chunks": 2})
    ctx.set_output({"summary": resp.content[0].text})
# the trace is sent when the block exits

LangChain and LangGraph

from datagol_lens import DatagolLensClient, TraceContext
from datagol_lens.langchain import DatagolLensCallbackHandler

with TraceContext(DatagolLensClient(), "<project-id>", name="langchain-agent") as ctx:
    handler = DatagolLensCallbackHandler(ctx)
    answer = chain.invoke("What is Python?", config={"callbacks": [handler]})

Every chat-model call is recorded as an llm span with its token usage, and every tool call as a tool span. Attach the same handler to a LangGraph agent's config.

Budgets and attribution

Pass company_id, agent_key and user_id to TraceContext and Lens attributes the trace's cost to that company, agent and user. Before a run, check the budgets:

from datagol_lens import BudgetExceeded

result = sdk.check_budget("<project-id>", company_id="acme", user_id="u-1", agent_key="support-bot")
if not result["allowed"]:
    raise BudgetExceeded("over budget", result)

Lens prices each span from its model and token counts, so the SDK only reports usage.

License

MIT

Metadata

Release files for datagol-lens 0.2.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 datagol-lens 0.2.0
File Size Uploaded Provenance
datagol_lens-0.2.0.tar.gz 24.5 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for datagol-lens 0.2.0
File Interpreter ABI Platform
datagol_lens-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 50.4 kB

Release files / datagol_lens-0.2.0.tar.gz

Download URL datagol_lens-0.2.0.tar.gz
Size 24.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0f9e44b03941eb9d70117246c6641afa2fcfaa2c930b5ddb215c7786adbe2adc
BLAKE2b-256 checksum
How to use checksums
d72effcbf4af24d16e1c4f95abd25e026d7d0fd1f8d4ca7a02e1c144d46199af
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 26, 2026.

Transparency log

Release files / datagol_lens-0.2.0-py3-none-any.whl

Download URL datagol_lens-0.2.0-py3-none-any.whl
Size 25.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
110558d0d844fdd57cd7011b236c78f46e134cacff3f94e858954d0dedb6142b
BLAKE2b-256 checksum
How to use checksums
9d7189f3b08a3ebf377d2e83eb4e0bb42d41a6c095741fbfd1902c7f5565e1e8
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 26, 2026.

Transparency log

Security for datagol-lens 0.2.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 datagol_lens-0.2.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 26, 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.2.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