Skip to main content

A Python script profiler using @profile decorators

Project description

Line Profiler Extension for Python (lprof_ext)

lprof_ext is a lightweight Python script profiler that seamlessly integrates with the line_profiler library. It simplifies performance analysis by automatically adding @profile decorators to your Python code and collecting detailed line-by-line performance statistics. This tool is ideal for developers looking to identify bottlenecks and optimize their Python scripts efficiently.

Features

  • Automatic Profiling: Adds @profile decorators to your code without manual intervention.
  • Line-by-Line Analysis: Leverages line_profiler to provide granular performance metrics for each line of code.
  • Easy Integration: Works with any Python script via a simple command-line interface.
  • Lightweight: Minimal dependencies and straightforward setup.
  • Open Source: Freely available for contributions and customization.

Installation

From PyPI

Install the latest stable version of lprof_ext using pip:

pip3 install --no-cache-dir lprof_ext

Prerequisites

  • Python 3.8 or higher
  • line_profiler (automatically installed as a dependency)

Usage

To profile a Python script, run the following command, replacing <entrypoint.py> with the path to your script:

# [Important] - You must run at project root for *.py file scanning.
lprof_ext <entrypoint.py>

Example

Suppose you have a script named example.py:

def compute_fibonacci(n):
    if n <= 1:
        return n
    return compute_fibonacci(n-1) + compute_fibonacci(n-2)

def main():
    result = compute_fibonacci(30)
    print(f"Result: {result}")

if __name__ == "__main__":
    main()

Run the profiler:

lprof_ext example.py

After execution, lprof_ext will output performance statistics into profile.json, showing execution time, number of calls, and percentage of time spent on each line of code in the profiled functions.

Output

The output will be store in JSON format. You can visualize it using our GUI tool prof_gui

docker run --rm -d --name prof_gui \
           -v ./profile.json:/profile.json \
           -p 8080:8080 \
           ruprof/prof_gui:rs

Build from Source

If you prefer to build lprof_ext from source (e.g., to use the latest development version or contribute), follow these steps:

  1. Clone the repository (replace with the actual URL):
git clone https://github.com/RuProf/lprof_ext
cd lprof_ext
  1. Set up a virtual environment (optional but recommended):
python3 -m venv .venv
source .venv/bin/activate
  1. Install dependencies and build the package using uv (or pip if uv is unavailable):
uv sync
pip3 install .
  1. Verify the installation:
lprof_ext -h

Requirements for Building

  • uv (optional, for dependency management; install via pip install uv)
  • setuptools and wheel (for building the package)

Reference

lprof_ext is built on top of the excellent line_profiler library. For more details on how line-by-line profiling works, refer to the official documentation:

line_profiler

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

lprof_ext-0.1.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

lprof_ext-0.1.1-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lprof_ext-0.1.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for lprof_ext-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c17711bdea6a464e9adbe498d837fad742ea926aede35a94e18eb577d5c89e04
MD5 4e35a5c44bd1c5f9c7e6d5238a7326f7
BLAKE2b-256 1ff99b62907b80b15fe25fdaa57587f4f96ccac5dc9dfafcc0492e1dac0166b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: lprof_ext-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for lprof_ext-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 efe47c082834d72f505c10669cb1c09348c035d33fcbcf37fb72d99b20954dd7
MD5 da099177f486a596028ea1f172765616
BLAKE2b-256 50b05c38a99087f98ea3d7278a243041335045c995675b6f6a7ddc567790a472

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