skillfed

line-profiler

Line-by-line profiler

line-profiler v5.0.2 3.1M downloads/30d#2,768 on PyPI3,241
Permissive license BSD Active released

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-profiler

uv

uv add line-profiler

poetry

poetry add line-profiler

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: CProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonTopic :: Software Development

Tags

line by line profilingpython performance profilerfunction execution timingcode hotspot detectionkernprof profiling toolpython line profilerstatement level timing
profilingperformance-debuggingkernprof

More Software Development packages