scope-profiler
Profile Python code regions—and optionally C, Fortran, MPI, NVTX, and LIKWID—with one consistent API and HDF5 output format.
pip install scope-profiler
Quick start
import scope_profiler as sp
with sp.session():
@sp.profile("main")
def main():
with sp.region("work"):
sum(range(100)) # replace with the code you want to measure
main()
# writes profiling_data.h5 and prints a summary
session, region, profile, setup and finalize are the everyday
calls, importable from the package root. They are ProfileManager class
methods acting on the process-wide default manager, so the two spellings
are interchangeable:
from scope_profiler import ProfileManager
with ProfileManager.session():
with ProfileManager.region("work"):
...
For a script that already has regions, the CLI owns the profiling lifecycle:
import scope_profiler as sp
@sp.profile("main")
def main():
with sp.region("iteration"):
work()
main()
Run it through Scope Profiler to collect those regions and finalize the output:
scope-profiler run app.py
Running the same file with python app.py leaves profiling disabled and
creates no output file. Existing session(), setup(), and
finalize() workflows remain available when application code needs
direct lifecycle control.
See the quickstart and profiling modes guide for recursive tracing, tags, concurrency, output formats, and advanced APIs.
Profile a pytest suite
The installed package provides an opt-in pytest plugin. It records one region for every selected test, named from its pytest node id, so the normal post-processing commands can show which tests consume the suite’s time:
pytest --scope-profile --scope-profile-out pytest-profile.h5
scope-profiler inspect pytest-profile.h5 --regions-only --sort total
scope-profiler plot durations pytest-profile.h5 -o pytest-plots
By default it measures only each test’s call phase. Include fixture
setup and teardown when those are relevant to the investigation:
pytest --scope-profile --scope-profile-phases=all
The plugin uses its own profiling manager, so tests that call
ProfileManager.setup() or ProfileManager.finalize() remain isolated.
The result measures complete test phases; it does not recursively trace
every function pytest calls. Existing application-level Scope Profiler
regions are therefore best collected in a dedicated application run when
detailed function-level attribution is needed. With pytest-xdist, the
plugin cannot yet be used: its workers must not write the same HDF5
file.
See the profiling modes guide for output formats, filtering, concurrency, aggregation, pause/resume, and sampling.
In a notebook
Install the notebook extra and see the notebook magics guide for cell profiling, recursive tracing, comparisons, and exports:
pip install "scope-profiler[notebook]"
Documentation
- Installation
- Quick start
- Python API and post-processing
- CLI reference
- Plotly figures for the web
- Configuration and profiling regions
- MPI, C, and Fortran
- LIKWID, line profiling, and MCP
- Jupyter/IPython magics
- Example notebooks
- Examples
Build the documentation locally
The hosted documentation is an Astro +
Starlight site in docs/, set up with
the shared starlight-theme.
It needs Node 22 or newer, an MPI implementation (mpirun) for the MPI
examples, and the docs extra:
python -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
make docs-install
make docs-build
This executes the tutorial notebooks, refreshes the generated command
output and builds the site into docs/dist; make docs-dev serves a live
preview at http://localhost:4321/scope-profiler/. The GitHub Pages
workflow runs the same steps. See the docs page on building the
docs for
the details.
Development
pip install -e '.[dev]'
pytest
See AGENTS.md for the measured benchmark workflow used when optimizing this project.
Metadata
Release files for scope-profiler 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| scope_profiler-0.8.0.tar.gz | 716.0 kB | With provenance | Details for scope_profiler-0.8.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| scope_profiler-0.8.0-py3-none-any.whl | Python 3 | none | any | Details for scope_profiler-0.8.0-py3-none-any.whl |
Total release size: 1.5 MB
Release files / scope_profiler-0.8.0.tar.gz
| Download URL | scope_profiler-0.8.0.tar.gz |
|---|---|
| Size | 716.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f98981f5d242acf6d03b889b66bb5c8675eac91e6310e3dc32a4c6033f910b20
|
|
BLAKE2b-256 checksum How to use checksums |
05b64f69a3931880682288813e98cc695a2008a7eba65f18404dd60687bba8f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logRelease files / scope_profiler-0.8.0-py3-none-any.whl
| Download URL | scope_profiler-0.8.0-py3-none-any.whl |
|---|---|
| Size | 800.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5b0d4e728a409a014a49ac2a30902917c8f13ba4bda6b6e7a665595ec7e11332
|
|
BLAKE2b-256 checksum How to use checksums |
a36e4c9be169dad5d2cdca3001ab4ea6a7ea4445e2672a972b5e092b38037668
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logSecurity for scope-profiler 0.8.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for scope_profiler-0.8.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.
Transparency logA 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.