A Python to V transpiler. Converts Python source code to the V programming language.
- V compiler
- Python 3.8+
- py2many -
pip install py2many
cd py2v
v . -o py2v# Output to stdout
py2v input.py
# Output to file
py2v input.py -o output.vPython input:
def fib(i: int) -> int:
if i == 0 or i == 1:
return 1
return fib(i - 1) + fib(i - 2)
if __name__ == "__main__":
print(fib(5))V output:
@[translated]
module main
fn fib(i int) int {
if i == 0 || i == 1 {
return 1
}
return fib((i - 1)) + fib((i - 2))
}
fn main() {
println((fib(5)).str())
}- Functions and type annotations
- Classes and methods
- List/dict/set comprehensions
- Generators and iterators
- Exception handling (try/except/finally)
- Context managers (with statements)
- Lambda expressions
- Walrus operator (:=)
- f-strings
- Async/await
- Dataclasses and enums
cd tests
sh run_tests.shpy2v uses a two-stage pipeline:
- Python frontend (
frontend/ast_dump.py) - Parses Python source using py2many's analysis passes, enriches the AST with type inference and scope information, outputs JSON - V backend (
transpiler.v) - Consumes the JSON AST and generates V code
MIT