An intelligent, lightweight Wall/CPU time and memory profiler with beautiful terminal reports.
Project description
PyVitals
PyVitals is an intelligent, lightweight performance profiler for Python. It tracks Wall Time, CPU Time, and Peak Memory usage with surgical precision, generating beautiful terminal reports and JSON history logs.
Whether you are debugging a slow API or hunting down a memory leak, PyVitals tells you exactly if your code is CPU Bound or I/O Bound.
Features
- Universal: Works seamlessly with both synchronous (
def) and asynchronous (async def) functions. - Flexible: Use it as a
@decoratoror as awithcontext manager for specific code blocks. - Smart Diagnostics: Automatically calculates CPU vs. Wall Time to detect I/O or CPU bottlenecks.
- Threshold Alerts: Set limits for execution time or memory and get visual warnings if exceeded.
- Zero-Overhead Production: Built-in Kill-Switch environment variable to disable tracking instantly in production.
- CLI Analyzer: Export your metrics to JSON and use the built-in CLI tool to track performance regressions over time.
Installation
Install via pip:
pip install pyvitals-profiler
Quickstart
- As a Decorator (Sync & Async) Simply add @track() to any function you want to profile.
import asyncio
from pyvitals import track
@track(name="Database Query", max_time_s=1.5)
async def fetch_users():
await asyncio.sleep(1.0) # Simulating I/O Wait
return {"status": "success"}
asyncio.run(fetch_users())
- As a Context Manager If you only want to profile a specific loop without decorating the whole function, use the with statement.
from pyvitals import track
def process_heavy_data():
print("Initializing...")
# Only profile this specific block
with track(name="Matrix Math", max_mem_mb=50):
data = [x**2 for x in range(1_000_000)]
print("Done!")
process_heavy_data()
Exporting & Analyzing Data (CLI)
PyVitals allows you to save your performance history to detect regressions.
Step 1: Export to JSON Use the export_to parameter. You can also use quiet=True to hide the terminal output if you are running the function thousands of times.
from pyvitals import track
@track(export_to="vitals_history.json", quiet=True)
def background_task():
# ... task logic ...
pass
Step 2: Use the CLI Analyzer PyVitals comes with a built-in command-line tool. Point it to your JSON file to generate a rich historical trend analysis table:
pyvitals vitals_history.json
The CLI will display the average Wall/CPU time, the maximum peak memory, the workload profile (I/O vs CPU), and highlight performance regressions (e.g., ▲ +12.5% slower).
Production Kill-Switch
You don't need to remove all your @track decorators before deploying to production. Set the following environment variable to 0 to instantly disable PyVitals. It will bypass the tracking logic entirely, ensuring 0ms performance overhead.
export PYVITALS_ENABLED=0
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Clone the repository.
Install dependencies: pip install -e .
Run tests: pytest
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyvitals_profiler-1.0.0.tar.gz.
File metadata
- Download URL: pyvitals_profiler-1.0.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0f694d544a997f4237ce68f3f8505c3d324f85b9e132c285f375ab96527c8c4
|
|
| MD5 |
538aa5a97f94a989d0147e7624ae9b79
|
|
| BLAKE2b-256 |
2a401e48024f737b182a290b380dd254ff9cb9f57b880239114a9b1140b72837
|
File details
Details for the file pyvitals_profiler-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyvitals_profiler-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcca667454ac21a1b7e25422c3aff601dd4fe327cf5bbdaba6e88d31319aa2c5
|
|
| MD5 |
96fc70c17bb9ae15f6a69da267a72fa9
|
|
| BLAKE2b-256 |
18570618444809e9699d78731414fadfefebca4bdbc9b8b786b0bbd228170a1e
|