Skip to main content

A beautiful profiler for Python projects with various options

Project description

Profiler Cub 🐻

pypi version

A beautiful Python code profiling library with rich terminal visualizations. Profile your code, categorize by layers, analyze dependencies, and get gorgeous color-coded performance reports.

Features

  • 🎨 Beautiful Rich Visualizations - Color-coded tables with performance gradients
  • 📊 Layer-based Categorization - Organize code into logical layers (Core, API, Database, etc.)
  • 🔍 Dependency Analysis - See exactly how much time external libraries consume
  • ⏱️ Import vs Runtime Tracking - Separate module load time from execution time
  • 🎯 Filtering & Sorting - Multiple sort modes and threshold filtering
  • 🔄 Multiple Iterations - Run workloads multiple times for stable measurements

Installation

pip install profiler-cub

With uv:

uv tool install profiler-cub

Quick Start

from pathlib import Path
from profiler_cub.core import CodeProfiler
from profiler_cub.display import display_all
from funcy_bear.tools.gradient import ColorGradient

# Create profiler
profiler = CodeProfiler(
    pkg_name="my_package",
    threshold_ms=0.5,  # Filter functions below 0.5ms
)

# Profile your code
def my_workload():
    # Your code here
    pass

profiler.run(my_workload, stats_file=Path("profile.stats"))

# Display beautiful results
gradient = ColorGradient(start_color="#00ff00", end_color="#ff0000")
display_all(profiler, color_gradient=gradient)

Layer-Based Profiling

Organize your code into logical layers for better insights:

profiler = CodeProfiler(
    pkg_name="my_app",
    module_map={
        "Database": {"db/", "models/"},
        "API": {"api/", "routes/"},
        "Core": {"core/", "engine/"},
    }
)

The profiler will categorize each function by its filepath and show aggregated stats per layer.

Examples

Check out the examples/ directory for complete examples:

  • simple_example.py - Minimal setup, get started quickly
  • profile_example.py - Full-featured with CLI args, setup/teardown, iterations

See examples/README.md for detailed usage.

Documentation

For comprehensive documentation, see CLAUDE.md which includes:

  • Complete architecture overview
  • All configuration options
  • Key concepts (layers, sort modes, thresholds, etc.)
  • Real-world usage patterns

Development

# Install dependencies
uv sync

# Run tests
nox -s tests

# Run linting
nox -s ruff_fix

# Run type checking
nox -s pyright

License

MIT

Credits

Created by Bear 🐻 with love for performance analysis.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

profiler_cub-0.0.10-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

Details for the file profiler_cub-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: profiler_cub-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 25.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for profiler_cub-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 31061a285c4764cb146e7c5a9635488a3a7f846da5589b6262b19731012d1503
MD5 06f68ee6138fa7e7abde39c5d018eada
BLAKE2b-256 15fc212e7e7baea2a83e74ed8d57ead72e785432f4113a7f252ff6d1b7532ed4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page