Python-to-Roblox Luau transpiler
Project description
RPy
A Python-to-Roblox Luau transpiler. Write game logic in Python; RPy compiles it to Luau that runs natively in Roblox Studio.
Quick Start
# Install
pip install -e ".[dev]"
# Scaffold a new project
rpy setup myproject
cd myproject
# Transpile a file
rpy transpile src/main.py out/main.lua
# Transpile a directory
rpy transpile src/ out/
# Live Sync (Dev Server + Watcher)
rpy live src/ out/
# Validate without writing output
rpy validate src/
# With type annotations
rpy build src/ out/ --typed --verbose
Example
Python (input):
from roblox import Instance, workspace, Vector3
class NPC:
def __init__(self, name, health):
self.name = name
self.health = health
def take_damage(self, amount):
self.health = self.health - amount
if self.health <= 0:
print(f"{self.name} defeated!")
guard = NPC("Guard", 100)
guard.take_damage(30)
Luau (output):
-- Generated by RPy — do not edit manually
local _RT = require(script.Parent.python_runtime)
local py_str = _RT.py_str
local NPC = {}
NPC.__index = NPC
function NPC.new(name, health)
local self = setmetatable({}, NPC)
self.name = name
self.health = health
return self
end
function NPC:take_damage(amount)
self.health = (self.health - amount)
if (self.health <= 0) then
print(("" .. py_str(self.name) .. " defeated!"))
end
end
local guard = NPC.new("Guard", 100)
guard:take_damage(30)
Supported Python Subset (v1.0.0)
- Variables & Logic: Full support for variables, arithmetic, logical comparisons, and ternary operators.
- Control Flow:
if/elif/else,while, and specializedfor i in range()loops. - Functions: Support for
def,return,lambda, and*args. - Data Structures: Lists, Dicts, and Tuples with 40+ method remaps to Luau's
tablelibrary. - Async & Task: Built-in
taskmodule support fortask.wait(),task.spawn(), andtask.delay(). - Standard Library: Native mapping for
math,string,table,coroutine, anddebuglibraries. - Roblox SDK: Integrated
robloxstubs for 100+ services and classes with autocompletion support. - Modern OOP: Single inheritance classes with metatable-based state management.
- Error Handling: Full
try/except/finallyblocks transpiled to Luaupcall. - Package Management: Native Wally integration via
rpy installfor Luau dependencies. - Intelligence Layer: Fuzzy property suggestions, flow-sensitive type refinement, and nil-safety diagnostics.
- Advanced Performance: Compile-time macros (
@compile_time), Recursive DCE, CSE, and LICM optimizations.
Compiler Flags
| Flag | Effect |
|---|---|
--typed |
Emit Luau type annotations (local x: number = 5) |
--fast |
Skip py_bool() truthiness shim (Lua semantics) |
--no-runtime |
Don't prepend runtime require() |
--compile-time |
Enable build-time Python execution (Macros) |
--debug |
Enable detailed diagnostic logging |
--verbose |
Print detailed build output |
| Command | Description |
|---|---|
rpy transpile <src> <out> |
Transpile files/directories (Alias: build) |
rpy validate <src> |
Validate without writing output (Alias: check) |
rpy setup [dir] |
Scaffold a new RPy project (Alias: init) |
rpy live <src> <out> |
Real-time Dev Server & Studio Sync (Alias: watch) |
Project Structure
RPy/
├── transpiler/ # Compiler pipeline
│ ├── parser.py # Python source → AST
│ ├── transformer.py # Scope analysis, import resolution
│ ├── generator.py # AST → Luau code generation
│ ├── type_inferrer.py # Type inference for --typed mode
│ ├── errors.py # Custom error hierarchy
│ └── ast_utils.py # AST utility functions
├── runtime/
│ └── python_runtime.lua # Luau runtime helpers (40+ functions)
├── sdk/
│ └── roblox.py # IDE stubs for Roblox APIs (30+ services)
├── cli/
│ └── main.py # CLI entry point (build/check/init/watch)
├── examples/ # Example RPy scripts
├── docs/ # Documentation
└── tests/ # 280+ unit & integration tests
Documentation
docs/supported_subset.md— Exact Python feature listdocs/semantic_map.md— Python → Luau mapping referencedocs/runtime_api.md— Runtime helper function signatures
License
MIT
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 rpy_roblox-1.0.0.tar.gz.
File metadata
- Download URL: rpy_roblox-1.0.0.tar.gz
- Upload date:
- Size: 162.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b4f4c947670451ab1d2085de7f80344222bf74ed1225788a958a24f37acb041
|
|
| MD5 |
049cb1aa6d5981437d5cfec954efb5ea
|
|
| BLAKE2b-256 |
47cebca2474b82333d0dba833e8825205aaf115c17ca80642cef01124ad0a5fb
|
Provenance
The following attestation bundles were made for rpy_roblox-1.0.0.tar.gz:
Publisher:
publish.yml on Tin65924/RPy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rpy_roblox-1.0.0.tar.gz -
Subject digest:
2b4f4c947670451ab1d2085de7f80344222bf74ed1225788a958a24f37acb041 - Sigstore transparency entry: 1188016642
- Sigstore integration time:
-
Permalink:
Tin65924/RPy@96fbe942d3abf9db70dc8912e56aaddf660dd002 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Tin65924
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@96fbe942d3abf9db70dc8912e56aaddf660dd002 -
Trigger Event:
release
-
Statement type:
File details
Details for the file rpy_roblox-1.0.0-py3-none-any.whl.
File metadata
- Download URL: rpy_roblox-1.0.0-py3-none-any.whl
- Upload date:
- Size: 174.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43a856fe5de8e8352b45c599542197f47a1fac537db11950aac381173bb726dc
|
|
| MD5 |
c9b0e65a88888956ce71d9eb4f935dcb
|
|
| BLAKE2b-256 |
4fbbe404ae5d5f27b3ac223b7394d6d8ea645561e229b787ef5ff54c2c87b9ec
|
Provenance
The following attestation bundles were made for rpy_roblox-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on Tin65924/RPy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rpy_roblox-1.0.0-py3-none-any.whl -
Subject digest:
43a856fe5de8e8352b45c599542197f47a1fac537db11950aac381173bb726dc - Sigstore transparency entry: 1188016649
- Sigstore integration time:
-
Permalink:
Tin65924/RPy@96fbe942d3abf9db70dc8912e56aaddf660dd002 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/Tin65924
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@96fbe942d3abf9db70dc8912e56aaddf660dd002 -
Trigger Event:
release
-
Statement type: