Bitfab
Bitfab client for provider-based API calls.
Monorepo Structure
This package is part of the Harvest monorepo. While the TypeScript/JavaScript packages use a pnpm workspace for shared dependencies, this Python package uses Poetry for its dependency management.
Note: The pnpm workspace includes:
bitfab-web- Next.js web applicationbitfab-typescript-sdk- TypeScript SDKbitfab-vscode- VS Code extensionfrontend- Legacy frontend
From the root directory, you can run TypeScript tests and validation across all packages with pnpm test or pnpm validate.
Installation
Python 3.10 or newer is required.
Basic Installation
pip install bitfab-py
With OpenAI Tracing Support
If you want to use the OpenAI Agents SDK tracing integration:
pip install bitfab-py[openai-tracing]
Local Development
For local development:
cd bitfab-python-sdk
poetry install --with dev
After installation, you can use developer tasks. For the best experience, add Poetry's venv to your PATH:
# Add to your ~/.zshrc or ~/.bashrc
export PATH="$(poetry env info --path)/bin:$PATH"
# Then you can use 'dev' directly (no ./run or poetry run needed!)
dev list
dev test
See Development Tasks below for all available commands.
Or install as an editable package from the parent directory:
poetry add --editable ../bitfab-python-sdk
Usage
Basic Usage
from bitfab import Bitfab
client = Bitfab(
api_key="bf_your_api_key_here",
service_url="https://bitfab.ai", # Optional, defaults to production
env_vars={"OPENAI_API_KEY": "sk-your-openai-key"}, # Optional, for local BAML execution
)
result = client.call("method_name", arg1="value1", arg2="value2")
OpenAI Agents SDK Tracing
If you have the openai-agents package installed (via pip install bitfab-py[openai-tracing]), you can use the tracing processor:
from bitfab import Bitfab
from agents import Agent, add_trace_processor
bitfab = Bitfab(api_key="bf_your_api_key_here")
# Register the processor once: it captures agent internals (LLM/tool/handoff spans).
add_trace_processor(bitfab.get_openai_tracing_processor())
agent = Agent(name="my-agent", instructions="...")
# The run wrapper records a replayable root carrying the run input.
handler = bitfab.get_openai_agent_handler("my-agent")
# Swap Runner.run(agent, input) -> handler.wrap_run(agent, input)
result = await handler.wrap_run(agent, "user input here")
The processor alone records a root with no input, so a processor-only trace is not replayable; wrap_run (a drop-in for Runner.run) records the keyed, replayable root.
Note: If you try to use get_openai_tracing_processor() without installing the openai-tracing extra, you'll get a helpful error message telling you to install it.
Configuration
api_key: Required - Your Bitfab API key (generate from your Bitfab dashboard)service_url: Optional - The Bitfab service URL (defaults tohttps://bitfab.ai)env_vars: Optional - Environment variables for LLM providers (e.g.,{"OPENAI_API_KEY": "..."})enabled: Optional - Enable/disable tracing (defaults toTrue). WhenFalse, decorated functions still execute but no spans are sent.
OpenTelemetry Transport
Bitfab keeps its public decorators and framework handlers, while one private
OpenTelemetry TracerProvider and BatchSpanProcessor per client
manage the bounded queue, batch worker, export scheduling, flush, and shutdown
lifecycle. Pipelines are created lazily on the first trace send and are not
installed globally, so an unused or disabled client starts no OTel worker and
the SDK does not replace an application's OTel setup. Framework integrations
submit the existing replay-safe Bitfab payload through the same transport
interface. Flush and shutdown honor one total caller-supplied deadline.
Long-running processes that create transient clients should call
client.close() or use with Bitfab(...) as client: to release that client's
workers; shared clients still shut down automatically at process exit.
The LangGraph/LangChain handler keeps langsmith:hidden scheduler callbacks
only for local parent resolution and submits visible Bitfab spans through OTel.
By default, batches are sent directly to Bitfab. To send through a local OTel
Collector instead, set BITFAB_OTEL_EXPORTER_ENDPOINT to its OTLP/HTTP base
URL (for example, http://localhost:4318). The SDK uses OTel's official
OTLP/HTTP exporter, appends /v1/traces, and sends protobuf. Production and
replay traffic use this same pipeline. Before finalizing a replay, the SDK
flushes OTel and polls Bitfab's replay-status API until every expected trace
completion and span count is persisted. This keeps Collector delivery batched
without mistaking Collector acceptance for Bitfab persistence.
OTel schedules direct exports in internal batches of at most 512 carriers. The
direct exporter packs that candidate window into requests containing at most
eight carriers and no more than the configured encoded-byte target, then runs
up to 32 complete requests concurrently. Set
BITFAB_OTEL_EXPORT_CONCURRENCY to an integer from 1 through 64 to tune
that direct-request concurrency; invalid values fall back to 32.
Collector delivery uses OTel's official exporter with at most 32 carriers per
export. The SDK partitions Collector protobuf exports into requests of at most
approximately 3 MB. Direct OTLP/JSON requests use the same limit while packing
up to eight carriers. Set
BITFAB_OTEL_MAX_REQUEST_BYTES to a positive integer no greater than 3000000
to use a smaller request target for a Collector or proxy with a stricter limit.
Invalid or larger values fall back to 3000000. A carrier that exceeds the
configured limit by itself cannot be split without changing the captured
payload; the SDK logs the failed export without interrupting the host
application.
If Bitfab accepts only part of a batch, it returns the standard OTLP
partialSuccess response and the SDK logs the rejected-span count and reason.
receivers:
otlp:
protocols:
http:
exporters:
otlphttp/bitfab:
endpoint: https://bitfab.ai/api/sdk/otel
encoding: json
headers:
Authorization: Bearer ${env:BITFAB_API_KEY}
service:
pipelines:
traces:
receivers: [otlp]
exporters: [otlphttp/bitfab]
Every trace uses one delivery path: when the Collector endpoint is configured, the SDK does not also send the same batch directly to Bitfab.
See the Python OpenTelemetry Transport Architecture for the full component ownership, carrier format, replay barrier, batching, and lifecycle design.
Development Tasks
This project uses a Python-based developer tasks module (dev/) instead of Makefiles for better cross-platform support and more robust CLI capabilities.
Using Developer Tasks
After running poetry install --with dev, you can use developer tasks:
Quick Setup (One-time)
# Install dependencies (creates the 'dev' script in the venv)
poetry install --with dev
# Run this script to add to PATH for current session and get command to make it permanent
./setup-dev-path.sh
# Copy-paste the command it outputs, then reload your shell config:
source ~/.zshrc # or ~/.bashrc
The setup-dev-path.sh script will:
- Add the venv bin to PATH for your current session
- Detect your shell (zsh/bash) and output a command you can copy-paste to make it permanent
- Skip if already configured
Using Developer Commands
Once PATH is set up, use commands directly - just like make <target>:
dev list # List all available commands
dev test # Run tests
dev test --verbose # Run tests with verbose output
dev lint # Lint code
dev format # Format code
dev build # Build package
dev publish patch # Publish with version bump
How it works: When you define [tool.poetry.scripts] in pyproject.toml, Poetry creates executable scripts in the venv's bin/ directory. Adding that bin/ to PATH makes those scripts available as commands.
Key advantage: Just like Makefiles, it's super clear - dev <command> is as obvious as make <target>!
Module Structure
Each command is in its own file in the dev/ module:
dev/test.py- Test commandsdev/lint.py- Lintingdev/build.py- Buildingdev/publish.py- Publishing- etc.
This makes it easy to find and modify individual commands.
Publishing
This package uses bump-my-version for version management. To publish a new version:
# Use the dev command
dev publish patch # Bump patch (0.3.0 -> 0.3.1)
dev publish minor # Bump minor (0.3.0 -> 0.4.0)
dev publish major # Bump major (0.3.0 -> 1.0.0)
dev publish version=1.2.3 # Custom version
# Or just bump version without publishing
dev bump patch
dev bump minor
The publish process will:
- Run all tests
- Bump the version in
pyproject.toml - Commit and tag the changes
- Build the package
- Prompt for confirmation before publishing to PyPI
Note: Publishing requires:
- A clean git working directory (no uncommitted changes)
- Poetry installed and configured
- PyPI credentials configured (via
poetry config pypi-token.pypi <token>)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bitfab_py-0.33.7.tar.gz.
File metadata
- Download URL: bitfab_py-0.33.7.tar.gz
- Upload date:
- Size: 104.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80c30a040ee4a0071dfa2ec909dc8ed32a2e68ce758a4a1fe6c5a9146168a7d1
|
|
| MD5 |
700a5646baf526ebfecd31883c68bb1e
|
|
| BLAKE2b-256 |
668cee5cddf2e51d83fe2027e7e79e476645be1870468e5bf74b88f0f02fa152
|
Provenance
The following attestation bundles were made for bitfab_py-0.33.7.tar.gz:
Publisher:
publish-python-sdk.yml on Project-White-Rabbit/ai-assistant
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bitfab_py-0.33.7.tar.gz -
Subject digest:
80c30a040ee4a0071dfa2ec909dc8ed32a2e68ce758a4a1fe6c5a9146168a7d1 - Sigstore transparency entry: 2341177485
- Sigstore integration time:
-
Permalink:
Project-White-Rabbit/ai-assistant@deee3e8c64e51f738cbc2cf41919b5f368e299c4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Project-White-Rabbit
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
publish-python-sdk.yml@deee3e8c64e51f738cbc2cf41919b5f368e299c4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bitfab_py-0.33.7-py3-none-any.whl.
File metadata
- Download URL: bitfab_py-0.33.7-py3-none-any.whl
- Upload date:
- Size: 110.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a012bce800515504d9e9bb0f141165dbce00d447bc02e00eca9f739f94c747e
|
|
| MD5 |
00ff97600f0c1f9fbd7ecd981aad1f23
|
|
| BLAKE2b-256 |
5c05cb69f12e33c8dc30e9189a106b93f911a9d80273f6880b6edc882607764d
|
Provenance
The following attestation bundles were made for bitfab_py-0.33.7-py3-none-any.whl:
Publisher:
publish-python-sdk.yml on Project-White-Rabbit/ai-assistant
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bitfab_py-0.33.7-py3-none-any.whl -
Subject digest:
4a012bce800515504d9e9bb0f141165dbce00d447bc02e00eca9f739f94c747e - Sigstore transparency entry: 2341177494
- Sigstore integration time:
-
Permalink:
Project-White-Rabbit/ai-assistant@deee3e8c64e51f738cbc2cf41919b5f368e299c4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Project-White-Rabbit
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
publish-python-sdk.yml@deee3e8c64e51f738cbc2cf41919b5f368e299c4 -
Trigger Event:
push
-
Statement type: