Skip to main content

precipiq — Python SDK

Track AI agent decisions and measure their financial consequences.

precipiq records the decisions your AI agents make, chains each one into an append-only, tamper-evident ledger, and later links those decisions to the financial events they caused — so you can attribute revenue, cost, and liability back to the agent that drove them.

Installation

pip install precipiq

Optional framework adapters are opt-in extras (install only what your stack needs):

pip install "precipiq[langchain]"   # LangChain callback handler
pip install "precipiq[crewai]"      # CrewAI callback handler (Python < 3.14)

Requires Python 3.11+. The core SDK has no upper Python bound; the crewai extra carries a < 3.14 ceiling (a CrewAI transitive constraint), so on Python 3.14+ install precipiq[langchain] or pin the adapter yourself.

Log your first decision

# demo.py
from precipiq import Precipiq

# ``enable_batching=False`` for the demo so the call ships synchronously and
# ``log_decision`` returns the server receipt instead of ``None``. In
# production, leave batching on for throughput and call ``pq.flush()`` at
# shutdown.
pq = Precipiq(
    api_key="pq_test_demo_key_REPLACE_ME",
    enable_batching=False,
)

receipt = pq.log_decision(
    agent_id="pricing-bot",
    action_type="discount_offer",
    inputs={"customer_id": "cust_123", "tier": "gold"},
    outputs={"discount_pct": 15},
    confidence=0.82,
    human_in_loop=False,
)
# ``receipt`` is a dict keyed by the server's snake_case schema.
print("decision id:", receipt["decision_id"])
print("chain hash:", receipt["hash"])

Wrap a real function with track

In production you rarely call log_decision directly. Instead, wrap the function that makes the decision — the SDK captures inputs, outputs, and any exception automatically.

@pq.track(agent_id="pricing-bot", action_type="discount_offer")
def compute_discount(customer_id: str, tier: str) -> dict:
    pct = 15 if tier == "gold" else 5
    return {"discount_pct": pct}

compute_discount("cust_456", "silver")

When the customer is charged (Stripe webhook, internal event, etc.), link the decision to the resulting financial event so the AI P&L can attribute dollars.

pq.link_outcome(
    receipt["decision_id"],
    "fev_abc",                      # the financial_event_id from your integration
    correlation_strength=1.0,       # 0..1 — strongest when directly caused
    link_type="revenue",            # "revenue" | "cost" | "liability" | "neutral"
)

Check your AI P&L

pnl = pq.get_ai_pnl(start="2026-04-01", end="2026-04-30")
if pnl is not None:
    print(pnl["total_revenue_attributed"], pnl["currency"])
    print(pnl["net_ai_impact"])

Async client

Every method has an async counterpart on AsyncPrecipiq, which doubles as an async context manager so the buffer is flushed on exit.

from precipiq import AsyncPrecipiq

async with AsyncPrecipiq(api_key="pq_live_...") as pq:
    await pq.log_decision(
        agent_id="refund-bot",
        action_type="approve",
        inputs={"ticket_id": "t1"},
        outputs={"refund_amount": 100},
        confidence=0.95,
    )

Framework adapters

The adapters are import-time optional — importing the SDK core never imports LangChain or CrewAI. Import the adapter module yourself once the matching extra is installed:

from precipiq import Precipiq
from precipiq.integrations.langchain import PrecipiqLangChainCallback
from precipiq.integrations.crewai import PrecipiqCrewAICallback

pq = Precipiq(api_key="pq_live_...")
# Pass the callback into your LangChain / CrewAI run to record each step.
# ``agent_id`` is required — it is stamped on every decision the callback emits.
handler = PrecipiqLangChainCallback(pq, agent_id="pricing-bot")

Graceful degradation

If the Precipiq API is unreachable, the SDK does not raise through your application. Decisions it could not deliver are appended to a rotating local fallback log (~/.precipiq/fallback.log by default) so an operator can replay them later.

Public surface

  • Precipiq / AsyncPrecipiq — sync and async clients.
  • Methods: log_decision, link_outcome, get_ai_pnl, track, flush.
  • Errors: PrecipiqError, PrecipiqAPIError, PrecipiqAuthError, PrecipiqTransportError.
  • Adapters: precipiq.integrations.langchain, precipiq.integrations.crewai.

Local development

cd packages/sdk-python
poetry install
poetry run pytest

License

MIT

Metadata

Release files for precipiq 0.1.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 precipiq 0.1.0
File Size Uploaded Provenance Actions
precipiq-0.1.0.tar.gz 22.6 kB With provenance Details for precipiq-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for precipiq 0.1.0
File Interpreter ABI Platform Actions
precipiq-0.1.0-py3-none-any.whl Python 3 none any Details for precipiq-0.1.0-py3-none-any.whl

Total release size: 47.3 kB

Release files / precipiq-0.1.0.tar.gz

Download URL precipiq-0.1.0.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
130bbc907925d01377fc0c357d67974749808439f217e987b030207d0e92f325
BLAKE2b-256 checksum
How to use checksums
3dd08319970a432c933ee854f8ba6ba20350cf4245ff6de8b38c46cc371e4614
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Jul 25, 2026.

Transparency log

Release files / precipiq-0.1.0-py3-none-any.whl

Download URL precipiq-0.1.0-py3-none-any.whl
Size 24.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
010975dd97d8c5effd2f0931e9d66084e0d7d234c217f09a8b8a45a6e504d6f7
BLAKE2b-256 checksum
How to use checksums
1915e7d03c681d991de58c4e3e910d57434d6859d92692816578bbf1c83939a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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 Jul 25, 2026.

Transparency log

Security for precipiq 0.1.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for precipiq-0.1.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 Jul 25, 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.1.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