Welcome to the new Golem Cloud Docs! 👋
Documentation
Python Language Guide
Building Components

Building Golem Components in Python

Building Golem components written in Python involves two steps:

Package the Python code into a WASM component

The componentize subcommand of the componentize-py tool packages the Python code and the Python interpreter into a single WebAssembly component:

$ componentize-py componentize main -o py_example.wasm

Note that the componentize-py tool respects the VIRTUAL_ENV environment variable, so make sure to activate the virtualenv if there are any Python dependencies used by your component.

Reducing the size of the component

The output of compoenntize-py is large. It is possible to strip some parts of it to reduce the size by about 50% using the wasm-tools strip command:

$ wasm-tools strip -a py_example.wasm -o py_example_stripped.wasm

Generate the Python bindings from the WIT files

The bindings subcommand of the componentize-py tool generates the module containing the generated bindings:

$ componentize-py bindings generated_bindings

This will generate bindings into the bindings directory. Make sure to not actually use these bindings to invoke imported functions, as they don't have any implementation.