Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pithon logo

Pithon

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.

Transformations

Identity (no transformation)

Parse and re-serialize without changes. Useful for validation.

To One-liner

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: yield and async/await cannot be one-linerized because Python lambdas cannot contain yield expressions or be declared async.

Obfuscation passes

  • Confuse Names - Rename variables to visually ambiguous l/I sequences
  • 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

Getting started

git clone https://github.com/mlhoutel/pithon.git && cd pithon

Library development

cargo test
cargo build

Demo website

cd docs
wasm-pack build --target web --out-dir static --out-name pithon_wasm
npm i && npm run start

Once the server is running, open http://localhost:3000 to see the demo.

Contributing

If you have ideas for new transformations, open an issue. Pull requests are welcome - please run cargo test and cargo fmt before submitting.

License

MPL-2.0

About

transformations on python programs

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages