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 | https://github.com/pyutils/line_profiler |
| Pypi | https://pypi.org/project/line_profiler |
| ReadTheDocs | https://kernprof.readthedocs.io/en/latest/ |
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.
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.
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
profileand decorate function(s) you want to profile:from line_profiler import profile @profile def slow_function(): ...Set the environment variable
LINE_PROFILE=1and 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.
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
Bugs and pull requests can be submitted on GitHub.