Skip to main content

pylaprof

pylaprof is a Python library that allows you to profile functions or sections of code.

As a decorator:

from pylaprof import profile

@profile()
def handler(event, context):
  ...

As a context manager:

from pylaprof import Profiler

def main():
  ...
  with Profiler():
    # Only code inside this context will be profiled.
    ...

It is built around three main abstractions: the profiler, the sampler, and the storer.

The profiler is the main component of pylaprof, it takes care of taking snapshots of your program's stack at regular intervals and feeding them to the sampler for processing; at the end of the profiling session, it will then ask the sampler for a report and provide it to the storer.

Take a look at the source for more documentation and some pre-implemented samplers and storers or here for some usage examples.

Features

  • Accessible: pylaprof's code is thoroughly documented and written to be read and understood by other humans.

  • Extensible: you can write your own sampler or storer to generate reports in the format you like and store them where and how you want.

  • Zero external dependencies1.

  • Close to zero impact on performances (check benchmark for more details).

  • Reliable: pylaprof was built with the context of long-running applications or continuously invoked lambda functions in mind. It will never break your code or pollute your standard output or error with unwanted messages.

  • Turn on/off profiling with an environment variable.

  • Store the profiling report only if execution takes longer than a threshold.

pylaprof-merge

pylaprof-merge is a CLI tool to merge multiple stackcollapse reports into a single one. This might come in handy if you want to get an aggregated overview of a function or piece of code that is executed frequently for short periods. It is installed automatically if you get pylaprof with pip.

Installation

pip install pylaprof

Or just copy-paste the pylaprof directory where you need it.

Credits

  • This library is heavily inspired to pprofile: thanks to its authors for writing such accessible and well-documented code.
  • Thanks to @jvns for writing and distributing some of her wizard zines for free: that's what got me into the rabbit hole of profiling in the first place.
  1. boto3 is optional and required only if you want to use the S3 storer. ↩

Metadata

Release files for pylaprof 0.4.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylaprof 0.4.6
File Size Uploaded Provenance Actions
pylaprof-0.4.6.tar.gz 6.5 kB Without provenance Details for pylaprof-0.4.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pylaprof 0.4.6
File Interpreter ABI Platform Actions
pylaprof-0.4.6-py3-none-any.whl Python 3 none any Details for pylaprof-0.4.6-py3-none-any.whl

Total release size: 13.2 kB

Release files / pylaprof-0.4.6.tar.gz

Download URL pylaprof-0.4.6.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9448929e218b3a2d63bb6ef13d36481f93d529f14ab11eff89c2e3afa6bf574d
BLAKE2b-256 checksum
How to use checksums
cd46256bc2e69ece84b0b75253a240df54cbce17bffaeea035952e2a620eec1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.7.12 Linux/5.11.0-1028-azure

Release files / pylaprof-0.4.6-py3-none-any.whl

Download URL pylaprof-0.4.6-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3308f00d9889c6070f758ac254c1d8548056646ef8438bee98130963d1a37249
BLAKE2b-256 checksum
How to use checksums
fddaf1eec61ffc32cc9665b073658433eb50fb2d52db0113428b1c60ea0390ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.7.12 Linux/5.11.0-1028-azure

Security for pylaprof 0.4.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page