Skip to main content

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]

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:

python -m visceral install

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 (Anthropic cache_control markers, OpenAI prompt_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 to wrap(). Capture an agent framework's structure (LangChain / LangGraph, LlamaIndex, CrewAI) without wrapping a client. Framework capture wins over provider capture, so don't also wrap() 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 with apply=True, served from a stored result instead of re-executed. Serving needs readonly=True and replay_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

pip install -e ".[dev]"
ruff check src/ tests/
pytest

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

visceral_ai-0.2.1.tar.gz (106.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

visceral_ai-0.2.1-py3-none-any.whl (72.7 kB view details)

Uploaded Python 3

File details

Details for the file visceral_ai-0.2.1.tar.gz.

File metadata

  • Download URL: visceral_ai-0.2.1.tar.gz
  • Upload date:
  • Size: 106.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for visceral_ai-0.2.1.tar.gz
Algorithm Hash digest
SHA256 42064d1083c6b8508a2dc0b6c216a5f44f0a270ca01f9371269b03a85db02cd4
MD5 a4b8dba551cf3d67e46e16cd05cac6b2
BLAKE2b-256 e314dad47edfe195919642e9b7385e58298f1cdd784ca3615d07b615e41db7eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for visceral_ai-0.2.1.tar.gz:

Publisher: publish.yml on visceral-ai/visceral-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file visceral_ai-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: visceral_ai-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 72.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for visceral_ai-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a335611e76d13c7746a1cbfc991f73246d12ad7440294e0eb9d84163ea15598b
MD5 bbd1aa86ff5a29027cb18a1b3b989b1f
BLAKE2b-256 33a31b6d312142d5ce5566c7e206f1d721c313acfd15924cdf7f5053c4914f8c

See more details on using hashes here.

Provenance

The following attestation bundles were made for visceral_ai-0.2.1-py3-none-any.whl:

Publisher: publish.yml on visceral-ai/visceral-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page