Precipiq) and an async twin (AsyncPrecipiq) that buffer decisions locally and flush them to the ledger in the background. Both clients share the same public surface, so you can switch between them without rewriting your integration logic.
Install
Overview
The public surface of theprecipiq package:
Precipiq/AsyncPrecipiq— sync and async clientsprecipiq.integrations.langchain— LangChain callback handlerprecipiq.integrations.crewai— CrewAI callback handler
Precipiq client
Precipiq is the thread-safe synchronous entry point. It buffers decisions in memory and flushes them on a background thread, so your hot path never blocks on network I/O.
Constructor
log_decision
enable_batching=False). Returns the server receipt when batching is disabled; returns None when the decision is queued for a later batched ship.
flush
POST /api/v1/decisions; larger drains use the batch endpoint POST /api/v1/decisions/batch (up to 100 decisions per call), so N queued decisions cost ceil(N/100) round-trips instead of N. The server preserves hash-chain order inside each batch.
Call
flush() during graceful shutdown to ensure no decisions are lost. Alternatively, use close() which flushes and then stops the background thread and closes the HTTP connection.link_outcome
decision_id and financial_event are positional so callers can write pq.link_outcome(decision_id, event_id, ...). correlation_strength and link_type are keyword-only so every link is explicit about its probabilistic weighting and economic character.
get_ai_pnl
track
functools.wraps. Extra **metadata keyword arguments are stamped onto every decision produced by the decorated function, letting you attach deployment context (version, env, etc.) without a second call.
track works on both regular and async def functions — coroutines are detected via inspect.iscoroutinefunction and wrapped accordingly.close
AsyncPrecipiq as a context manager.
AsyncPrecipiq client
AsyncPrecipiq is the async twin of Precipiq. All methods are coroutines and batching uses an asyncio.Lock with a background task instead of a thread, so concurrent log_decision calls cannot interleave writes into the buffer.
Use it as a context manager for automatic cleanup:
Precipiq — log_decision, flush, link_outcome, get_ai_pnl, track, and close — all as async def coroutines. See the sync client docs above for argument signatures and descriptions.
AsyncPrecipiq.flush() drains and ships queued decisions, batching when there is more than one item — the same ceil(N/100) round-trip logic as the sync client.
Exceptions
All SDK exceptions inherit fromPrecipiqError so you can catch the base class when you want to handle all SDK failures uniformly.
Integrations
LangChain
PrecipiqLangChainCallback is a LangChain BaseCallbackHandler that automatically tracks LLM, tool, and chain calls. Streaming responses are handled correctly — tokens are aggregated per run_id and a single consolidated decision is shipped on on_llm_end, so you get one record per completion rather than one per token.
CrewAI
PrecipiqCrewAICallback tracks every agent task execution. Pass it as the step_callback on a crewai.Agent or crewai.Crew.