Skip to main content

Reliable, Rust-Powered Agentic AI Framework with Transactional Memory.

Project description

Theus Framework

PyPI version License: MIT Python 3.14+

"Safe architecture for AI-assisted development. Powered by Rust."


🧭 Where do I start?

Theus is vast. Use our Interactive Documentation Map to find your path:


� Why Theus?

"Build with confidence. Your AI assistant writes the code—Theus makes sure it's safe."

Whether you're vibe coding with an AI assistant, building a complex agent, or crafting production software that needs to last for years—Theus has your back.

For Vibe Coders & AI-Assisted Development

You focus on what you want to build. Let your AI write the logic. Theus automatically ensures:

  • Every function declares exactly what data it reads and writes
  • No hidden side effects or surprise mutations
  • If something goes wrong, it rolls back cleanly

For Teams Who Care About Maintainability

Come back to your code in 2 years. You'll thank yourself:

  • Explicit Contracts: Every @process is self-documenting
  • Transparent State: Know exactly where your data lives and who can touch it
  • Built-in Audit: Validate business rules at the boundary, not scattered in code

For Safety-Critical Applications

When bugs aren't just annoying—they're costly:

  • Transaction Safety: Automatic rollback on failure
  • Explicit Access: Processes must declare every data point they touch via @process contracts
  • Industrial Audit: Block, warn, or stop based on configurable rules

📦 Installation

Theus v3.0 requires Python 3.14+ to leverage Sub-interpreter support.

pip install theus

⚡ Quick Start

Option 1: Use a Template (Recommended)

# Create a new project with the E-Commerce demo (full-featured)
py -m theus.cli init my_app --template ecommerce
cd my_app
python main.py

This creates a complete runnable demo with: Orders, Payments, Heavy Zone, Audit Rules, and Workflow.

Option 2: Manual Setup

from theus import TheusEngine, process

# 1. Define a Process with Contract
@process(
    inputs=['domain.accounts'],
    outputs=['domain.accounts'],
    errors=['ValueError']
)
def transfer(ctx, from_user: str, to_user: str, amount: int):
    if amount <= 0:
        raise ValueError("Amount must be positive")
    
    # V3 Pattern: Copy -> Modify -> Return
    # ctx.domain.accounts is Immutable (FrozenDict) in strict_mode
    accounts = dict(ctx.domain.accounts)
    
    if accounts.get(from_user, 0) < amount:
        raise ValueError("Insufficient funds")
    
    accounts[from_user] -= amount
    accounts[to_user] = accounts.get(to_user, 0) + amount
    
    # Return new state (Engine handles the commit)
    return accounts

# 2. Initialize Engine
from src.context import DemoSystemContext
engine = TheusEngine(DemoSystemContext(), strict_mode=True)
engine.register(transfer)

# 3. Execute with Transaction Safety
result = engine.execute(transfer, from_user="Alice", to_user="Bob", amount=500)

💡 Available Templates: standard, ecommerce, hybrid, agent, minimal Run py -m theus.cli init --help to see all options.


🔄 Workflow: Flux DSL

v3.0 introduces Flux DSL - a declarative YAML language for workflow control.

# workflows/main.yaml
steps:
  - process: "initialize"
  
  - flux: if
    condition: "domain['is_valid'] == True"
    then:
      - "process_data"
      - "save_result"
    else:
      - "handle_error"
  
  - flux: while
    condition: "domain['items_left'] > 0"
    do:
      - "process_next_item"

Execute with:

engine.execute_workflow("workflows/main.yaml")

🛠️ CLI Tools

Theus provides a powerful CLI suite to accelerate development and maintain architectural integrity.

  • py -m theus.cli init <project_name>: Scaffolds a new project with the standard V3 structure.
  • py -m theus.cli audit gen-spec: Scans your @process functions and automatically populates specs/audit_recipe.yaml.
  • py -m theus.cli audit inspect <process_name>: Inspects the effective audit rules for a process.
  • py -m theus.cli schema gen: Generates specs/context_schema.yaml from your Python Dataclass definitions.
  • py -m theus.cli check: Runs the POP Linter to enforce architectural purity.

🧠 Advanced Architecture

The Transaction Engine (v3.0)

