Skip to main content

Tool to package Python applications as WebAssembly components

Project description

componentize-py

A Bytecode Alliance project

This is a tool to convert a Python application to a WebAssembly component. It takes the following as input:

  • a WIT file or directory
  • the name of a WIT world defined in the above file or directory
  • the name of a Python module which targets said world
  • a list of directories in which to find the Python module and its dependencies

The output is a component which may be run using e.g. wasmtime.

Getting Started

First, install Python 3.10 or later and pip if you don't already have them. Then, install componentize-py:

pip install componentize-py

Next, create or download the WIT world you'd like to target, e.g.:

cat >hello.wit <<EOF
package example:hello;
world hello {
  export hello: func() -> string;
}
EOF

If you're using an IDE or just want to examine the bindings produced for the WIT world, you can generate them using the bindings subcommand:

componentize-py -d hello.wit -w hello bindings .

Then, use the hello module produced by the command above to write your app:

cat >app.py <<EOF
import hello
class Hello(hello.Hello):
    def hello(self) -> str:
        return "Hello, World!"
EOF

And finally generate the component:

componentize-py -d hello.wit -w hello componentize app -o app.wasm

See the examples directories for more examples, including various ways to run the components you've created.

For an example of running a sandboxed Python guest within a Python host, see component-sandbox-demo.

Known Limitations

Currently, the application can only import dependencies during build time, which means any imports used at runtime must be resolved at the top level of the application module. For example, if x is a module with a submodule named y the following may not work:

import x

class Hello(hello.Hello):
    def hello(self) -> str:
        return x.y.foo()

That's because importing x does not necessarily resolve y. This can be addressed by modifying the code to import y at the top level of the file:

from x import y

class Hello(hello.Hello):
    def hello(self) -> str:
        return y.foo()

This limitation is being tracked as issue #23.

See the issue tracker for other known issues.

Contributing

See CONTRIBUTING.md for details on how to contribute to the project and build it from source.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

componentize_py-0.9.2-cp37-abi3-win_amd64.whl (35.4 MB view details)

Uploaded CPython 3.7+Windows x86-64

componentize_py-0.9.2-cp37-abi3-manylinux_2_28_x86_64.whl (38.1 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.28+ x86-64

componentize_py-0.9.2-cp37-abi3-manylinux_2_28_aarch64.whl (37.8 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.28+ ARM64

componentize_py-0.9.2-cp37-abi3-macosx_11_0_arm64.whl (36.0 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

componentize_py-0.9.2-cp37-abi3-macosx_10_12_x86_64.whl (36.2 MB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

Details for the file componentize_py-0.9.2-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for componentize_py-0.9.2-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4034f290abb2f386dc06effc5f0fa6c4c20276db6987afaae0270540274bf657
MD5 c8f2cd2ce4459d7a0cf6eda0fc1df314
BLAKE2b-256 0033ae048a0f8de857674cd890bcf83dce3f4de720e95921dd2c2a021d63b1ae

See more details on using hashes here.

File details

Details for the file componentize_py-0.9.2-cp37-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for componentize_py-0.9.2-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 496863114167b21bf2af01290ef7c704724f63c4836bf656268ca8b4e973e5a4
MD5 b675c6c0a360be6470b1e84b215d510b
BLAKE2b-256 8673d94578c5e0b8f818c02c787bf449f670af87565391ae23c4a668484365f7

See more details on using hashes here.

File details

Details for the file componentize_py-0.9.2-cp37-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for componentize_py-0.9.2-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8204e0a27abe4c625013f89587e80222debf2f3c333dab24c7c77d9c1b3530af
MD5 e891f8efc0e3cb4667d99952d4e70873
BLAKE2b-256 a96df8aa9a3094ad323c9d81cd9fee83c90c61db5d759d33ccaafe9e7fe76479

See more details on using hashes here.

File details

Details for the file componentize_py-0.9.2-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for componentize_py-0.9.2-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d648e318f3dc5bc137858923e997516fcbeec70f74355044ff2f8d2ea824ea4e
MD5 59873e0f72449bb6380b4ea0f3377a49
BLAKE2b-256 863624ed136d282ca901728fc5f34693da5d413bcee3525e080a42278fae9817

See more details on using hashes here.

File details

Details for the file componentize_py-0.9.2-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for componentize_py-0.9.2-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4166d280ec0f834cf5583f0233abcad3e1ccd773ab2ad1616819d48552b8dbb4
MD5 88cdcebecb2850dd699f1fad59f7370f
BLAKE2b-256 6e490ba3a0ec32f3b9eb4da3c4196c898916da1bb72ec7b60ddb7a21753b57f2

See more details on using hashes here.

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