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.7.0-cp37-abi3-win_amd64.whl (32.1 MB view details)

Uploaded CPython 3.7+Windows x86-64

componentize_py-0.7.0-cp37-abi3-manylinux_2_28_x86_64.whl (35.1 MB view details)

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

componentize_py-0.7.0-cp37-abi3-manylinux_2_28_aarch64.whl (34.9 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.28+ ARM64

componentize_py-0.7.0-cp37-abi3-macosx_11_0_arm64.whl (32.9 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

componentize_py-0.7.0-cp37-abi3-macosx_10_12_x86_64.whl (33.1 MB view details)

Uploaded CPython 3.7+macOS 10.12+ x86-64

File details

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

File metadata

File hashes

Hashes for componentize_py-0.7.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ecaac8a41668c89d6b475bf520d057de6933b6833d39642c3e1bf45896c21421
MD5 c1bdbabe398e51d0487612f233b249c6
BLAKE2b-256 27da6fde3c717cdbe779144ab9d3312ebe1caf7ae0bc802c335e7b6a9ac4388d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for componentize_py-0.7.0-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8ac01302eef3dd0774be2c527a8e00b2cc25dcfcaf46453c59b2805ef274f6f3
MD5 1c791e0d2bfb61edb19dc536c2eacf9e
BLAKE2b-256 1732be4fdafe779157ad546e738060c307e4eb37e72c709f80e432b3c2d572c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for componentize_py-0.7.0-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 0e681f06b488cdfefbca7a44f2d30e9cf0ed6b3a23e713ff5d34a725df14c570
MD5 60f3fac3b89ec0a56aab26309b0747eb
BLAKE2b-256 4e5da57cbb5675f51c135662e23efa1bc4c3322fb155cad1bda9d20c6b575e9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for componentize_py-0.7.0-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 76a471ddc171ea22db875458d1b1660576aa35ece2c3a214abec589a45e6d7c0
MD5 3814c493dc1b6d1c94c4ceecf673f12d
BLAKE2b-256 1de57c156da318e63d308968b7d3eedadd4f62afc7205165debcee12d6c2dc27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for componentize_py-0.7.0-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e7ca5d5d0e4da10b819a7a0e0ae1cbd1a1f485f334c342989077a3bba3d7ee85
MD5 0c6c213a9d54ecbf1a93e2ece02d1dcd
BLAKE2b-256 69ebee56d52699e7af0cc17d35b2a58aea4756b3bfc04fd09493632d3e98b47b

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