Skip to main content

Context-manager based line-by-line profiler for Python functions

Project description

lineprofiler

Statistical profiler to find lines that take a long time to compute. One can specify a folder, wherein the profiler traces lines. The profiler can be bound using with.

Features

  • Zero configuration – just wrap code in a with block
  • Line-level timing – see exactly which lines are slow
  • Auto-filtering – only profiles code in your project (auto-detects git repo root)
  • Flexible output – sort by time, hits, or line number; filter by threshold

Installation

pip install with-line-profiler

Workflow

from lineprofiler import LineProfiler
profiler = LineProfiler(project_folder="path/to/your/project")
profiler.clear()
with profiler:
  your_function()
profiler.print_global_top_stats(min_time_us=0.01, top_n=40)
Method Description
print_stats(min_time_us, top_n_lines, sort_by) Print per-function statistics
print_global_top_stats(top_n, min_time_us, sort_by) Print top N lines across all functions
get_stats() Get raw FunctionStats dictionary
clear() / reset() Clear all collected data

Licence

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

with_line_profiler-0.1.1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

with_line_profiler-0.1.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file with_line_profiler-0.1.1.tar.gz.

File metadata

  • Download URL: with_line_profiler-0.1.1.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for with_line_profiler-0.1.1.tar.gz
Algorithm Hash digest
SHA256 74dc39ed811915cb73621e6f70d01fac0d1df39f7e2b8452bf3673414c593781
MD5 2029f0282963f06d0f9ce1d72368be87
BLAKE2b-256 9ffa0721b02abafd8522249c3c434ef19774e0a48b1067102ec4971a5539ed18

See more details on using hashes here.

File details

Details for the file with_line_profiler-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for with_line_profiler-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec5c6d72766ef419fbbf78edaedd9e3109c5e17be0c10fdac3f6247f35d72e97
MD5 6e2294a0e8f3f523dc74fa5bb0a3f32e
BLAKE2b-256 23c49be4cc566b9c6af63e54416e704dcb58c516f7943289657fa1ff37f0c75e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page