A Rust-based tool that applies transformations on Python programs.
Try the demo · GitHub
Pithon parses Python source code, applies a pipeline of AST transformations (one-liner conversion, name obfuscation, string encoding, constant folding, ...), and serializes the result back to valid Python. It compiles to WebAssembly for in-browser use.
This tool is currently in development and is considered a preview: it may be unstable and doesn't support all Python 3 language features.
Parse and re-serialize without changes. Useful for validation.
Flatten multi-line Python programs into a single expression.
| Feature | Status |
|---|---|
| Variables and data types | ✅ Done |
| Control structures (if/else, for/while loops) | ✅ Done |
| Flow statements (return, break, continue, pass) | ✅ Done |
| Functions and lambdas | ✅ Done |
| Classes and objects | ✅ Done |
| Annotations | ✅ Done |
| List, tuple, and dictionary manipulation | ✅ Done |
| Modules and packages | ✅ Done |
| Decorators | ✅ Done |
| Built-in functions and modules | ✅ Done |
| Generators and iterators | ✅ Done |
| Globals | ✅ Done |
| Delete | ✅ Done |
| Exceptions | ✅ Done |
| Exception handling (try/except/finally) | ✅ Done |
| Context managers (with) | ✅ Done |
| Type hints / Static typing | ✅ Done |
| Yield | ⛔ Not feasible |
| Async / Await | ⛔ Not feasible |
Note:
yieldandasync/awaitcannot be one-linerized because Python lambdas cannot containyieldexpressions or be declaredasync.
- Confuse Names - Rename variables to visually ambiguous
l/Isequences - Encode Strings - Replace string literals with
chr()expressions - Homoglyphs - Swap identifiers with Unicode lookalike characters
- Reverse Booleans - Negate conditions and swap branches
- Obfuscate Numbers - Replace numeric literals with equivalent expressions
- Fold Constants - Evaluate constant expressions at compile time
- Expand Augmented - Expand
+=,-=,*=into full assignments
git clone https://github.com/mlhoutel/pithon.git && cd pithoncargo test
cargo buildcd docs
wasm-pack build --target web --out-dir static --out-name pithon_wasm
npm i && npm run startOnce the server is running, open http://localhost:3000 to see the demo.
If you have ideas for new transformations, open an issue. Pull requests are welcome - please run cargo test and cargo fmt before submitting.