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
  • Concurrency Safety: Advanced Conflict Manager with Backoff & VIP Locking

📦 Installation

Theus v3.0.23 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
from theus.structures import StateUpdate

# 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)
    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 explicit update (Engine handles the commit)
    return StateUpdate(domain={'accounts': accounts})

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

# 3. Execute with Transaction Safety (Async API)
import asyncio
result = asyncio.run(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: "process_data"
      - process: "save_result"
    else:
      - process: "handle_error"
  
  - flux: while
    condition: "domain['items_left'] > 0"
    do:
      - process: "process_next_item"

Execute with (Sync Bridge):

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 & Zero-Copy Parallelism (Strategy V3)

Current Status (v3.0.23): True Parallelism is now available via ProcessPool.

For AI workload/Tensors > 1MB, ctx.heavy acts as a Shared Memory Gateway:

  • Zero-Copy: leverages shared memory to pass large datasets between processes without serialization overhead.
  • True Parallelism: CPU-bound tasks can bypass the GIL using ProcessPool.
  • Conflict Safety: Integrated Exponential Backoff and VIP Locking ensure that high-concurrency workloads do not starve or livelock.

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.


⚖️ 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.24.tar.gz (567.5 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.24-cp314-cp314-win_amd64.whl (951.5 kB view details)

Uploaded CPython 3.14Windows x86-64

theus-3.0.24-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

theus-3.0.24-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

theus-3.0.24-cp314-cp314-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

theus-3.0.24-cp314-cp314-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

theus-3.0.24-cp313-cp313-win_amd64.whl (951.5 kB view details)

Uploaded CPython 3.13Windows x86-64

theus-3.0.24-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

theus-3.0.24-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

theus-3.0.24-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

theus-3.0.24-cp313-cp313-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

theus-3.0.24-cp312-cp312-win_amd64.whl (947.7 kB view details)

Uploaded CPython 3.12Windows x86-64

theus-3.0.24-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

theus-3.0.24-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

theus-3.0.24-cp312-cp312-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

theus-3.0.24-cp312-cp312-macosx_10_12_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for theus-3.0.24.tar.gz
Algorithm Hash digest
SHA256 3791fdb08a99b9b6ba1ae30663f651b1925d2cd89e47f4f785a1c9c893cf6bf4
MD5 aa771ce82e7056e26d9678676064a927
BLAKE2b-256 aa1bca2468ab2f6dcd1a9b2101e9c0d2b5668cfbd7f5fc4792d59b9e53dd1002

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: theus-3.0.24-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 951.5 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for theus-3.0.24-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 ed562210adaaa5a50a1261ac4874a56f948d6710bb4d3e6bb3eed41cff9b4925
MD5 f1714dd559ff33b502daac9b86182f89
BLAKE2b-256 6d7079ed3c363a6e7c546ccf0e043e491b281252e882065054493523e8a03c01

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for theus-3.0.24-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 db2783a9399eb087a61917bfa6314281c08b51fbe599cbff2bff5d543174950d
MD5 afde7d88021b767763ba84bdf55b8c6c
BLAKE2b-256 342bc173ad2165c10e6a495b3dc86cbf058427bb811f052a0fc8b13f17c63699

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for theus-3.0.24-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 810c616eca3e8c13fb03a49c45df06c106ec36c7c92817b1335e3cf6c149cc93
MD5 f2b8d2eaff1ec773f844bcd729f33357
BLAKE2b-256 25b81f12425658e10e70d54984a51f3940527782663d6238fa5f57fc86a464c3

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for theus-3.0.24-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5ce944091f8228c50fff5c4bd524fe4aefb2b1710d2b39d2507e7cb9a43a4bd
MD5 7aeb4ed3797897bf749793ac91b892e3
BLAKE2b-256 d28eee5e885e01eb3778b4e1db82d3eb5256c93f8d26b679480eac2a135e670f

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for theus-3.0.24-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5a53166dc6030bc67802f038188b2dc0966a033a5faa9f272c14fbad877c9b7a
MD5 31d691e8ad6c7cb459201ce40fb3012f
BLAKE2b-256 071f13970d4f3236acb344f3e0c936f70d2f898f9e6ac751e03ea1944accba7e

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: theus-3.0.24-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 951.5 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for theus-3.0.24-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 fab34e80195d1f0948e4c2f90f086cd268de0ef6d08a7de8ff259243ea877038
MD5 a71fc6faaad0ce2937e9f4c8c8a38ab7
BLAKE2b-256 347e86b9337f794754af234b4ab2c4a033384bc0953aa98afc0a834df07d4675

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for theus-3.0.24-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e9255c1d975fd7cd90d93b70b5e95e0f5442639fa23ac1dfc933be723ad0669b
MD5 0b331d09b2c7a7479d489d607099171b
BLAKE2b-256 f7883e91718510b1af932fa600095979baad1822acb72570258146b28e6c9dc1

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for theus-3.0.24-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5645af121359e0a9dc1e6afdc68ebed5c3cb1dcd73d78dc0215853ff9ff65984
MD5 813d9d92c4c4d8df9bfa8efb18f05110
BLAKE2b-256 52ade03bc46399e6ab03dea22c71921099bff1101d8a4f04d4e010d234e79b50

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for theus-3.0.24-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 98584f248f9ae080cfe69bbbaba59e138ed48e7c36df67d085719fb7439dab1e
MD5 c61c44d12bc148972550bd9ec432f58d
BLAKE2b-256 5762362aae8963924f4079fa7316402d6f7d2d578334247852c17e068257f09f

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for theus-3.0.24-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 54b62d03ffed080224afc6ee52ccb1848aefac8c815f7bc48c925fd4a9b39044
MD5 6d708ffd2e2a1190c14835515d19dbfe
BLAKE2b-256 abac528efc96d70a8a6c75f75102880243b634dbef265e23fb385414f670754c

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: theus-3.0.24-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 947.7 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for theus-3.0.24-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 67c34c4e6d4e9dc06da282c6babc6b111f9bbb86986f30c867e870f84f036c11
MD5 24f9ae050ff80545235ae36a6988723a
BLAKE2b-256 7321afb8c4ee2e27d621eca1322bdbe38853a65cb45e95cc1e1b628b3c6c293d

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for theus-3.0.24-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a0fc744e07eb5592362ef683393b1dbb30edb9ef30b6b8a2f5134e8c2b8dc917
MD5 43acab5cad5b8d176d0d88076a4191da
BLAKE2b-256 e431be0d1c6758a79928a76c5a83ee101178a1a494929e16ba309fa45d60d555

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for theus-3.0.24-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cfc01b9bf161bcddfe998d7bd8d42553377b7a80dbc42e03cbbe0a9d497a5e93
MD5 dbcdc5a91dd4ef496a0333c806bff52b
BLAKE2b-256 032b975857729bab91a530fdb9d461956f8de5edc6ab64984318d1e938bc6b23

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for theus-3.0.24-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 44d760cc47dc2b1af762c29bf3456196d134c7702f0f22a787995485f905015c
MD5 646e2ca65fccffbbd53414bf4151ab3e
BLAKE2b-256 ea7e6f27b20a64651fdaa19bcca64b83873981a859ecd2ac3b1b86138fb1a8d8

See more details on using hashes here.

File details

Details for the file theus-3.0.24-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for theus-3.0.24-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6fe6d1d4d9c15500534268d1705697b147b6d6f1faea54340d4388559d3e0b58
MD5 b7cb12617c14f4a223e34c4b7468b2b2
BLAKE2b-256 a8eddceeec358cfe5481b9ba81faab55fb344203af79f7e364c88837b8422797

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