Theus prioritizes Performance (Zero-Copy) while providing Safety Tools:

  • Zero-Copy Reads: Reading data is O(1) direct memory access.
  • Copy-on-Write: To modify data, you MUST create a copy (new = list(old)).
  • Atomic Commit: The Engine swaps the pointer to the new data only if the transaction succeeds.

⚠️ Warning: In-place mutation (e.g., list.append) bypasses the safety lawyer. Always use the Copy-on-Write pattern.

The Heavy Zone (Optimization)

For AI workloads (Images, Tensors) > 1MB, use heavy_ variables.

  • Behavior: Writes bypass the Transaction Log (Zero-Copy).
  • Trade-off: Changes to Heavy data are NOT reverted on Rollback.

Research & Debugging Mode

For rapid experimentation where you need to bypass architectural constraints:

engine = TheusEngine(sys_ctx, strict_mode=False) Effect: Disables strict architectural guards (ContextGuard), allowing access to private attributes (_hidden) and restricted zones. Note: Transaction safety (CAS) is still enforced to ensure consistency.


📚 Documentation

  • POP Manifesto: The philosophy behind Process-Oriented Programming.

⚖️ License

Maintained by: Hoàng Đỗ Huy

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

theus-3.0.2.tar.gz (392.1 kB view details)

Uploaded Source

Built Distributions

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

theus-3.0.2-cp312-abi3-win_amd64.whl (582.0 kB view details)

Uploaded CPython 3.12+Windows x86-64

theus-3.0.2-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (797.1 kB view details)

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

theus-3.0.2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (791.1 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

theus-3.0.2-cp312-abi3-macosx_11_0_arm64.whl (724.4 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

theus-3.0.2-cp312-abi3-macosx_10_12_x86_64.whl (740.5 kB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

Details for the file theus-3.0.2.tar.gz.

File metadata

  • Download URL: theus-3.0.2.tar.gz
  • Upload date:
  • Size: 392.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for theus-3.0.2.tar.gz
Algorithm Hash digest
SHA256 e3f8195ba559d15ac318ec4af38b2ec9e2751d0743b2fbf6c0e64629543eb992
MD5 034fc1b397a7ecafb7b9fd62874bbf1c
BLAKE2b-256 40df759ab3d1f62ca3a9f2ec149f9d31a7a120e1cb49dee3f70fa320ae492cd3

See more details on using hashes here.

File details

Details for the file theus-3.0.2-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: theus-3.0.2-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 582.0 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.11.5

File hashes

Hashes for theus-3.0.2-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5f3260bcd6f220045ac107d0611160ffed0b7e6ba876bc7d5cf369dd106c4ce9
MD5 9e8477fea5fd1edd25a517ea817c7b29
BLAKE2b-256 b079a181adabc2b08e26db4ea97212c767ed8aa5ca276b0b0a0a5ca51e1fbe94

See more details on using hashes here.

File details

Details for the file theus-3.0.2-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for theus-3.0.2-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 637d01e1243bdfd0fd3a1ee95eb7662bd4501ed1f33d9c91933b57650da637d2
MD5 b61cccc22325448e9b6ce8044765773c
BLAKE2b-256 7a07e6f10cb526cf182386c12537326b678df0c34256c589cb3faafd466b4c5d

See more details on using hashes here.

File details

Details for the file theus-3.0.2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for theus-3.0.2-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a26f6d1f4a313a66070cb38b45cbd60f910cd5a32359cd3bc66fffcf55134c75
MD5 03763c371dea5f58f0a83b294b341177
BLAKE2b-256 3cbdf40278d0b00ec8bc43ab4500067b9131dc07ad2989ae860d722087ac7d4c

See more details on using hashes here.

File details

Details for the file theus-3.0.2-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for theus-3.0.2-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8e773d93ce700fa594657ef3dd21093215deed33c888eb51ebbc82a3de939fa8
MD5 2c7a17cb73deb34e6474f882e3e0d1eb
BLAKE2b-256 ec037a2571b1dc6af0ec938fccb34725c9333038cdbdc6443e5987e554ed7288

See more details on using hashes here.

File details

Details for the file theus-3.0.2-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for theus-3.0.2-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 8e9e598a7ef94654130eb301b7377b8ca00a6daa7c6934611ad7f498d66b7114
MD5 a3c2e4896433f826af95379b9e0001c1
BLAKE2b-256 1b58b1f80af61e5e1922e794cec45b08b139f47dca73347f9ff22613fc990485

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