line-profiler
Line-by-line profiler
What it is and what it does
line_profiler is a Python profiling module that measures execution time at the individual line level within decorated functions, complementing Python's standard cProfile which only times explicit function calls. This is particularly useful for identifying performance bottlenecks in scientific computing or data-heavy code where a single statement (like a NumPy array operation) can dominate runtime without appearing as a function call.
The package provides two main interfaces: the line_profiler module itself, which can be imported and used programmatically with the @line_profiler.profile decorator, and kernprof, a command-line script that automates profiling workflows. Modern versions (4.1.0+) support environment-variable-based activation via LINE_PROFILE=1, while legacy workflows use the kernprof command directly. Results are written to .lprof binary files and can be inspected via the command line or Python module.
Use it for:
- Identify which lines in a NumPy-heavy function consume the most time when function-level profiling shows only a single call.
- Optimize data processing pipelines by pinpointing slow statements in tight loops that cProfile would not break down.
- Debug performance regressions in scientific computing code by comparing line-level timings before and after changes.
- Profile web request handlers or batch jobs to find unexpectedly slow operations within a single function.
- Validate algorithmic improvements by measuring per-line execution time changes in critical functions.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
line_profiler measures execution time on a per-line basis within Python functions, helping identify performance bottlenecks that function-level profilers miss.
Yes. line_profiler is actively maintained, has no known vulnerabilities, runs on modern Python versions (3.8–3.14), and solves a real problem that standard profilers do not: identifying slow individual statements. Install friction is moderate but manageable via prebuilt wheels. The BSD license imposes no restrictions. It is a standard tool in the Python performance-debugging toolkit.
Install
line-profiler on PyPI
pip
pip install line-profileruv
uv add line-profilerpoetry
poetry add line-profilerInstalling line-profiler
Before you install
Medium install friction due to C extension compilation, but prebuilt wheels are available for Python 3.8–3.14 on major platforms (Linux, macOS, Windows). The package is actively maintained with a recent release and no known vulnerabilities.
License in practice
BSD license is permissive and places no significant restrictions on use, modification, or distribution in proprietary or open-source projects.
Quickstart
pip install line_profiler
import line_profiler
@line_profiler.profile
def my_function():
pass
# Set LINE_PROFILE=1 environment variable and run your script
C compiler required when building from source; prebuilt wheels avoid this for standard Python versions on common platforms.
Verify before relying
- Whether the package works with Python 3.13 and 3.14 in practice, given classifiers list them but the description's version history may predate their release.
Package facts
| License | BSD (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | 2 — tomli, typing_extensions |
| Maintenance | actively maintained — 172 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,069,356/month — #2,768 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: line_profiler-5.0.2-cp310-cp310-macosx_10_9_universal2.whl; line_profiler-5.0.2-cp310-cp310-macosx_10_9_x86_64.whl; line_profiler-5.0.2-cp310-cp310-macosx_11_0_arm64.whl; line_profiler-5.0.2-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; line_profiler-5.0.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; line_profiler-5.0.2-cp310-cp310-musllinux_1_2_aarch64.whl; line_profiler-5.0.2-cp310-cp310-musllinux_1_2_x86_64.whl; line_profiler-5.0.2-cp310-cp310-win_amd64.whl; line_profiler-5.0.2-cp311-cp311-macosx_10_9_universal2.whl; line_profiler-5.0.2-cp311-cp311-macosx_10_9_x86_64.whl; line_profiler-5.0.2-cp311-cp311-macosx_11_0_arm64.whl; line_profiler-5.0.2-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl; line_profiler-5.0.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl; line_profiler-5.0.2-cp311-cp311-musllinux_1_2_aarch64.whl; line_profiler-5.0.2-cp311-cp311-musllinux_1_2_x86_64.whl; line_profiler-5.0.2-cp311-cp311-win_amd64.whl; line_profiler-5.0.2-cp311-cp311-win_arm64.whl; line_profiler-5.0.2-cp312-cp312-macosx_10_13_universal2.whl; line_profiler-5.0.2-cp312-cp312-macosx_10_13_x86_64.whl; line_profiler-5.0.2-cp312-cp312-macosx_11_0_arm64.whl
Keywords: timing, timer, profiling, profiler, line_profiler
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
ipython-autotimeIPython extension that automatically measures…
permissive · top 15,000 on PyPI
memory-profilerProfiles memory consumption line-by-line in…
permissive · top 5,000 on PyPI
pyinstrumentPyinstrument is a statistical call-stack…
permissive · top 5,000 on PyPI
yappiYappi is a deterministic profiler for Python…
permissive · top 5,000 on PyPI
scaleneScalene profiles Python code to measure CPU,…
permissive · top 15,000 on PyPI
pyprof2calltreeConverts Python cProfile profiling data into…
permissive · top 15,000 on PyPI
tunatuna visualizes Python performance profiles in…
copyleft · top 15,000 on PyPI
viztracerVizTracer traces Python code execution and…
permissive · top 5,000 on PyPI
django-cprofile-middlewareMiddleware that profiles Django view execution…
permissive · top 15,000 on PyPI
codetimingMeasures elapsed time in Python code using a…
permissive · top 5,000 on PyPI