A lightweight Python module designed for straightforward function tracing
Project description
Seshat: A Simple Python Function Tracer
Seshat is a lightweight Python module designed for straightforward function tracing. It logs function calls, arguments, keyword arguments, and return values, making it easy to understand the flow of your code. Seshat also provides a simple proxy class to record READ/WRITE access to object attributes.
Installation
Seshat is a pure python module. Just place the seshat directory in your project and import it.
Usage
Tracing
To trace a function, simply decorate it with @seshat.record:
from seshat import seshat
@seshat.record
def my_function(a, b, c):
result = a + b + c
return result
my_function(1, 2, 3)
This will print the following output to the console:
2024-03-08 10:00:00.000000 [FUNC] [__main__] [ <module> >> my_function() ]
args:
(1, 2, 3)
return:
6
Seshat handles keyword arguments and multiple return values. You can decorate nested function calls, generators, even async functions.
Object Proxy
Seshat provides an object proxy to observe all attribute READ and WRITE activity.
from seshat import seshat
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
print("Woof!")
buddy = Dog("Buddy")
# Create a proxy for the Dog object
buddy = seshat.proxy(buddy)
# Accessing attributes through the proxy will be logged
print(buddy.name) # Logs the read operation
buddy.name = "Max" # Logs the write operation
buddy.bark() # Calls the original bark method (also logged)
This will print the following output to the console:
2024-03-08 10:00:00.000000 [READ] [__main__] [ <module> >> buddy.name ]
2024-03-08 10:00:00.000000 [WRITE] [__main__] [ <module> >> buddy.name ]
2024-03-08 10:00:00.000000 [CALL] [__main__] [ <module> >> buddy.bark() ]
Logging Messages
You can add custom log messages using seshat.info, seshat.warn, and seshat.error:
from seshat import seshat
def my_function():
seshat.info("Starting the function")
# ... some code ...
seshat.warn("Something might be wrong")
# ... more code ...
seshat.error("An error occurred")
Optionally, you can log mesaages to a file by calling seshat.save_log("seshat.log") before running your code.
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 seshat_trace-0.1.0.tar.gz.
File metadata
- Download URL: seshat_trace-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4458707371498e2f02d751e05ef2f155618df35735b38d2be0b9f6cafd2788f
|
|
| MD5 |
f42b01e07b5fcd8f89fb82f820d37445
|
|
| BLAKE2b-256 |
22497bb9c86aa76643a43a4117cef93c047877e564594a008d02392bc0c5a179
|
File details
Details for the file seshat_trace-0.1.0-py3-none-any.whl.
File metadata
- Download URL: seshat_trace-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35c1c3b98c5176ea3d56c915e24fd47e015d6119c872edfc1fee7a05d7d77f07
|
|
| MD5 |
7996f0ece7238387f771f8f26a977227
|
|
| BLAKE2b-256 |
dd1dcda42a903dc3b82ddb2621af878042a02dae33c636a3d50101c8ed90cbba
|