Skip to main content

Python extension to run WebAssembly binaries

Project description

Wasmer logo Wasmer Python PyPI version Wasmer Python Documentation Wasmer PyPI downloads Wasmer Slack Channel

A complete and mature WebAssembly runtime for Python based on Wasmer.

Features:

  • Easy to use: The wasmer API mimics the standard WebAssembly API,
  • Fast: wasmer executes the WebAssembly modules as fast as possible, close to native speed,
  • Safe: All calls to WebAssembly will be fast, but more importantly, completely safe and sandboxed,
  • Modular: wasmer can compile the WebAssembly modules with different engines or compiler.

Documentation: browse the detailed API documentation full of examples.

Examples as tutorials: browse the examples/ directory, it's the best place for a complete introduction!

Quick Introduction

The wasmer package brings the required API to execute WebAssembly modules. In a nutshell, wasmer compiles the WebAssembly module into compiled code, and then executes it. wasmer is designed to work in various environments and platforms: From nano single-board computers to large and powerful servers, including more exotic ones. To address those requirements, Wasmer provides 2 engines and 3 compilers.

Succinctly, an engine is responsible to drive the compilation and the execution of a WebAssembly module. By extension, a headless engine can only execute a WebAssembly module, i.e. a module that has previously been compiled, or compiled, serialized and deserialized. By default, the wasmer package comes with 2 headless engines:

  1. wasmer.engine.JIT, the compiled machine code lives in memory,
  2. wasmer.engine.Native, the compiled machine code lives in a shared object file (.so, .dylib, or .dll), and is natively executed.

Because wasmer does not embed compilers in its package, engines are headless, i.e. they can't compile WebAssembly module; they can only execute them. Compilers live in their own standalone packages. Let's briefly introduce them:

Compiler package Description PyPi
wasmer_compiler_singlepass Super fast compilation times, slower execution times. Not prone to JIT-bombs. Ideal for blockchains On PyPi Downloads
wasmer_compiler_cranelift Fast compilation times, fast execution times. Ideal for development On PyPi Downloads
wasmer_compiler_llvm Slow compilation times, very fast execution times (close to native, sometimes faster). Ideal for Production On PyPi Downloads

We generally recommend wasmer_compiler_cranelift for development purposes and wasmer_compiler_llvm in production.

Learn more by reading the documentation of the wasmer.engine submodule.

Install

To install the wasmer Python package, and let's say the wasmer_compiler_cranelift compiler, just run those commands in your shell:

$ pip install wasmer==1.1.0
$ pip install wasmer_compiler_cranelift==1.1.0

And you're ready to get fun!

Example

We highly recommend to read the examples/ directory, which contains a sequence of examples/tutorials. It's the best place to learn by reading examples.

But for the most eager of you, and we know you're numerous you mischievous, there is a quick toy program in examples/appendices/simple.rs, written in Rust:

#[no_mangle]
pub extern fn sum(x: i32, y: i32) -> i32 {
    x + y
}

After compilation to WebAssembly, the examples/appendices/simple.wasm binary file is generated. (Download it).

Then, we can execute it in Python:

from wasmer import engine, Store, Module, Instance
from wasmer_compiler_cranelift import Compiler

# Let's define the store, that holds the engine, that holds the compiler.
store = Store(engine.JIT(Compiler))

# Let's compile the module to be able to execute it!
module = Module(store, open('simple.wasm', 'rb').read())

# Now the module is compiled, we can instantiate it.
instance = Instance(module)

# Call the exported `sum` function.
result = instance.exports.sum(5, 37)

print(result) # 42!

And then, finally, enjoy by running:

$ python examples/appendices/simple.py

Development

The Python extension is written in Rust, with pyo3 and maturin.

First, you need to install Rust and Python. We will not make you the affront to explain to you how to install Python (if you really need, check pyenv). For Rust though, we advise to use rustup, then:

$ rustup install stable

To set up your environment, you'll need just, and then, install the prelude of this project:

$ cargo install just
$ just --list # to learn about all the available recipes
$ just prelude

It will install pyo3 and maturin for Python and for Rust. It will also install virtualenv.

Then, simply run:

$ source .env/bin/activate
$ just build api
$ just build compiler-cranelift
$ python examples/appendices/simple.py

Supported platforms

We try to provide wheels for as many platforms and architectures as possible. For the moment, here are the supported platforms and architectures:

