Registry / observability / logfire-api

logfire-api

JSON →
library4.41.0pypypi✓ verified 30d ago

The `logfire-api` library is a lightweight shim for the Logfire SDK, designed for packages that want to offer opt-in integration with Logfire without a hard dependency. It provides a clone of the `logfire` package's Python API that performs no-op operations if `logfire` is not installed, but makes real calls when `logfire` is present. This allows users of an integrated package to decide whether to install and configure Logfire for observability. The current version is 4.31.0, with frequent releases aligning with the main Logfire SDK.

pip install logfire-api
INSTALL
IMPORT
SIG · LOGFIRE-API
L
logfire-api
observabilitypythonv4.41.0
Install
1.6s avg
Import
342ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v4.41.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.368s · 18.5MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.316s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

logfire
✓ import logfire_api as logfire
Importing `logfire_api` as `logfire` is the recommended pattern to ensure compatibility with code written for the full `logfire` SDK.

This quickstart demonstrates how to use `logfire_api` as a shim. When `logfire` (the full SDK) is installed and configured by the end-user, `logfire_api` calls will be delegated to the actual Logfire SDK. If `logfire` is not installed, `logfire_api` methods will gracefully act as no-ops. Library authors typically `import logfire_api as logfire` and use its API, leaving the `logfire.configure()` call to their users. To send data to the Logfire platform, the `LOGFIRE_TOKEN` environment variable must be set.

import os import logfire_api as logfire # Simulate Logfire being installed (or not) for demonstration # In a real scenario, `logfire` would either be in your environment or not. # For this example, we'll configure a mock for `logfire.configure` if `logfire` is not installed. # In a production environment, users would `pip install logfire` and configure it. try: import logfire as _actual_logfire logfire_installed = True except ImportError: logfire_installed = False if not logfire_installed: print("Logfire (the full SDK) is NOT installed. `logfire_api` will act as a no-op.") else: print("Logfire (the full SDK) IS installed. `logfire_api` will delegate to it.") # Configure Logfire (this would typically be done by the end-user of a library using logfire-api) # For logfire-api, library authors usually *don't* call configure(). # The actual `logfire.configure()` would typically read LOGFIRE_TOKEN or other env vars. if logfire_installed: # Only configure if the actual logfire SDK is present, otherwise it's a no-op by design os.environ['LOGFIRE_TOKEN'] = os.environ.get('LOGFIRE_TOKEN', 'your-logfire-write-token') # Replace with a real token in production logfire.configure(service_name='my-shimmed-app') print("Logfire (actual SDK) configured.") else: print("Skipping logfire.configure() as the actual SDK is not installed.") @logfire.instrument("my_function") def my_function(name: str): logfire.info("Hello from {name}!", name=name) with logfire.span("inner_operation"): logfire.debug("Performing an inner operation.") return f"Processed {name}" result = my_function("World") print(f"Function returned: {result}") # To see output in Logfire, ensure LOGFIRE_TOKEN is set and 'logfire' is installed. # The above `logfire.configure()` will only run if `logfire` is installed. # Otherwise, all logfire calls above will effectively do nothing.
Debug
Known issues
gotchaThe `logfire-api` package is a shim; its methods are no-ops if the full `logfire` SDK is not installed. Integrators should avoid calling `logfire_api.configure()` directly within their library, as configuration is meant for the end-user who decides whether to enable Logfire.
fix
Library authors using `logfire-api` should only `import logfire_api as logfire` and use its logging/instrumentation methods. The end-user is responsible for installing `pip install logfire` and calling `logfire.configure()` to enable and configure the actual Logfire SDK.
affects: All versions
breakingAs `logfire-api` mirrors the API of the main `logfire` SDK, any breaking changes introduced in major versions of `logfire` (e.g., changes to method signatures, attribute names, or default behaviors) will implicitly affect users of `logfire-api` when they have the corresponding `logfire` version installed. For example, Logfire v0.51.0 introduced changes to system metrics collection and auto-tracing behavior.
fix
Always consult the release notes for the main `logfire` SDK when updating `logfire`, as `logfire-api` will reflect these changes if `logfire` is present. Adapt your code to new API patterns as required by the `logfire` SDK.
affects: All versions of `logfire-api` in conjunction with `logfire` versions that introduce breaking changes.
gotchaFor Logfire to send data to the Logfire platform, the `LOGFIRE_TOKEN` environment variable (or other configuration methods) must be correctly set, and the full `logfire` package must be installed and configured. Without proper configuration of the underlying `logfire` SDK, `logfire-api` calls will not result in any observable telemetry.
fix
Ensure end-users are aware they need to `pip install logfire` and configure it (e.g., by setting `LOGFIRE_TOKEN` and calling `logfire.configure()`) to enable data submission.
affects: All versions
Errors
Common errors & fixes
TypeError: '<' not supported between instances of 'MagicMock' and 'float'
This error occurs when the `logfire` package is not installed, and `logfire-api` is providing `MagicMock` objects as no-ops. Subsequent code that expects real numeric values (like `float` for duration calculations) will fail when attempting operations with these mock objects.
fix
Install the full `logfire` SDK (`pip install logfire`) to ensure real `Logfire` objects are used, allowing proper type-based operations.
ModuleNotFoundError: No module named 'pytest'
This error can occur if an older version of the `logfire` SDK (which `logfire-api` delegates to when installed) has an implicit dependency on `pytest` within certain submodules (e.g., `logfire.testing`), and `pytest` is not installed in the environment.
fix
Install the `pytest` package (`pip install pytest`) to satisfy the missing dependency.
ModuleNotFoundError: No module named 'openai._legacy_response'
This specific `ModuleNotFoundError` arises when using `logfire.instrument_openai()` with an incompatible version of the `openai` library. The `logfire` SDK's OpenAI instrumentation expects a different internal structure or module path that is not present in the installed `openai` version.
fix
Ensure compatibility between your `logfire` and `openai` library versions. You might need to upgrade or downgrade `openai` to a version known to work with your `logfire` SDK version, or check the `logfire` documentation for supported `openai` versions.
Logfire authentication configuration has not been set up.
This is a common warning message (rather than a Python exception) indicating that the `logfire.configure()` method has not been called with a valid project token, or the token is not correctly loaded from environment variables (e.g., `LOGFIRE_TOKEN`). This prevents telemetry data from being sent to the Logfire platform, even if `logfire` is installed and `logfire-api` is delegating calls.
fix
Call `logfire.configure(token='your_project_token_here')` early in your application's lifecycle, or set the `LOGFIRE_TOKEN` environment variable with your valid Logfire project token. Authenticate via `logfire auth` if necessary.
Upgrade
Version history
4.41.0latest on PyPI · released Aug 20, 2026
Audit
Dependencies
logfireoptionalThe `logfire-api` package functions as a no-op shim unless the main `logfire` SDK is installed, at which point it uses Logfire's functionality.
Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
2
Resources
logfire-api — pip install logfire-api · libregistry