Skip to main content

Enhanced exception analysis library for Python - prints detailed information about what happened when an exception occurs

Project description

Lunacept

Lunacept is an enhanced exception analysis library for Python. It automatically instruments your code to capture and display the values of intermediate expressions when an exception occurs, making debugging significantly easier.

Instead of just telling you where an error happened, Lunacept tells you why by showing you the runtime values of every part of the failing expression.

Lunacept Example

Highlights

  • Show the values of all sub-expressions at the exact position (line and column) that caused the exception.

  • Easy to use - no need to modify your existing code.

  • Low Overhead, benchmark results show overhead between 1.1x and 1.4x:

Installation

pip install lunacept

Usage

Inline

Add one of the following to the beginning of your entry file:

import lunacept; lunacept.install()

Or, you can use the autoinstall module to install lunacept automatically:

from lunacept import autoinstall

Command Line Interface

You can run your script using lunacept instead of python:

lunacept my_script.py arg1 arg2

Decorator

You can also use the @capture_exceptions decorator to mark specific functions or classes for instrumentation:

from lunacept import luna_capture

@luna_capture
def my_function():
    ...

If you want to disable global instrumentation and only instrument marked targets:

import lunacept

lunacept.configure(global_install=False)
lunacept.install()

How It Works

Lunacept uses Python's ast (Abstract Syntax Tree) module to parse and transform your code at runtime. It breaks down complex expressions into temporary variable assignments, allowing it to track the value of each sub-expression individually. When an exception occurs, Lunacept uses these captured values to generate a detailed report.

Performance

Lunacept is designed to be lightweight, but since it instruments code at runtime, there is some overhead. Below are benchmark results comparing standard execution vs. Lunacept instrumentation (MacBook Pro, Apple M1, 16GB RAM):

Test Case Baseline Instrumented Slowdown
Simple Math (Arithmetic Loop) 0.052 ms 0.068 ms 1.3x
Recursive Fib (Function Calls) 0.062 ms 0.089 ms 1.4x
Complex Logic (Branching) 0.049 ms 0.056 ms 1.1x

The overhead is generally between 1.1x and 1.4x

License

This project is licensed under the MIT License.

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

lunacept-0.5.4.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

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

lunacept-0.5.4-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file lunacept-0.5.4.tar.gz.

File metadata

  • Download URL: lunacept-0.5.4.tar.gz
  • Upload date:
  • Size: 20.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for lunacept-0.5.4.tar.gz
Algorithm Hash digest
SHA256 d17a105750addc4aace655780f921079b8a4d870f341da02579a876140a1ec50
MD5 4777b8293ff7080a0f5032f3ae64d374
BLAKE2b-256 8d0b382641a405e55e1ae07bc91b14b802c1dfc28accde1f2a9ec3ed789a4f6f

See more details on using hashes here.

File details

Details for the file lunacept-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: lunacept-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for lunacept-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 04e02a9c1cb88eb1457f981ad798d9dfa9d33225e448b1d50c196609659e4778
MD5 3b82fb0e971403264e3e081cc501f835
BLAKE2b-256 8fc973882ecc33c95d393c859c8a00b149940bf1629726f88194e1b103892400

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