Engine for generating and executing dynamic code templates: fast, readable, and incredibly flexible.
Project description
🦜 Ditto
Tiny 🐍 Python templating + validation DSL.
🚀 Quick Example
_ditto = Ditto()
Phrase = _ditto.phrase
Rule = _ditto.customrule
Rule("even", lambda x: x % 2 == 0)
say = Phrase("print({int,1:3,even})")
say(24) # ✅ OK
📋 Feature Table
| 🧩 Feature | ✍ Syntax | ✅ What It Does | 📝 Example |
|---|---|---|---|
| Type check | {int} |
Ensures argument is built-in type | {str} |
| Length rule 📏 | {str,3:10} |
Length must be between min:max |
{list,1:5} |
| Ignore field | * |
Skips that validation | {*,*,rule} |
| Custom rule 🔧 | {int,*,even} |
Runs registered rule | Rule("even", fn) |
| Arg count check | Auto | Args must match placeholders | — |
| Error override ⚠ | failrule= |
Custom error handler | Phrase(..., failrule=fn) |
| Executable template 🔥 | exec() |
Runs validated template | "print({int})" |
🧩 Placeholder Format
{type, min:max, custom_rule}
All fields optional. Use * to ignore.
❌ Errors
Raises ValueError by default.
def handler(exc):
print("⚠", exc)
return False
🔥 Security Warning
Uses eval() + exec() 💣
Never use with untrusted input.
🧪 Experimental 🚫 Not production-safe 🛠 Built for DSL exploration
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dittox-0.0.2.tar.gz.
File metadata
- Download URL: dittox-0.0.2.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.11.14 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
933e6862231bc9c6557d04b3c839263d424361cd60f55cfb3cba9b8ce565ca6e
|
|
| MD5 |
de4a2a47e9d72c59575c2c7a3c598800
|
|
| BLAKE2b-256 |
2d0304ec3e4dd949f59f691461182a882714901e3cb07da6060fde2cfaea3b1c
|
File details
Details for the file dittox-0.0.2-py3-none-any.whl.
File metadata
- Download URL: dittox-0.0.2-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.5 cpython/3.11.14 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8491f49271faa7110642a4231187c28ddfbaf4bce5d81e29a0047e6184e3c79f
|
|
| MD5 |
6a3848c129c4e5c8939d66c0da623d67
|
|
| BLAKE2b-256 |
07fe2376ea8954debfacf37469aafbef21d6ddf2d0bbb6c8a184dc5e7560af89
|