Skip to content

Getting started with the Python SDK

The Python SDK is split into small packages. Start with the package that matches how you want to integrate Prefactor.

PackageUse it whenReference
prefactor-coreCore client for agent instances, spans, schema registration, and wrapper authors.Reference
prefactor-httpLow-level async client for direct access to the Prefactor API.Reference
prefactor-langchainLangChain integration package with middleware and LangChain-specific span types.Reference
prefactor-livekitLiveKit integration package for tracing session and voice-agent events.Reference

Install the package you need:

Terminal window
pip install prefactor-langchain

Or install a different package:

Terminal window
pip install prefactor-core
pip install prefactor-http
pip install prefactor-livekit

Most applications start with an integration package. This example uses the LangChain middleware:

from prefactor_langchain import PrefactorMiddleware
middleware = PrefactorMiddleware.from_config(
api_url="https://api.prefactor.ai",
api_token="your-token",
agent_id="my-agent",
agent_name="My Agent",
)

If you want to build your own wrapper or instrument code directly, start with prefactor-core:

from prefactor_core import PrefactorCoreClient, PrefactorCoreConfig
from prefactor_http import HttpClientConfig
config = PrefactorCoreConfig(
http_config=HttpClientConfig(
api_url="https://api.prefactor.ai",
api_token="your-token",
)
)
client = PrefactorCoreClient(config)
await client.initialize()