Fiberplane with Python (alpha)
Fiberplane Studio is an API debugger for local developement. This is a work in progress on supporting Python applications with Fiberplane instrumentation and debugging. This directory includes the fpxpy package which supports FastAPI instrumentation and a few examples to quickstart.
fpxpy
Provides instrumentation and route detection for FastAPI apps.
The package is available on PyPI, installing it as simple as
uv add fpxpy
After installing fpxpy either from source or from pip, simply add the second line
referencing your FastAPI app.
from fpxpy import setup
app = FastAPI()
setup(app)
After that, when running your FastAPI server, be sure to set the FPX_ENDPOINT env variable
pointing to your instance of Fiberplane Studio, e.g:
FPX_ENDPOINT=http://localhost:8788/v1/traces uv run fastapi dev main.py
Using MCP server with Fiberplane
Fiberplane runs a local API that can be used through the Model Context Protocol. This enables MCP hosts like Claude Desktop to connect to Fiberplane Studio and query the API.
Setting up using Claude Desktop
If you have Claude Desktop installed, update the configuration to use the local MCP server.
{
"mcpServers": {
"fiberplane": {
"command": "npx",
"args": [
"@fiberplane/mcp-server-fiberplane"
]
}
}
}
fpxpy API
The package exports two functions:
setupwhich is used for adding middleware to the FastAPI appmeasurewhich is used for creating spans each time a function is called. Typically used as a decorator.
setup
Function
Initializes FPX instrumentation for a FastAPI application by configuring route detection and span instrumentation.
Parameters
- app (
FastAPI): The FastAPI application instance that was instrumented
Returns
FastAPI: The instrumented application instance
Environment Variables
FPX_ENDPOINT: Required. The endpoint URL for FPX instrumentation
Example Usage
from fastapi import FastAPI
from fpxpy import setup
app = FastAPI()
setup(app)
Behavior
- Checks for
FPX_ENDPOINTenvironment variable - If not set:
- Prints warning message
- Returns unmodified app
- If set:
- Installs route detection
- Configures span instrumentation with parsed URL
- Returns instrumented app
Notes
-
Must be called after FastAPI app creation
-
Requires
FPX_ENDPOINTenvironment variable -
Modifies app in-place by adding middleware and route handlers
Measure
A decorator that wraps functions with OpenTelemetry span instrumentation to measure execution time and track errors.
Usage
Basic Usage:
from fpxpy import measure
from opentelemetry.trace import SpanKind
@measure()
def my_function():
return "Hello World"
@measure("custom-name")
def named_function():
return "Hello Named World"
With Custom Span Configuration:
@measure(
name="db-query",
span_kind=SpanKind.CLIENT,
attributes={"db.system": "postgresql"}
)
async def query_database():
# ... database code
pass
With Callbacks:
def on_start_cb(span, *args, **kwargs):
span.set_attribute("custom.start", "started")
@measure(
name="monitored-function",
on_start=on_start_cb,
on_success=lambda span, result: span.set_attribute("result.value", str(result)),
on_error=lambda span, exc: span.set_attribute("error.message", str(exc))
)
def monitored_function():
pass
Parameters
- name (
Optional[str]): Name of the span. Defaults to the function name if not provided. - func (
Optional[Callable]): Function to wrap. Used internally by the decorator. - span_kind (
SpanKind): Kind of span to create. Defaults toSpanKind.INTERNAL - on_start (
Optional[Callable]): Callback executed when span starts. Receives span and function arguments. - on_success(
Optional[Callable]): Callback executed on successful completion. Receives span and function result. - on_error (
Optional[Callable]): Callback executed on error. Receives span and exception. - check_result (
Optional[Callable]): Optional validation function for the result. - attributes (
Optional[Dict]): Initial attributes to set on the span.
Returns
Returns a wrapped function that:
- Creates a new span when called
- Executes the original function
- Records success/failure in the span
- Supports both sync and async functions
Notes
- Automatically handles both synchronous and asynchronous functions
- Preserves function signatures and docstrings
- Supports direct function decoration and configuration via parameters
- Integrates with OpenTelemetry context propagation
- Thread-safe and context-manager compatible
Examples
Track Database Queries:
@measure(
name="db-query",
span_kind=SpanKind.CLIENT,
attributes={"db.system": "postgresql"}
)
async def get_user(user_id: str):
# ... database code
pass
Monitor HTTP Requests
@measure(
name="http-request",
span_kind=SpanKind.CLIENT,
attributes={"http.method": "GET"}
)
async def fetch_data(url: str):
# ... http request code
pass
Track Function Performance
@measure(
name="expensive-calculation",
attributes={"calculation.type": "matrix-multiply"}
)
def matrix_multiply(a: np.ndarray, b: np.ndarray):
# ... calculation code
pass
Example application
We also have an example application that can be found under /examples/python-fastapi
Development
This package uses uv for its dependencies and running the tooling. The following tools are used for linting, checking & formatting. They are listed as part of the dev dependencies (and will be installed by uv by default).
Metadata
Release files for fpxpy 0.3.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fpxpy-0.3.5.tar.gz | 114.6 kB | Without provenance | Details for fpxpy-0.3.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fpxpy-0.3.5-py3-none-any.whl | Python 3 | none | any | Details for fpxpy-0.3.5-py3-none-any.whl |
Total release size: 131.0 kB
Release files / fpxpy-0.3.5.tar.gz
| Download URL | fpxpy-0.3.5.tar.gz |
|---|---|
| Size | 114.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ac1d97bd5b5b31e01018c948b480a671e2e911a35a1ba6ac38b20219c85077d
|
|
BLAKE2b-256 checksum How to use checksums |
9aabdfe0a28506a278768e81d33ce2e3061203c3bf1555a6312abb1a77eadb44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.11
|
Release files / fpxpy-0.3.5-py3-none-any.whl
| Download URL | fpxpy-0.3.5-py3-none-any.whl |
|---|---|
| Size | 16.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
605ef04e0e43ee2a0d4532267db0394cd59d5200b169d2ae165350ada105fd33
|
|
BLAKE2b-256 checksum How to use checksums |
54c7ba29bed18b78c1462a6e0c4a2f22d982a3c191031922a83da5cc2a3a1090
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.11
|
Security for fpxpy 0.3.5
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.