Development Status
- 5 - Production/Stable
Intended Audience
- Developers
Programming Language
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: 3.14
- Python :: 3.15
Topic
- Software Development :: Libraries :: Python Modules
- Utilities
This is the official line_profiler repository. The most recent version of line-profiler on pypi points to this repo. The original line_profiler package by @rkern is unmaintained. This fork is the official continuation of the project.
Github |
|
Pypi |
|
ReadTheDocs |
line_profiler is a module for doing line-by-line profiling of functions. Use it when function-level profiling identifies a slow function, but you need to see which individual source lines account for the time. kernprof is the command-line helper included with the package.
They are available under a BSD license.
Installation
Releases of line_profiler can be installed using pip:
$ pip install line_profiler
Current releases require Python 3.10 or newer. Older Python versions require older line_profiler releases.
Installation while ensuring a compatible IPython version can also be installed using pip:
$ pip install line_profiler[ipython]
Source installs may require a C compiler. Git checkouts also require Cython. Wheels are published for common platforms. If no wheel is available for your platform or Python version, installation may build from source.
Quick Start
The recommended way to use line_profiler is to import profile and enable profiling with the LINE_PROFILE environment variable.
To profile a python script:
Install line_profiler: pip install line_profiler.
In the relevant file(s), import profile and decorate function(s) you want to profile:
from line_profiler import profile @profile def slow_function(): ...Set the environment variable LINE_PROFILE=1 and run your script as normal. When the script ends a summary of profile results, files written to disk, and instructions for inspecting details will be written to stdout.
For more details and a short tutorial see Line Profiler Basic Usage.
Older kernprof workflow
The older kernprof -l workflow is still supported, but it is no longer the main README quick start. See Usage Notes and FAQ for the previous README material covering kernprof, IPython, lower-level API usage, related tools, and FAQ entries.
The short version is:
$ kernprof -lv script_to_profile.py
Documentation
Bugs and Such
Bugs and pull requests can be submitted on GitHub.