Platform Architecture Triple Packages
Linux amd64 x86_64-unknown-linux-gnu wasmer
wasmer_compiler_singlepass
wasmer_compiler_cranelift
wasmer_compiler_llvm
aarch64 aarch64-unknown-linux-gnu wasmer
wasmer_compiler_singlepass 1
wasmer_compiler_cranelift
wasmer_compiler_llvm
Darwin amd64 x86_64-apple-darwin wasmer
wasmer_compiler_singlepass
wasmer_compiler_cranelift
wasmer_compiler_llvm
Windows amd64 x86_64-pc-windows-msvc wasmer
wasmer_compiler_singlepass
wasmer_compiler_cranelift
wasmer_compiler_llvm 2

Notes:

  • 1 wasmer_compiler_singlepass does not support aarch64 for the moment
  • 2 wasmer_compiler_llvm is not packaging properly on Windows for the moment

Wheels are all built for the following Python versions:

  • Python 3.7,
  • Python 3.8.
  • Python 3.9.
  • Python 3.10,
Learn about the “fallback” py3-none-any wheel

py3-none-any.whl

A special wasmer-$(version)-py3-none-any wheel is built as a fallback. The wasmer libray will be installable, but it will raise an ImportError exception saying that “Wasmer is not available on this system”.

This wheel will be installed if none matches before (learn more by reading the PEP 425, Compatibility Tags for Built Distributions).

Testing

Build all the packages and run the tests:

$ just build-all
$ just test

What is WebAssembly?

Quoting the WebAssembly site:

WebAssembly (abbreviated Wasm) is a binary instruction format for a stack-based virtual machine. Wasm is designed as a portable target for compilation of high-level languages like C/C++/Rust, enabling deployment on the web for client and server applications.

About speed:

WebAssembly aims to execute at native speed by taking advantage of common hardware capabilities available on a wide range of platforms.

About safety:

WebAssembly describes a memory-safe, sandboxed execution environment […].

License

The entire project is under the MIT License. Please read the LICENSE file.

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

wasmer-1.1.0-py3-none-any.whl (1.6 kB view details)

Uploaded Python 3

wasmer-1.1.0-cp310-none-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10 Windows x86-64

wasmer-1.1.0-cp310-cp310-manylinux_2_24_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.24+ x86-64

wasmer-1.1.0-cp310-cp310-macosx_10_7_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10 macOS 10.7+ x86-64

wasmer-1.1.0-cp39-none-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.9 Windows x86-64

wasmer-1.1.0-cp39-cp39-manylinux_2_24_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.24+ x86-64

wasmer-1.1.0-cp39-cp39-macosx_11_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

wasmer-1.1.0-cp39-cp39-macosx_10_7_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9 macOS 10.7+ x86-64

wasmer-1.1.0-cp38-none-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.8 Windows x86-64

wasmer-1.1.0-cp38-cp38-manylinux_2_24_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.24+ x86-64

wasmer-1.1.0-cp38-cp38-macosx_10_7_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.8 macOS 10.7+ x86-64

wasmer-1.1.0-cp37-none-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.7 Windows x86-64

wasmer-1.1.0-cp37-cp37m-manylinux_2_24_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.24+ x86-64

wasmer-1.1.0-cp37-cp37m-macosx_10_7_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.7m macOS 10.7+ x86-64

File details

