Theus Framework
"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
@processis 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
@processcontracts - 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,minimalRunpy -m theus.cli init --helpto 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@processfunctions and automatically populatesspecs/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: Generatesspecs/context_schema.yamlfrom 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
- Software: MIT License.
- Whitepaper: CC-BY 4.0.
Maintained by: Hoàng Đỗ Huy
Release files for theus 3.0.25
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| theus-3.0.25.tar.gz | 568.0 kB | Details |
Built distributions (wheels)
Total release size: 17.2 MB
Release files / theus-3.0.25.tar.gz
| Download URL | theus-3.0.25.tar.gz |
|---|---|
| Size | 568.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9dd7382d4da2461e2edf029d78db4823552fd546d74e044bc8e80479a716fa03
|
|
BLAKE2b-256 checksum How to use checksums |
4980e36e3d6dcd9a15fbd9a24972b7cf40eecf33b11a450eb01b58f251538f44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp314-cp314-win_amd64.whl
| Download URL | theus-3.0.25-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 951.7 kB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
1315eff2e064ce3a3ca8ce2d9cddecb062654e5f92b984d7a30c2b446d855252
|
|
BLAKE2b-256 checksum How to use checksums |
36fdcd3bc4e7f4747d15cec8960e8c4bfe47a6d4e8ab1c6e694570c52d3aec4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | theus-3.0.25-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.14 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
7beb53a78144b5bcadee6c678b3e53214b82487671969bb4c3f96fc4cf6c6966
|
|
BLAKE2b-256 checksum How to use checksums |
ce5be643a2eeabd8a5af869705509c8ca9447fd1498286d5c0db38e5de4b6f6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | theus-3.0.25-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.14 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
7c9eeea5f4daab7b77984cb33925e61d3d10f75ddc21623ffdf249ea8a5d481e
|
|
BLAKE2b-256 checksum How to use checksums |
ca8517f36d60acee8e4f34db2210350db862d24d13600d951578683491697afd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | theus-3.0.25-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5c3ef23e633130758e3f9c1fefa0b48f70984037c872b97aa59ff374f3abc756
|
|
BLAKE2b-256 checksum How to use checksums |
225180dc7830a15c451aeaa6fb90106d7bfc39c4db9f8dbd38eb92e992fe5c82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp314-cp314-macosx_10_12_x86_64.whl
| Download URL | theus-3.0.25-cp314-cp314-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.14 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
5933fe2ef9ab25a05274371ef270ec35e35908cd58931f785bb90e8f1c8cf7af
|
|
BLAKE2b-256 checksum How to use checksums |
967cdbc3e845c7bb4859ace66c1b81f9fc9253bb0635f5a299e0f9f9952041da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp313-cp313-win_amd64.whl
| Download URL | theus-3.0.25-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 951.7 kB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6fe73b647c4d45c74fa0e3d415e8cfe4d179637e1af0a371a3c6f334f26fe47d
|
|
BLAKE2b-256 checksum How to use checksums |
7736d71ecba35406e2322083493484aa7e648a29a08c4f04ab21a48722861bca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | theus-3.0.25-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
6ca5930a1aa4425702586db2e10cb4d36f519111f74512548ad653186db121ad
|
|
BLAKE2b-256 checksum How to use checksums |
1205e8f8ddb5fee73f31b687a961898d6a16afdf391fa3215e649cf9089bacd4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | theus-3.0.25-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
486cfac7ed80bdecbacad96a9a3f1e313b94c57fac429938579c5b7b43de0cef
|
|
BLAKE2b-256 checksum How to use checksums |
bac72fbed832cdbbd235a17f8742ea327b71f0fbd98b5fe572bb5e2dfa04b58d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | theus-3.0.25-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
dbfa877b11dfe621e7244ca1e32db5302c6350bd590cedf6c0a3cfe12d0f9174
|
|
BLAKE2b-256 checksum How to use checksums |
c1ec8725b4ec83a2a274cdcebe26e16612e0a1b8601ca5dbbf9b97472eb0f0c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp313-cp313-macosx_10_12_x86_64.whl
| Download URL | theus-3.0.25-cp313-cp313-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.13 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
ac72c04525d4013146a86cca1bec69b08f1407307b5ff2fc531f717a8f233ab7
|
|
BLAKE2b-256 checksum How to use checksums |
8cd5b0ea2608e18fe6333cf55a71b2f33e2848520fe196033c34991a12c1c2ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp312-cp312-win_amd64.whl
| Download URL | theus-3.0.25-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 947.9 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
ffa5fa736213a1cc9eb6654f270d458619ffbfcccf192b8a992316ec5892ba11
|
|
BLAKE2b-256 checksum How to use checksums |
45355f7fbfe7184c40d4e8ac11cca1a8acdb5328591f0cfeb2c26fb517e91155
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | theus-3.0.25-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
507e237d82919a01604b725d98255062ca64e03f8262db6b985a23906c54013e
|
|
BLAKE2b-256 checksum How to use checksums |
e1e22e1fe0fb8c86868cfca4f74fe69c07446b6ab5edc53ced21dc1cd7b8a883
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | theus-3.0.25-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
b133dc93e60e0cc6127d18f13657225731b000288fc2a46ce94ca45c3d47d72e
|
|
BLAKE2b-256 checksum How to use checksums |
b89251526b01ba6e9b3beec6a6d8bf456b670222c30bac57062bb3f2e73c1e77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | theus-3.0.25-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4a4e3b18aa281e5c011fdf819236d72ce44fec7de5f23686ad44acc829a25f15
|
|
BLAKE2b-256 checksum How to use checksums |
97397280631aa3362c0f140330e0b6c95130d0964303d54adf32f8520ba0455f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|
Release files / theus-3.0.25-cp312-cp312-macosx_10_12_x86_64.whl
| Download URL | theus-3.0.25-cp312-cp312-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.12 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
469a416bd7e354b55732e8da74a2f168707f0521189515fc0094b4df50b7356d
|
|
BLAKE2b-256 checksum How to use checksums |
edec6a5e6e7ad12d8dd7f18077abaf09b63bd6ad6cb0116ad7ac905eb7cff32d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.12.6
|