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-apiVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
Install the full `logfire` SDK (`pip install logfire`) to ensure real `Logfire` objects are used, allowing proper type-based operations.
Install the `pytest` package (`pip install pytest`) to satisfy the missing dependency.
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.
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.