Visceral Python SDK
visceral — runtime optimization layer for AI agents. Wrap your LLM client and
Visceral observes traffic, finds wasted work, and proves a cheaper call is safe
before making it. Fails open: if Visceral is unreachable, your agent runs exactly
as before.
Install
pip install "visceral-ai[openai]" # or [anthropic], [google], [all-providers]
uv add "visceral-ai[openai]" # same extras, uv-managed projects
On a framework, add its extra so instrument() can capture it:
pip install "visceral-ai[langchain]" # or [llama-index], [crewai]
Distribution name is visceral-ai; the import package is visceral.
Requires Python 3.10+.
Agent-assisted setup
The package ships a /visceral skill for AI coding assistants (Claude Code
today). Register it once:
visceral install
(python -m visceral install does the same; and if you only want the
registrar without adding the SDK to a project yet, uv tool install visceral-ai or pipx install visceral-ai gives you the visceral command
globally.)
Then open your assistant in the repo you want instrumented and run
/visceral . — it detects your stack (provider clients vs. frameworks) and
wires wrap() / instrument() / @node / @tool in the right spots,
observe-only, then reports what it did. --project installs the skill into
the current repo instead of your user profile; --stdout prints it for
other assistants.
Usage
from openai import OpenAI
from visceral import wrap
client = wrap(OpenAI(), agent_id="my-agent") # same client back, now instrumented
Annotate the steps of your agent so they show up as named spans:
from visceral import node
@node("retrieve")
def retrieve(query: str) -> list[str]:
...
Beyond observation
Observation is the default; three opt-in paths build on it, each fully fail-open. Full detail in the SDK guide.
-
wrap(..., apply=True)— apply the optimizations the backend has already proven safe for your traffic: output-neutral cache-layout rewrites (Anthropiccache_controlmarkers, OpenAIprompt_cache_key) and tool-call reuse. Never changes what the model reads or returns.client = wrap(Anthropic(), agent_id="support-bot", apply=True)
-
instrument(framework, agent_id)— the client-less counterpart towrap(). Capture an agent framework's structure (LangChain / LangGraph, LlamaIndex, CrewAI) without wrapping a client. Framework capture wins over provider capture, so don't alsowrap()the same traffic.from visceral import instrument instrument("langgraph", agent_id="research-agent")
-
@tool(...)— annotate a tool function so read-only calls can be deduplicated and, once proven and withapply=True, served from a stored result instead of re-executed. Serving needsreadonly=Trueandreplay_safe=True; a failure always runs the real tool.from visceral import tool @tool("get_customer", readonly=True, replay_safe=True) def get_customer(customer_id: str) -> dict: return db.fetch_customer(customer_id)
Authentication
You hold exactly one secret: the workspace API key (vsc_...), from your
workspace's Settings page in the dashboard (or from Visceral during
onboarding). Set it as VISCERAL_API_KEY, or pass api_key= to wrap();
set VISCERAL_BASE_URL only if self-hosting. The key both authenticates the
SDK and selects the workspace your traffic lands in — there is no separate
user or org credential. One process serves one workspace: wrap every client
in a process with the same key.
Prompt and response text never leaves your process unencrypted: content is stripped or AES-256-GCM-encrypted before export with a per-workspace encryption key the SDK fetches automatically — you never handle it — and spans that cannot be redacted are dropped, never sent.
Develop
uv sync --extra all-providers --extra dev # or: pip install -e ".[dev]"
uv run ruff check src/ tests/
uv run pytest
uv.lock is committed; CI installs with uv sync --locked, so lockfile
drift fails the build — run uv lock after changing dependencies.
License
Apache-2.0 — see LICENSE.
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 visceral_ai-0.2.2.tar.gz.
File metadata
- Download URL: visceral_ai-0.2.2.tar.gz
- Upload date:
- Size: 107.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce6fbaa09861316758a25f49ad6a39c17dbb20939946a7335c928654b7a4100a
|
|
| MD5 |
beeb7be178b434e766333d0c8a1608ef
|
|
| BLAKE2b-256 |
45bb4c594a8556385c8868dced4b537e96f1831f6668637746e86c0a01d7bb6c
|
Provenance
The following attestation bundles were made for visceral_ai-0.2.2.tar.gz:
Publisher:
publish.yml on visceral-ai/visceral-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
visceral_ai-0.2.2.tar.gz -
Subject digest:
ce6fbaa09861316758a25f49ad6a39c17dbb20939946a7335c928654b7a4100a - Sigstore transparency entry: 2457348057
- Sigstore integration time:
-
Permalink:
visceral-ai/visceral-py@ea11c6090fc2e281c485cd195d7bc2d07ed0f3f8 -
Branch / Tag:
refs/tags/sdk-v0.2.2 - Owner: https://github.com/visceral-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ea11c6090fc2e281c485cd195d7bc2d07ed0f3f8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file visceral_ai-0.2.2-py3-none-any.whl.
File metadata
- Download URL: visceral_ai-0.2.2-py3-none-any.whl
- Upload date:
- Size: 73.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2f54e3402b9c77451a98ad46ab06654675be6424ce396e6e0c79206fddb9b58
|
|
| MD5 |
fea73dd8965f2fba221033d85e5458dd
|
|
| BLAKE2b-256 |
395241289ef83878d1497649c28ad452491107088bbdf71667c265a27dd543f6
|
Provenance
The following attestation bundles were made for visceral_ai-0.2.2-py3-none-any.whl:
Publisher:
publish.yml on visceral-ai/visceral-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
visceral_ai-0.2.2-py3-none-any.whl -
Subject digest:
a2f54e3402b9c77451a98ad46ab06654675be6424ce396e6e0c79206fddb9b58 - Sigstore transparency entry: 2457348114
- Sigstore integration time:
-
Permalink:
visceral-ai/visceral-py@ea11c6090fc2e281c485cd195d7bc2d07ed0f3f8 -
Branch / Tag:
refs/tags/sdk-v0.2.2 - Owner: https://github.com/visceral-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ea11c6090fc2e281c485cd195d7bc2d07ed0f3f8 -
Trigger Event:
push
-
Statement type: