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.
- Source: prefactordev/python-sdk
- DeepWiki: prefactordev/python-sdk on DeepWiki
Choose a package
Section titled “Choose a package”| Package | Use it when | Reference |
|---|---|---|
prefactor-core | Core client for agent instances, spans, schema registration, and wrapper authors. | Reference |
prefactor-http | Low-level async client for direct access to the Prefactor API. | Reference |
prefactor-langchain | LangChain integration package with middleware and LangChain-specific span types. | Reference |
prefactor-livekit | LiveKit integration package for tracing session and voice-agent events. | Reference |
Installation
Section titled “Installation”Install the package you need:
pip install prefactor-langchainOr install a different package:
pip install prefactor-corepip install prefactor-httppip install prefactor-livekitQuick start
Section titled “Quick start”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, PrefactorCoreConfigfrom 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()