keke
raw JSON → 0.2.0 verified Sat May 09 auth: no python
A lightweight Python library for easy profiling in Chrome trace format (about: tracing). Version 0.2.0 supports sync/async, generators, automatic trace saving, and stats threads. Maintenance-oriented, with occasional updates.
pip install keke Common errors
error TypeError: Object of type YourObject is not JSON serializable ↓
cause Passing non-JSON-serializable objects as `args` to ktrace.
fix
Convert args to JSON-serializable types, e.g.,
args={'id': myobj.id}. error AttributeError: module 'keke' has no attribute 'ktrace' ↓
cause Incorrect import: using `import keke` and then `keke.ktrace` may fail if the module top-level doesn't expose it (but it does in recent versions). Alternatively, using an older keke version (<0.2.0) where ktrace was named differently.
fix
Use
from keke import ktrace. If using pre-0.2.0, ktrace was keketrace? Actually always use from keke import ktrace. Warnings
breaking In v0.2.0, `ktrace` now supports async functions and generators, but the internal trace format changed. Old trace analysis scripts may break if they relied on specific internal attribute names. ↓
fix Update any custom trace format parsing to expect the new schema (see GitHub changelog).
gotcha By default, keke does NOT save trace files unless `TraceConfig` is configured with `output_dir`. Users often expect traces to appear automatically, but they won't. ↓
fix Set `TraceConfig(enabled=True, output_dir='/path/to/traces')` at startup, or set environment variable `KEKE_OUTPUT_DIR`.
gotcha Arguments passed to `ktrace` as `args` must be JSON-serializable. Non-serializable values will cause runtime errors. ↓
fix Ensure args are basic types (str, int, list, dict) that can be json.dumps'd.
Imports
- ktrace
from keke import ktrace - TraceConfig
from keke import TraceConfig
Quickstart
from keke import ktrace, TraceConfig
import time
# Basic usage: decorate function
@ktrace
def my_function():
time.sleep(0.5)
my_function()
# Context manager usage
with ktrace('my_block', args={'key': 'value'}):
time.sleep(0.3)
# Auto-save configuration (optional)
import os
TraceConfig(enabled=True, output_dir=os.environ.get('TRACE_DIR', './traces')).apply()