Skip to content

Getting Started

CI codecov pypi license versions Join Slack

About 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.

Overview

This page is a quick walk-through for setting up a Python app:

  1. Set up Logfire
  2. Install the SDK
  3. Instrument your project

Set up Logfire

  1. Log into Logfire
  2. Follow the prompts to create your account
  3. Once logged in, you'll see the Welcome to Logfire prompt. Click Let's go! to go to the starter-project Setup page.

Welcome to Logfire

  1. You will find how to send data to your starter-project there. Also, there are some code snippets to help you get started.

A Logfire project is a namespace for organizing your data. All data sent to Logfire must be associated with a project.

Ready to create your own projects in UI or CLI?
  • In the UI, create projects by navigating to the Organization > Projects page, and click New project.
  • For CLI check the SDK CLI documentation.

Install the SDK

  1. In the terminal, install the Logfire SDK (Software Developer Kit):
pip install logfire
uv add logfire
poetry add logfire
conda install -c conda-forge logfire
  1. Once installed, try it out!
logfire -h
  1. 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.

  1. Set your project
in the terminal:
logfire projects use <first-project>

Run this command from the root directory of your app, e.g. ~/projects/first-project

  1. Write some basic logs in your Python app
hello_world.py
import logfire

logfire.configure()  # (1)!
logfire.info('Hello, {name}!', name='world')  # (2)!
  1. The configure() method should be called once before logging to initialize Logfire.
  2. This will log Hello world! with info level.

Other log levels are also available to use, including trace, debug, notice, warn, error, and fatal.

  1. See your logs in the Live view

Hello world screenshot

Production setup

In production, we recommend you provide your write token to the Logfire SDK via environment variables.

  1. Generate a new write token in the Logfire platform

    • Go to Project Settings Write Tokens
    • Follow the prompts to create a new token
  2. Configure your Logfire environment

In the terminal:
export 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

  1. Write some basic logs in your Python app
hello_world.py
import logfire

logfire.configure()  # (1)!
logfire.info('Hello, {name}!', name='world')  # (2)!
  1. The configure() method should be called once before logging to initialize Logfire.
  2. This will log Hello world! with info level.

Other log levels are also available to use, including trace, debug, notice, warn, error, and fatal.

  1. See your logs in the Live view

Hello world screenshot


Next steps

Ready to keep going?

More topics to explore...