Table of Contents

Profiler for Python

The Python profiler is a decorator-based timing library. It tracks call counts, latency statistics and exceptions, and exports JSON, CSV or HTML. It does not document an API-upload path in the same way as the .NET, Java and Node.js agents, so treat it as an in-process measurement library rather than a production trace-collection agent.

Catalogue status. The Python profiler is present in the profiler.python repository. It is not part of the public profiler catalogue. The website's profiler catalogue intentionally excludes Python; do not present it as a published, installable agent.

Install

pip install reignite-profiler

Or add the profiler package directory to your project.

Use

from profiler import profile, get_session, JsonExporter

@profile
def calculate_fibonacci(n):
    if n <= 1:
        return n
    return calculate_fibonacci(n - 1) + calculate_fibonacci(n - 2)

@profile
def process_data(items):
    return [item * 2 for item in items]

fib_result = calculate_fibonacci(10)
data = process_data([1, 2, 3, 4, 5])

session = get_session()
JsonExporter.export_session(session, "profiling_results.json")

Async functions

from profiler import profile_async
import asyncio

@profile_async
async def fetch_data(url):
    await asyncio.sleep(0.1)
    return f"Data from {url}"

Sessions

from profiler import start_session, end_session

start_session("checkout")
run_checkout()
session = end_session()
print(f"Total calls: {session.total_calls}")
print(f"Duration: {session.duration_seconds:.2f}s")

Statistics

For each profiled method the session exposes call count, average, median, minimum, maximum, standard deviation and exception count:

session = get_session()
for name, profile in session.method_profiles.items():
    print(f"{name}: {profile.call_count} calls, "
          f"{profile.average_duration_ms:.2f} ms average")

Export

Exporter Output
JsonExporter JSON, with to_json_string for in-memory use
CsvExporter CSV
HtmlExporter A standalone, sortable HTML report

Limitations

  • Timing is taken in-process and is subject to Python's GIL. It is appropriate for application-level timing (business logic, API calls, database queries), not for micro-benchmarking or GIL-contention analysis.
  • For GIL-free profiling or micro-benchmarking, use cProfile or py-spy.
  • Disable the profiler in production with disable_profiling() or enabled=False unless you have a specific reason to keep it on.