Skip to main content
The transpile command converts a Python function into C++ source code. You can then compile the generated source code into a library or executable.

Usage

# Transpile a Python function
$ muna transpile [OPTIONS] PATH
The provided path can either be a path to a Python module; or a URL pointing to a Python module. There must be a function decorated with @compile.

Specifying the Output Directory

Use the --output flag to write the generated sources to a given directory:
# Output to a custom directory
$ muna transpile  --output ./generated greeting.py
The provided directory must not already exist on the file system.

Transpiling from GitHub

You can transpile Python files directly from GitHub:
# Transpile from a GitHub URL
$ muna transpile --trust-remote-code https://github.com/muna-ai/muna-predictors/blob/main/python-coverage/fstring.py
When using --trust-remote-code, the CLI will download and execute code from the remote URL. Only use this option with code sources you trust.

Using the Generated Code

The generated code defines a header which can be used in C++ libraries and applications; along with an example command-line application that runs the compiled function. The muna transpile command will write a self-contained header file (*.hpp) along with a CMakeLists.txt file to the output directory.

Running the Example Code

Build the example application using cmake:
# 🔥 Build the example application
$ cmake -B build && cmake --build build
Building the example application requires cmake to be installed, along with a compiler toolchain for the current system (e.g. Visual Studio, Xcode, etc).
Once compiled, you can then run the example app in the command line:
# 🚀 Run the example app
$ ./example --help

Using the Library

You can also use the transpiled function as a library in a C++ target:
CMakeLists.txt
# Include the transpiled function
include(generated)

# Link against the transpiled function
target_link_libraries(
    my_app PRIVATE
    greeting::greeting
)
For most use cases, you should use muna compile instead, which handles transpilation, compilation, and deployment in a single step.