FastAPI
Python

Our FastAPI integration lets you instrument individual HTTP requests. Please note that Blackfire supports FastAPI `0.51.0` and higher.

Install Blackfire for Python.

The recommended way to use Blackfire with FastAPI is to use the blackfire-python command, as it configures the needed bits for you.

Run your webserver with blackfire-python command:

1
blackfire-python uvicorn main:app

Or with hypercorn:

1
blackfire-python hypercorn main:app

If you prefer configuring FastAPI manually, you can add the following call manually within your code:

1
2
import blackfire
blackfire.patch_all()

This call should be made as early as possible in the lifecycle of an application, ideally before any other import statements.

Then, restart your server.

You can use the blackfire curl command to profile specific requests:

1
blackfire curl http://localhost:8000/polls/1/results

You can also use one of our browser extensions for Firefox or Chrome.

Read more about profiling web applications with a browser, or profiling with the CLI.