Pydantic Logfire¶
From the team behind Pydantic, Logfire is a new type of observability platform built on the same belief as our open source library — that the most powerful tools can be easy to use.
Logfire is built on OpenTelemetry, and supports monitoring your application from any language, with particularly great support for Python! Read more.
Getting Started¶
This page is a quick walk-through for setting up a Python app:
Set up Logfire¶
- Log into Logfire
- Follow the prompts to create your account
- From your Organisation, click New project to create your first project
The first time you use Logfire in a new environment, you'll need to set up a project. A Logfire project is a namespace for organizing your data. All data sent to Logfire must be associated with a project.
You can also create a project via CLI...
Check the SDK CLI documentation for more information on how to create a project via CLI.
Install the SDK¶
- In the terminal, install the Logfire SDK (Software Developer Kit):
pip install logfire
uv add logfire
rye add logfire
poetry add logfire
conda install -c conda-forge logfire
- Once installed, try it out!
logfire -h
- Next, authenticate your local environment:
logfire auth
Upon successful authentication, credentials are stored in ~/.logfire/default.toml
.
Instrument your project¶
Development setup
During development, we recommend using the CLI to configure Logfire. You can also use a write token.
- Set your project
logfire projects use <first-project>
Run this command from the root directory of your app, e.g. ~/projects/first-project
- Write some basic logs in your Python app
import logfire
logfire.configure() # (1)!
logfire.info('Hello, {name}!', name='world') # (2)!
- The
configure()
method should be called once before logging to initialize Logfire. - This will log
Hello world!
withinfo
level.
Other log levels are also available to use, including trace
, debug
, notice
, warn
,
error
, and fatal
.
- See your logs in the Live view
Production setup
In production, we recommend you provide your write token to the Logfire SDK via environment variables.
-
Generate a new write token in the Logfire platform
- Go to Project Settings Write Tokens
- Follow the prompts to create a new token
-
Configure your Logfire environment
LOGFIRE_TOKEN=<your-write-token>
Running this command stores a Write Token used by the SDK to send data to a file in the current directory, at .logfire/logfire_credentials.json
- Write some basic logs in your Python app
import logfire
logfire.configure() # (1)!
logfire.info('Hello, {name}!', name='world') # (2)!
- The
configure()
method should be called once before logging to initialize Logfire. - This will log
Hello world!
withinfo
level.
Other log levels are also available to use, including trace
, debug
, notice
, warn
,
error
, and fatal
.
- See your logs in the Live view
Next steps¶
Ready to keep going?
- Read about Tracing with Spans
- Complete the Onboarding Checklist
More topics to explore
- Logfire's real power comes from integrations with many popular libraries
- As well as spans, you can use Logfire to record metrics
- Logfire doesn't just work with Python, read more about Language support