--- id: line-profiler version: "5.0.2" license: BSD license_treatment: permissive maintenance: active --- # line-profiler — Line-by-line profiler License: permissive · Maintenance: active · Downloads: 3.1M/mo ## 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 above — 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 pip install line-profiler uv add line-profiler 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_current - Install friction: medium - Maintenance: active - Downloads: 3.1M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags line by line profiling, python performance profiler, function execution timing, code hotspot detection, kernprof profiling tool, python line profiler, statement level timing, profiling, performance-debugging, kernprof [View on SkillFed](https://skillfed.io/packages/line-profiler) · [View on PyPI](https://pypi.org/project/line-profiler/)