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.25.tar.gz (568.0 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.25-cp314-cp314-win_amd64.whl (951.7 kB view details)

Uploaded CPython 3.14Windows x86-64

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

Uploaded CPython 3.14macOS 11.0+ ARM64

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

Uploaded CPython 3.14macOS 10.12+ x86-64

theus-3.0.25-cp313-cp313-win_amd64.whl (951.7 kB view details)

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

theus-3.0.25-cp312-cp312-win_amd64.whl (947.9 kB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

theus-3.0.25-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.25.tar.gz.

File metadata

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

File hashes

Hashes for theus-3.0.25.tar.gz
Algorithm Hash digest
SHA256 9dd7382d4da2461e2edf029d78db4823552fd546d74e044bc8e80479a716fa03
MD5 bcd9d51c04289678259161b539ab98c0
BLAKE2b-256 4980e36e3d6dcd9a15fbd9a24972b7cf40eecf33b11a450eb01b58f251538f44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: theus-3.0.25-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 951.7 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.25-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 1315eff2e064ce3a3ca8ce2d9cddecb062654e5f92b984d7a30c2b446d855252
MD5 2fdbd623bb7800f31c0888792456766c
BLAKE2b-256 36fdcd3bc4e7f4747d15cec8960e8c4bfe47a6d4e8ab1c6e694570c52d3aec4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.25-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7beb53a78144b5bcadee6c678b3e53214b82487671969bb4c3f96fc4cf6c6966
MD5 782ff1f49892e407049120edc4b76d9a
BLAKE2b-256 ce5be643a2eeabd8a5af869705509c8ca9447fd1498286d5c0db38e5de4b6f6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.25-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7c9eeea5f4daab7b77984cb33925e61d3d10f75ddc21623ffdf249ea8a5d481e
MD5 9658b5ea035991800d2da274afbe7c89
BLAKE2b-256 ca8517f36d60acee8e4f34db2210350db862d24d13600d951578683491697afd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.25-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5c3ef23e633130758e3f9c1fefa0b48f70984037c872b97aa59ff374f3abc756
MD5 6eed11fe43cc1a496113fd1d24df4624
BLAKE2b-256 225180dc7830a15c451aeaa6fb90106d7bfc39c4db9f8dbd38eb92e992fe5c82

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.25-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5933fe2ef9ab25a05274371ef270ec35e35908cd58931f785bb90e8f1c8cf7af
MD5 68995302c0dd74b35ee3ed70187daddc
BLAKE2b-256 967cdbc3e845c7bb4859ace66c1b81f9fc9253bb0635f5a299e0f9f9952041da

See more details on using hashes here.

File details

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

File metadata

  • Download URL: theus-3.0.25-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 951.7 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.25-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6fe73b647c4d45c74fa0e3d415e8cfe4d179637e1af0a371a3c6f334f26fe47d
MD5 7bd8ee5ee281af33bb4c1272da154f29
BLAKE2b-256 7736d71ecba35406e2322083493484aa7e648a29a08c4f04ab21a48722861bca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.25-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6ca5930a1aa4425702586db2e10cb4d36f519111f74512548ad653186db121ad
MD5 1706c988d0aa8912fdb1d90213263577
BLAKE2b-256 1205e8f8ddb5fee73f31b687a961898d6a16afdf391fa3215e649cf9089bacd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.25-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 486cfac7ed80bdecbacad96a9a3f1e313b94c57fac429938579c5b7b43de0cef
MD5 4001f3c3ef3a362bd6249901bde05e09
BLAKE2b-256 bac72fbed832cdbbd235a17f8742ea327b71f0fbd98b5fe572bb5e2dfa04b58d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.25-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dbfa877b11dfe621e7244ca1e32db5302c6350bd590cedf6c0a3cfe12d0f9174
MD5 04c5600419efcf2e8d6b1e08d9b8ca91
BLAKE2b-256 c1ec8725b4ec83a2a274cdcebe26e16612e0a1b8601ca5dbbf9b97472eb0f0c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.25-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ac72c04525d4013146a86cca1bec69b08f1407307b5ff2fc531f717a8f233ab7
MD5 04eb0c1c0805c1c4568ccc0148994be5
BLAKE2b-256 8cd5b0ea2608e18fe6333cf55a71b2f33e2848520fe196033c34991a12c1c2ae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: theus-3.0.25-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 947.9 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.25-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ffa5fa736213a1cc9eb6654f270d458619ffbfcccf192b8a992316ec5892ba11
MD5 346513fde2ce1880169096212f1a6eb6
BLAKE2b-256 45355f7fbfe7184c40d4e8ac11cca1a8acdb5328591f0cfeb2c26fb517e91155

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.25-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 507e237d82919a01604b725d98255062ca64e03f8262db6b985a23906c54013e
MD5 6fd30a9f6ade4d111694ed77230a21a2
BLAKE2b-256 e1e22e1fe0fb8c86868cfca4f74fe69c07446b6ab5edc53ced21dc1cd7b8a883

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.25-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b133dc93e60e0cc6127d18f13657225731b000288fc2a46ce94ca45c3d47d72e
MD5 96245d3b76f98b46562cec8733b1b916
BLAKE2b-256 b89251526b01ba6e9b3beec6a6d8bf456b670222c30bac57062bb3f2e73c1e77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.25-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4a4e3b18aa281e5c011fdf819236d72ce44fec7de5f23686ad44acc829a25f15
MD5 1d4c8a82a73fa79a3fcf4a299def425e
BLAKE2b-256 97397280631aa3362c0f140330e0b6c95130d0964303d54adf32f8520ba0455f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for theus-3.0.25-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 469a416bd7e354b55732e8da74a2f168707f0521189515fc0094b4df50b7356d
MD5 ca6ed3f287d5df555262cca09989833c
BLAKE2b-256 edec6a5e6e7ad12d8dd7f18077abaf09b63bd6ad6cb0116ad7ac905eb7cff32d

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