Skip to main content

A tamper-evident auditing ledger with Tsundere philosophy.

Project description

Tundere Ledger 🧐

A tamper-evident auditing ledger with Tsundere philosophy. "It's not like I'm recording this for you or anything!"

Backed by Rust 🦀 for strictness and performance.

Features

  • 🔒 Tamper-Evident: Uses SHA-256 chaining (Blockchain-like structure).
  • 🚀 High Performance: Core logic runs in native Rust.
  • 🐍 Pythonic: Simple @audit_log decorator for easy integration.

Installation

pip install tundere-ledger

Or build from source:

git clone https://github.com/kuruitinoji-sys/tundere_ledger.git
cd tundere_ledger
pip install .

Usage

Basic Example: The "Tsundere" Decorator

Wrap any function to automatically record inputs, outputs, and errors.

from tundere_ledger import audit_log, verify_log

@audit_log(actor_name="Maid_Chan", importance=2.0)
def delete_database(reason):
    print(f"Deleting DB because: {reason}")
    # If this raises an error, it is also recorded immutably.

# Call the function
delete_database("Master spilled coffee")

# Verify log integrity
if verify_log():
    print("Log is clean.")
else:
    print("Log has been TAMPERED with!")

API Reference

@audit_log(actor_name="Unknown", importance=1.0, log_file="tundere_audit.jsonl")

Decorator that automatically records function calls to an audit log.

Parameters:

  • actor_name (str): Identifier of who performed the action. Default: "Unknown"
  • importance (float): Importance level of the action. Used for weighted audit trails. Default: 1.0
  • log_file (str): Path to the audit log file. Must be within the current directory (path traversal protection). Default: "tundere_audit.jsonl"

Recorded Information:

  • Function name
  • Arguments and keyword arguments (converted to strings)
  • Return value (on success)
  • Exception details (on error)
  • Timestamp (RFC3339 format)
  • SHA-256 chain signature

verify_log(log_path="tundere_audit.jsonl") -> bool

Verifies the integrity of an audit log using SHA-256 chaining.

Parameters:

  • log_path (str): Path to the audit log file to verify. Default: "tundere_audit.jsonl"

Returns:

  • True if the log is intact and unmodified
  • False if the log has been tampered with or is corrupted

get_recorder(log_path="tundere_audit.jsonl") -> TundereRecorder

Returns or creates a recorder instance for the specified log file.

Parameters:

  • log_path (str): Path to the audit log file. Default: "tundere_audit.jsonl"

Returns:

  • A TundereRecorder instance (Rust-backed)

Advanced Usage

Multiple Audit Logs

You can maintain separate audit trails for different components:

from tundere_ledger import audit_log, verify_log

@audit_log(actor_name="system", log_file="payments.jsonl")
def process_payment(amount):
    pass

@audit_log(actor_name="system", log_file="user_access.jsonl")
def access_user_data(user_id):
    pass

# Verify each log independently
if verify_log("payments.jsonl"):
    print("Payment log is clean")

if verify_log("user_access.jsonl"):
    print("Access log is clean")

Custom Recorder Management

from tundere_ledger import get_recorder

# Get or create a recorder
recorder = get_recorder("custom_audit.jsonl")

# Manually record events
recorder.commit_truth("admin", 5.0, '{"action": "user_deleted", "user_id": 42}')

# Verify integrity
if recorder.verify_integrity():
    print("Audit trail is intact")

Security Considerations

  • Path Traversal Protection: All log file paths are validated and must reside within the current working directory.
  • Immutable Chain: Each entry is hashed with the previous hash, making tampering immediately detectable.
  • Actor Identification: Always specify a meaningful actor_name for audit traceability.

License

MIT

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 Distributions

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

tundere_ledger-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (322.0 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

tundere_ledger-0.1.0-cp38-abi3-macosx_11_0_arm64.whl (280.1 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file tundere_ledger-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tundere_ledger-0.1.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 db4966a2e11cb015533b94f79806ec39a78d1f4b63d5245a013e6da2e057c608
MD5 86d6bded3fca4b0dd0726757c3eedd67
BLAKE2b-256 82cfe89310972f1236bfe607710e87613543c5d006eb81c3a6f33032b08d63fd

See more details on using hashes here.

File details

Details for the file tundere_ledger-0.1.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tundere_ledger-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f7f21571b775f32f39010f055e32bc8b882358e98fa21bd7a9115327b1233aa1
MD5 bccbee73b691777aafb9a5e017364d14
BLAKE2b-256 0c3e7be80bbf572dce622a10db96274766d433adaa1064362f0376aba5fa3db6

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