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.22 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.22): 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.22.tar.gz (534.8 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.22-cp314-cp314-win_amd64.whl (944.2 kB view details)

Uploaded CPython 3.14Windows x86-64

theus-3.0.22-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.22-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.22-cp314-cp314-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.12+ x86-64

theus-3.0.22-cp313-cp313-win_amd64.whl (944.2 kB view details)

Uploaded CPython 3.13Windows x86-64

theus-3.0.22-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.22-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.22-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

theus-3.0.22-cp312-cp312-win_amd64.whl (941.9 kB view details)

Uploaded CPython 3.12Windows x86-64

theus-3.0.22-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.22-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.22-cp312-cp312-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

theus-3.0.22-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.22.tar.gz.

File metadata

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

File hashes

Hashes for theus-3.0.22.tar.gz
Algorithm Hash digest
SHA256 9c4869b266048aaf5f8b799feb4a118d1e65d0e98ac9684be7fb06bbd9db350f
MD5 ad3834a5472d810479e9a3b8afe0ab78
BLAKE2b-256 ecec5a522690db40d7a1f122f9e0f454fb82d584852a51edfe6488309fae6a26

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for theus-3.0.22-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 34a97accd241759c86797b1a83fe7b13f0ce5c1cab150dfef3fabdecbf11c37f
MD5 afbd3ff26ee7fe38f253e96dae96901a
BLAKE2b-256 bdaba1aac2183a477faf32a5ba6af0d7495df383bc878dee5859644610e99b0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.22-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 529b5be1c0d9e89c5be5522452eef2ee1222dd7c00e76b36c2498798296ad826
MD5 52f333b00d36b23dbc59faf1f5be8961
BLAKE2b-256 3f4316a66bc8c013732a29a6beff56d9c0c6eb1c9e978b58e2b8a3779f733cb1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.22-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 52a33e732c474c66bc7220e7f95e91c8bc1a3f1619d841a918ef679e389242a4
MD5 999a7ec67a8910be73881b3e091e29f1
BLAKE2b-256 8e46f0e71575d43655687520518ea0f203c0053b0dcc61e5661d1af13fd75e69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.22-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c5e5cf5fef4c0f3a11cb6f3a6df7c05a4618ee0f1f3a36930a86279975b005f
MD5 51a3379b9aefb452cc3f4b42b19fbff5
BLAKE2b-256 1da388643f36a1e8c1c10a2e27a16ab422c1debe2674ad7ac71dee248d701acf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.22-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7355a8e77b21ee27984ddf4d2691e0011dfdc40fbece2141759142e72291a13e
MD5 9ec6620c7d08513329a9dfa0285fde55
BLAKE2b-256 6e6748d0a42febcd54aaf6101fe2e60acc69b7e3ab7769775637101314d1ba21

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for theus-3.0.22-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 340b249f8455dea7dbe4d99ae85a84f8f266fe0d0b35d50f6882b70001fe5906
MD5 fed093ef15ddd15fd6cd82c5a629d3bf
BLAKE2b-256 7636196d9047126563095146a864373113243771917314d39d3d020a301e5767

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.22-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4687707c7ebf91099a9ee7205c4e4a3039247e225449a76942e83a242f6acd51
MD5 ca3de76e63c1ab65b591e32c61fddf87
BLAKE2b-256 06067519ec8c77cb1437a8525f68a94bd808ebaa6dc531af615535434df06427

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.22-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 04de5dbdf502d52c9ef0f253f985add6ee060f1060799973635892313f6aec32
MD5 71141160207716410e6bda823fd0eec9
BLAKE2b-256 585546d4952e9abea9262dc8c142b86b23b2bf9fa0cdf3b3cdfca7458da7522a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.22-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e69c701c383d7ab665a03a823da14c5cb13c8699315726eb46661deef029ea80
MD5 bd45ca98b8228d6130624e0cd7e41dd7
BLAKE2b-256 c6e062058af8bd6d91772c26f538db5f74106598e7695952e248e997792581fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.22-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 7f43e48c2b1aa9688c34b49284b510ca73a5b64dcd37356ea2e5bf531909bcf6
MD5 781735a65beb4a04a10722ec40c264a3
BLAKE2b-256 9a393ba7529800f341a294c6ca60127bf9600f8823c4d625f6e1ba814fa7445c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for theus-3.0.22-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7e07fab0f2e773d5034116511b7f5bd7415df5db662c2103a6ba4c83af650b2d
MD5 62b870dab328ebfa7e2cb82e72ecb0f4
BLAKE2b-256 f3f29df3aa142f68f858056780cc01123531620d6f6e3989db8c86514ff989a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.22-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 413f141404e75b7b5d8235283c66154c8bb059853d3696c326dec4dfc2e9e4d4
MD5 0ef914fb9f3e77c678ca88e5fb2d508c
BLAKE2b-256 07372f362ac926e8091d115cb9550ea514cecc85d9a18febb533cd30a62fcdf2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.22-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d5ef48a8aa2d2d9a8208f6642cb537a3264799b18e23a1aaef17d613f36dc36c
MD5 6eb740a12507f2dcb69c05f3a8bad793
BLAKE2b-256 ba1ff3507563477c5ffbb7d322027203feeca5dbdfbc9049f5e6a92324180714

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.22-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b22608b8c657c97bfaf251346582c22e686700d84ecbcd041f7e8c1509fc2a31
MD5 038db4cf0b870be97a1821e85c4f36d9
BLAKE2b-256 ac10a215e7f5d27dfe0a475ffecc989e73c09439ba0f12458b7745aea03f4fa2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.22-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ec21ff63322d6b377f5a30acf57f2689f76709a79547ecc5c0fb78fcb29ab785
MD5 dea2191b867543d535b34831b978bb59
BLAKE2b-256 61cc9a877afebbea16dd5ff8e230e3ee89b07515d593c976d5ebebeb3854da3d

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