Details for the file wasmer-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: wasmer-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 1.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2caf8c67feae9cd4246421551036917811c446da4f27ad4c989521ef42751931
MD5 ffdb0cf30e3528769d055b56e60a9073
BLAKE2b-256 396b30e25924cae7add377f5601e71c778e9a1e515c7a58291f52756c1bb7e87

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp310-none-win_amd64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp310-none-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp310-none-win_amd64.whl
Algorithm Hash digest
SHA256 d0d93aec6215893d33e803ef0a8d37bf948c585dd80ba0e23a83fafee820bc03
MD5 cae83dc46379ae9e7f71feaa6d4da6a2
BLAKE2b-256 2470ca7bf7a3f85d8de745eca73e40bc83cf86bb52ea494b33721fc0572889ab

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp310-cp310-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp310-cp310-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.10, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp310-cp310-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 ab1ae980021e5ec0bf0c6cdd3b979b1d15a5f3eb2b8a32da8dcb1156e4a1e484
MD5 fce28ee1bf37ec5c254d94bee67c3c64
BLAKE2b-256 a7793f53cf611cbdd04a9b9997bf3ad18e5602350f90d404c162fbf3112684f2

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp310-cp310-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp310-cp310-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.10, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp310-cp310-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 c2af4b907ae2dabcac41e316e811d5937c93adf1f8b05c5d49427f8ce0f37630
MD5 453d687c73340fa0eb7495bf545292c8
BLAKE2b-256 cf0a9e5efd92e5cf24d5c08030b4f76dcdf10cbc55c639bbf4df8aeb0c76d448

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp39-none-win_amd64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp39-none-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp39-none-win_amd64.whl
Algorithm Hash digest
SHA256 a0a4730ec4907a4cb0d9d4a77ea2608c2c814f22a22b73fc80be0f110e014836
MD5 4737eb60ac0b839862563a13b922231e
BLAKE2b-256 b032f6978008cdfd7b932a9ae7dc233688f0a4db29b73b59c23d9182731d57a3

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp39-cp39-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp39-cp39-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.9, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp39-cp39-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 c0b37117f6d3ff51ee96431c7d224d99799b08d174e30fcd0fcd7e2e3cb8140c
MD5 a4d98f3ff8a72b3170e8d49ddd72df40
BLAKE2b-256 dda66f9cf77500073969c96afd626857694418d707cc97c15705665250420c67

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aa112198b743cff2e391230436813fb4b244a24443e37866522b7197e3a034da
MD5 155b264858ad8316084f20b34880a706
BLAKE2b-256 f7d1502e40f1c63c8ddcfc9c5dee41af1c109c0cc0373e176c476cf46c205b21

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp39-cp39-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp39-cp39-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.9, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp39-cp39-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 ee442f0970f40ec5e32011c92fd753fb2061da0faa13de13fafc730c31be34e3
MD5 f3277357137c045fcfecdcc6ac6135d4
BLAKE2b-256 1242142b95b68e3cb9f1b49174677e1861575a47fdac0221f46d9a8631d2b469

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp38-none-win_amd64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp38-none-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 20b5190112e2e94a8947967f2bc683c9685855d0f34130d8434c87a55216a3bd
MD5 afaa19be3102112f4668f9deed0090a6
BLAKE2b-256 7fd71d346733b1c32dc6a95053e09baa9979322dc09fd5273b3db328c547f059

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp38-cp38-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp38-cp38-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.8, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp38-cp38-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 b9e5605552bd7d2bc6337519b176defe83bc69b98abf3caaaefa4f7ec231d18a
MD5 1549f14af83dce9a491e617455227a60
BLAKE2b-256 93f597ecad043c138f48c37ce4f0fa782831b5d2dbb3f7d80031f07105b9e7ba

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp38-cp38-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.8, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 214d9a3cfb577ea9449eb2b5f13adceae34c55365e4c3d930066beb86a7f67bc
MD5 e34b6cf9747334bcc7732aea8b52808f
BLAKE2b-256 a177e8f9b4e32fcdf2d54dfab67e26cc7557a094e85817281e8f203294d4ea52

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp37-none-win_amd64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp37-none-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.7, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 a182a6eca9b46d895b4985fc822fab8da3d2f84fab74ca27e55a7430a7fcf336
MD5 c29a7ac98d9f5cda38a598c10bec264d
BLAKE2b-256 d6389f92d6a54aa11fcb74e3dd1a790a2ed531ff267ed3d2e256480ad00ce26b

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp37-cp37m-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp37-cp37m-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp37-cp37m-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 85e6a5bf44853e8e6a12e947ee3412da9e84f7ce49fc165ba5dbd293e9c5c405
MD5 8fb5a3cd7148fb716f869510b8b73d3b
BLAKE2b-256 5c7f9b96442cc3984baa7a5e5651901202176cb30fe879fef0c4f79020566262

See more details on using hashes here.

File details

Details for the file wasmer-1.1.0-cp37-cp37m-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: wasmer-1.1.0-cp37-cp37m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.7m, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wasmer-1.1.0-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 1e63d16bd6e2e2272d8721647831de5c537e0bb08002ee6d7abf167ec02d5178
MD5 b1a259efaa6e55f138ae85f5fabcccc0
BLAKE2b-256 7121091c53b34e312bea376cb4a5806834f84e674e7f78d52eb92423cedf8a5f

See more details on using hashes here.

Supported by

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