Skip to main content

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 specialized for 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 table library.
  • Async & Task: Built-in task module support for task.wait(), task.spawn(), and task.delay().
  • Standard Library: Native mapping for math, string, table, coroutine, and debug libraries.
  • Roblox SDK: Integrated roblox stubs for 100+ services and classes with autocompletion support.
  • Modern OOP: Single inheritance classes with metatable-based state management.
  • Error Handling: Full try / except / finally blocks transpiled to Luau pcall.
  • Package Management: Native Wally integration via rpy install for 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

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rpy_roblox-1.0.0.tar.gz (162.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rpy_roblox-1.0.0-py3-none-any.whl (174.6 kB view details)

Uploaded Python 3

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

Hashes for rpy_roblox-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2b4f4c947670451ab1d2085de7f80344222bf74ed1225788a958a24f37acb041
MD5 049cb1aa6d5981437d5cfec954efb5ea
BLAKE2b-256 47cebca2474b82333d0dba833e8825205aaf115c17ca80642cef01124ad0a5fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpy_roblox-1.0.0.tar.gz:

Publisher: publish.yml on Tin65924/RPy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for rpy_roblox-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43a856fe5de8e8352b45c599542197f47a1fac537db11950aac381173bb726dc
MD5 c9b0e65a88888956ce71d9eb4f935dcb
BLAKE2b-256 4fbbe404ae5d5f27b3ac223b7394d6d8ea645561e229b787ef5ff54c2c87b9ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for rpy_roblox-1.0.0-py3-none-any.whl:

Publisher: publish.yml on Tin65924/RPy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page