Skip to main content

eprofiler

A lightweight, zero-dependency toolkit to monitor execution of functions or code blocks.

PyPI Build Status License Documentation

eprofiler provides decorators and context managers to observe execution time, cpu time, peak memory and arguments used for a function.

for a function or code block you can monitor and log;

  • execution time
  • peak memory usage
  • CPU time
  • parameters passed to a function

Installation

pip install eprofiler

Core Tools

  • @audit: Execution logging with SUCCESS/FAIL status and error capturing.
  • @timeit: Execution timing (microsecond precision).
  • @memit: Tracks current and peak memory usage.
  • @profile: The "All-in-One": Wall time, CPU time, and Memory.
  • @profile_cpu: User vs System time (Unix) & Efficiency %.
  • Timer: Context manager and/or decorator for granular blocks.

Usage

1. Function Auditing (@audit)

Good for monitoring what parameters are passed to a function/method. where you need to know if a function finished, how long it took, and why it failed and with which parameters.

⚠ Warning:
if parameters passed to function are not printable like str, int or a python object without __str__ or __repr__ that can be used in fstrings its better to use callback to handle them in logging

from eprofiler import audit

@audit(label="Audit", include_args=True)
def create_user(username, email):
    return f"User {username} created."

Output:

INFO: {'timestamp': '2026-03-05T18:33:37.651931', 'function': 'create_user', 'label': 'Audit', 'args': ('jdoe', 'jane@example.com'), 'kwargs': {}, 'status': 'SUCCESS', 'elapsed_seconds': '0.000003'}

2. Basic Timing (@timeit)

For quick performance checks during development. By default, results are printed to the console.

from eprofiler import timeit

@timeit(label="Computation")
def my_func():
    return sum(i**2 for i in range(100000))

my_func()

Output:

{'label': 'Computation', 'function': 'my_func', 'duration': '0.000074'}

3. Comprehensive Profiling (@profile & @profile_cpu)

Track wall-clock time, actual CPU usage, and memory (current and peak) simultaneously.

from eprofiler import profile, profile_cpu

# Standard profile (Wall Time + CPU Time + Memory)
@profile(label="Data Batch")
def process_data():
    return [x for x in range(1000000)]

# CPU profile (User/System breakdown + Efficiency)
@profile_cpu(label="Heavy Computation")
def compute_pi():
    return sum(1/i**2 for i in range(1, 1000000))

process_data()
compute_pi()

Output:

{'label': 'Data Batch', 'function': 'process_data', 'duration': '0.241128', 'cpu_time': '0.241104', 'peak': 40440488, 'current': 40440448}

{'label': 'Heavy Computation', 'function': 'compute_pi', 'user_time': '0.048526', 'system_time': '0.000074', 'cpu_time': '0.048600', 'duration': '0.048610', 'efficiency': '99.98%'}

4. Using Callback

Instead of printing to the console, you can pass a callback function to any decorator to handle the results programmatically (e.g., sending metrics to a database, Slack, or a logging service).

from eprofiler import profile_cpu

def metrics_handler(stats):
    """Custom function to process profiling data."""
    # Send to Datadog, CloudWatch, or an ELK stack
    print(f"TELEMETRY: {stats['function']} ran with {stats['efficiency']} efficiency.")

@profile_cpu(label="Production_Task", callback=metrics_handler)
def sync_data():
    # Logic here...
    return "Done"

sync_data()

Using your own metrics_handler you can do anything you want with stats.

5. Timer class for codeblocks

Timer can be used as a decoator, or can be used for code blocks for part of a function rather than whole function Note that Timer class does not have a callback

from eprofiler import Timer
import time

# Use as a Context Manager
with Timer(label="External API Call") as t:
    time.sleep(0.5)  # Simulate a network delay

print(f"Result: {t.stats['label']} took {t.stats['duration']:.6f}s")

# Also works as a decorator for simple timing
@Timer(label="Quick Check")
def short_task():
    pass

Links


Metadata

Release files for eprofiler 0.1.0

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

Source distribution (sdist)

Source distribution for eprofiler 0.1.0
File Size Uploaded
eprofiler-0.1.0.tar.gz 10.5 kB Details

Built distribution (wheel)

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

Total release size: 19.3 kB

Release files / eprofiler-0.1.0.tar.gz

Download URL eprofiler-0.1.0.tar.gz
Size 10.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d7fbeee58f9d6465d37df2f8ae834497531145910796f54142b202df3f9cfc76
BLAKE2b-256 checksum
How to use checksums
3abfb68b2cdbceb87a4f0828a895acaafbe486ef85399f8813e4f60d195aa3ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / eprofiler-0.1.0-py3-none-any.whl

Download URL eprofiler-0.1.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd43831cea3ade7c76fb346d43496f2880910ef4dfa4ff186d40ec9debb48a9a
BLAKE2b-256 checksum
How to use checksums
a2e70715228d5943fedb9f5604696c6c2d731d8fa5a47bfb399fd2f214d4cb7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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