Skip to main content

Zero-dependency local Python tracer

Project description

OKernel

OKernel is a lightweight, zero-dependency Python tracing engine designed for education and visualization. It provides a way to inspect the internal execution of Python code, tracking line-by-line progression, function calls, stack depth, and simulated hardware costs.

This package is intended for students and educators who want to understand how Python code interacts with memory and the CPU, or as a local, unlimited alternative to the OKernel web-based simulation.

Features

  • Local Execution: Runs code entirely on your machine without external API calls or Docker.
  • Zero Dependencies: Uses only the Python Standard Library.
  • Bytecode Analysis: Maps Python opcodes to abstract hardware costs (ALU, Memory Read/Write, etc.).
  • Memory Tracking: Monitors object sizes and peak memory usage during execution.
  • Interactive Visualizer: Generates a self-contained HTML file with a step-through debugger interface.
  • Schema Compatible: Produces JSON trace data compatible with the SysCore engine.

Installation

pip install okernel

For local development:

git clone https://github.com/Vaiditya2207/OKernel.git
cd OKernel
pip install -e .

Quick Start

import okernel

code = """
def fibonacci(n):
    if n <= 1:
        return n
    return fibonacci(n-1) + fibonacci(n-2)

result = fibonacci(5)
print(f"Result: {result}")
"""

# Execute and trace
trace = okernel.trace(code)

# View text summary
print(trace.summary())

# Export to interactive HTML
trace.to_html("trace_report.html")

API Reference

okernel.trace(code: str) -> Trace

Executes the provided Python string in an isolated namespace. Tracing includes bytecode opcodes, line numbers, and variable states.

Trace.summary() -> str

Returns a formatted string containing total execution steps, peak memory consumption, and execution duration.

Trace.to_html(path: str)

Generates a standalone HTML visualizer at the specified path. This file includes the step-through timeline, variable inspector, and console output.

Trace.to_json(path: str)

Exports the raw execution event sequence as a JSON file for custom analysis.

Trace.events

A property containing the list of raw event dictionaries. Each event follows the SysCore schema, including bytecode offsets and hardware cost estimations.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

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

Source Distribution

okernel-0.1.3.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

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

okernel-0.1.3-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file okernel-0.1.3.tar.gz.

File metadata

  • Download URL: okernel-0.1.3.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for okernel-0.1.3.tar.gz
Algorithm Hash digest
SHA256 256ddfbc28878e24d74c2987778628f28f2f005a64d65bb767a49fab8db6858c
MD5 2f7942d06149385c5b9f2dde638dcd40
BLAKE2b-256 19133fd8dc41ba7e0f4e4041226ab5104dce20f9868d67b9395aae896b19ddfa

See more details on using hashes here.

File details

Details for the file okernel-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: okernel-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for okernel-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1d5c5689938a562dcd5daaba99e5661aee753f1dbffa64a414fceaf9d9d2d29e
MD5 495318d45cc58418cc2f9a596afad424
BLAKE2b-256 63a273aacffcfbdaa0cdce32d6aaa16a2f3125ebabac4e9fd63a79751bcf2a9a

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