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 lineprofiler

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.0.tar.gz (6.8 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.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: with_line_profiler-0.1.0.tar.gz
  • Upload date:
  • Size: 6.8 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.0.tar.gz
Algorithm Hash digest
SHA256 7382063a13d6a71574759e974eb9d7fc458ab83cd2c9950e5a06e9679f126852
MD5 b30ca83e3f271ca9fbcc2dbff73affd6
BLAKE2b-256 ac1adef684d3d56b5c2f5030c0de45e964e76df5ce6ff66ad980aa5d1c001b85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for with_line_profiler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df0fbe858ae8430953c74b0989d810d9801ea1199558d1fff9b589820452c4b6
MD5 60e76fc0125d341e3c1e6ce67e71b6f0
BLAKE2b-256 b597789eba31ff37d52a6de65ce47b6a88ba63f7d549a0c40fddce599deef1c4

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