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

The claude.md is partially created from https://github.com/multica-ai/andrej-karpathy-skills/blob/main/CLAUDE.md

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.2.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.2-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: with_line_profiler-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 fe803fa64135bd237b1a7136918795961aefcd9bafcbf0c66f560bba8c45dd4d
MD5 07a2f4781fcca993a08395d9c42d2372
BLAKE2b-256 6ebab68cb45a819846e92b83f9028accebb3ca6c0bfbd9e3883f16e6a3a70819

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for with_line_profiler-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9f889a762cf3b708f066430452c18e716f5300033ec098311010a52687d84e4c
MD5 1c1c6a651a981349859dc91d49e3b426
BLAKE2b-256 bc84f9b9feef5481e867b3fb047fd4e9165134be0f674da58266b3c3d7b16d13

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