Home

Awesome

pyinstrument

PyPI version .github/workflows/test.yml Build wheels

Documentation

<!-- MARK intro start -->

Screenshot

Pyinstrument is a Python profiler. A profiler is a tool to help you optimize your code - make it faster. To get the biggest speed increase you should focus on the slowest part of your program. Pyinstrument helps you find it!

☕️ Not sure where to start? Check out this video tutorial from calmcode.io!

<!-- MARK intro end -->

Installation

<!-- MARK installation start -->
pip install pyinstrument

Pyinstrument supports Python 3.8+.

<!-- MARK installation end -->

To run Pyinstrument from a git checkout, there's a build step. Take a look at Contributing for more info.

Documentation

To learn how to use pyinstrument, or to check the reference, head to the documentation.

Known issues

Changelog

v5.0.0

11 October 2024

Loads of improvements to the HTML renderer!

Check my blog post for more info on the new features.

v4.7.3

6 September 2024

v4.7.2

5 August 2024

v4.7.1

2 August 2024

v4.7.0

1 August 2024

v4.6.2

26 January 2024

v4.6.1

8 November 2023

v4.6.0

12 October 2023

v4.5.3

7 September 2023

v4.5.2

1 September 2023

v4.5.1

22 July 2023

v4.5.0

5 June 2023

v4.4.0

5 November 2022

v4.3.0

21 August 2022

v4.2.0

v4.1.1

v4.1.0

v4.0.4

v4.0.3

v4.0.2

v4.0.0

v3.4.2

v3.4.1

v3.4.0

v3.3.0

v3.2.0

v3.1.2

v3.1.1

v3.1.0

v3.0.3

v3.0.2

v3.0.1

v3.0.0

Yikes! See #49 for the gory details. I hope you like it.

v2.3.0

v2.2.1

v2.2.0

v2.1.0

v2.0.4

v2.0.3

v2.0.2

v2.0.1

v2.0.0

v0.13

v0.12

Contributing

To setup a dev environment:

virtualenv --python=python3 env
. env/bin/activate
pip install --upgrade pip
pip install -r requirements-dev.txt
pre-commit install --install-hooks

To get some sample output:

pyinstrument examples/wikipedia_article_word_count.py

To run the tests:

pytest

To run linting checks locally:

pre-commit run --all-files

Some of the pre-commit checks, like isort or black, will auto-fix the problems they find. So if the above command returns an error, try running it again, it might succeed the second time :)

Running all the checks can be slow, so you can also run checks individually, e.g., to format source code that fails isort or black checks:

pre-commit run --all-files isort
pre-commit run --all-files black

To diagnose why pyright checks are failing:

pre-commit run --all-files pyright

The HTML renderer Vue.js app

The HTML renderer works by embedding a JSON representation of the sample with a Javascript 'bundle' inside an HTML file that can be viewed in any web browser.

To edit the html renderer style, do:

cd html_renderer
npm ci
npm run serve

When launched without a top-level window.profileSession object, it will fetch a sample profile so you can work with it.

To compile the JS app and bundle it back into the pyinstrument python tool:

bin/build_js_bundle.py [--force]