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
wasmer_compiler_cranelift Fast compilation times, fast execution times. Ideal for development On PyPi
wasmer_compiler_llvm Slow compilation times, very fast execution times (close to native, sometimes faster). Ideal for Production On PyPi

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.0.0a3
$ pip install wasmer_compiler_cranelift==1.0.0a3

And you're ready to get fun!

Example

We highly recommend to the 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 excecute 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
$ just python-run examples/appendices/simple.py

If you need to interact with Python, or run a specific file, use the following commands:

$ just python-run
$ just python-run file/to/run.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
Linux amd64 x86_64-unknown-linux-gnu
Linux aarch64 aarch64-unknown-linux-gnu
Darwin amd64 x86_64-apple-darwin
Windows amd64 x86_64-pc-windows-msvc

Wheels are all built for the following Python versions:

  • Python 3.5,
  • Python 3.6,
  • Python 3.7,
  • Python 3.8.
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

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

wasmer-1.0.0a3-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

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

Uploaded CPython 3.8Windows x86-64

wasmer-1.0.0_alpha3-cp38-cp38-manylinux1_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.8

wasmer-1.0.0_alpha3-cp38-cp38-macosx_10_7_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8macOS 10.7+ x86-64

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

Uploaded CPython 3.7Windows x86-64

wasmer-1.0.0_alpha3-cp37-cp37m-manylinux1_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.7m

wasmer-1.0.0_alpha3-cp37-cp37m-macosx_10_7_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.7mmacOS 10.7+ x86-64

wasmer-1.0.0_alpha3-cp36-none-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.6Windows x86-64

wasmer-1.0.0_alpha3-cp36-cp36m-manylinux1_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.6m

wasmer-1.0.0_alpha3-cp36-cp36m-macosx_10_7_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.6mmacOS 10.7+ x86-64

wasmer-1.0.0_alpha3-cp35-none-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.5Windows x86-64

wasmer-1.0.0_alpha3-cp35-cp35m-manylinux1_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.5m

wasmer-1.0.0_alpha3-cp35-cp35m-macosx_10_7_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.5mmacOS 10.7+ x86-64

File details

Details for the file wasmer-1.0.0a3-py3-none-any.whl.

File metadata

  • Download URL: wasmer-1.0.0a3-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for wasmer-1.0.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 ab7233e4bc6adb80713ab63a94568a3dd42fa00130a56ab5495f322de96e6c49
MD5 8ba5f2851c0b647d9a598f046b837b98
BLAKE2b-256 87982d6ec52ddbeb8fff34e1e6d7e317c4fc710266157cbc547acfe02ca9f8f2

See more details on using hashes here.

File details

Details for the file wasmer-1.0.0_alpha3-cp38-none-win_amd64.whl.

File metadata

  • Download URL: wasmer-1.0.0_alpha3-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.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for wasmer-1.0.0_alpha3-cp38-none-win_amd64.whl
Algorithm Hash digest
SHA256 7f9c2c88787f381d2d6a1f19a436a526f55dfd816443e9699be8f34d8fcd6047
MD5 07b963c4a0522c8d371f022afb8aeef3
BLAKE2b-256 e713f455cc51b86267a57a0d98c4781f2f92d984978d12313df7ff1162864f67

See more details on using hashes here.

File details

Details for the file wasmer-1.0.0_alpha3-cp38-cp38-manylinux1_x86_64.whl.

File metadata

  • Download URL: wasmer-1.0.0_alpha3-cp38-cp38-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.8
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for wasmer-1.0.0_alpha3-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f1dad9a579ce856eb0600141bb890feb8c4ef9be0fc668db2e14892c026ab6be
MD5 1e3fe5738db08916c96cc4be8bb56dd5
BLAKE2b-256 8cd9e8c268d3721cf688f6c1e2e90e404b2e61a877a7d71d198dbe7bb578eea0

See more details on using hashes here.

File details

Details for the file wasmer-1.0.0_alpha3-cp38-cp38-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: wasmer-1.0.0_alpha3-cp38-cp38-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.8, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for wasmer-1.0.0_alpha3-cp38-cp38-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 8853cc8d899c1cbc15aa14481f08b1ae1cecfccf0486dba16d971584ff78fd1f
MD5 ab31f633481185bf6d81618de1bc3b8a
BLAKE2b-256 825ca10a5e3ab154295670c4ffd91408ebab47b6599344f43b665db9bf1ad6c5

See more details on using hashes here.

File details

Details for the file wasmer-1.0.0_alpha3-cp37-none-win_amd64.whl.

File metadata

  • Download URL: wasmer-1.0.0_alpha3-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.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.9

File hashes

Hashes for wasmer-1.0.0_alpha3-cp37-none-win_amd64.whl
Algorithm Hash digest
SHA256 929f592f8cbcafcfef68cb7287771723d7b94b811565bd59f31f635b3929c14b
MD5 92ab795fab64885a413308b87dbc0aa4
BLAKE2b-256 9d077c1ca030ed74253cd9f45ecb5e80c5a4155adb346e047afbad99c03b286c

See more details on using hashes here.

File details

Details for the file wasmer-1.0.0_alpha3-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

  • Download URL: wasmer-1.0.0_alpha3-cp37-cp37m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.7m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.9

File hashes

Hashes for wasmer-1.0.0_alpha3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e80105ae29dc513913b73d18196f900bb15f90a2252f3ade2af5be197f073aa1
MD5 b5ef2b4785a9b7bd3519be8bf6d83270
BLAKE2b-256 4cb4a263ae4a99fdea306c3bbc96de340cc0a9d5353f5544f7be6966e29e4cdf

See more details on using hashes here.

File details

Details for the file wasmer-1.0.0_alpha3-cp37-cp37m-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: wasmer-1.0.0_alpha3-cp37-cp37m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.7m, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.7.9

File hashes

Hashes for wasmer-1.0.0_alpha3-cp37-cp37m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 f2c38072cabc8191a94d652b792ef3a318e4755a45a93cd7d6884ebcb67e74ce
MD5 b55757829234d4d25e6d827ffb02c9b3
BLAKE2b-256 8d3f228bdb7c29fc1bdcc47c60e415eb04fba32ea1ed99f1331e63c800f4cb58

See more details on using hashes here.

File details

Details for the file wasmer-1.0.0_alpha3-cp36-none-win_amd64.whl.

File metadata

  • Download URL: wasmer-1.0.0_alpha3-cp36-none-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.6, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.8

File hashes

Hashes for wasmer-1.0.0_alpha3-cp36-none-win_amd64.whl
Algorithm Hash digest
SHA256 31ec40a4f90cc69dd76782cc74925b434e2071335560c4c088cc85af57a178ef
MD5 3eedddf24d537790115dc439131bf9c2
BLAKE2b-256 0ab75ebc50ad32915c43fd5aa9ecc7ea54b8033b357a94a5e0156b253fb302c3

See more details on using hashes here.

File details

Details for the file wasmer-1.0.0_alpha3-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

  • Download URL: wasmer-1.0.0_alpha3-cp36-cp36m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.6m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.12

File hashes

Hashes for wasmer-1.0.0_alpha3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 aaae0c41ba290cb540e38b5f98edb3b3a39c6605ec2f751f9fb331f28c88ec41
MD5 264c2063892d81b3ca9038e9b0ba6735
BLAKE2b-256 74e4a276c7e9b2045560517e5bd503847a1b5de80d5cd9825c4e57246879a0f2

See more details on using hashes here.

File details

Details for the file wasmer-1.0.0_alpha3-cp36-cp36m-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: wasmer-1.0.0_alpha3-cp36-cp36m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.6m, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.12

File hashes

Hashes for wasmer-1.0.0_alpha3-cp36-cp36m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 b63c7fc3df97660a545efa34c9d6f194240b5cf0d7461ccd34c9dd254c7502c9
MD5 cb9ca2e5617f887bb7f8a867b6a0a392
BLAKE2b-256 221cb7d2c865b8075717f89cefef45e00cfca3cdb3578f1da39ee8570e7864d7

See more details on using hashes here.

File details

Details for the file wasmer-1.0.0_alpha3-cp35-none-win_amd64.whl.

File metadata

  • Download URL: wasmer-1.0.0_alpha3-cp35-none-win_amd64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: CPython 3.5, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.5.4

File hashes

Hashes for wasmer-1.0.0_alpha3-cp35-none-win_amd64.whl
Algorithm Hash digest
SHA256 2f774b8112a957a9225f7c2fcea56bf1fb41d6f39083dbf30652db987fe3f65c
MD5 752a7275739a121645d14163dc6a1824
BLAKE2b-256 06bacfc77a9a16804adb40d4e16692de8e23f6aeca87bf5d069e18ef9241be82

See more details on using hashes here.

File details

Details for the file wasmer-1.0.0_alpha3-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

  • Download URL: wasmer-1.0.0_alpha3-cp35-cp35m-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.5m
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.5.10

File hashes

Hashes for wasmer-1.0.0_alpha3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6037f935e248b807f4978fb5b34644427a26cc892975f87c0223458d5ffbcc7e
MD5 098958f931952e439963713079986246
BLAKE2b-256 17464a39be2a47394de352b959d488842d41339e46ce748050afff79b3da3377

See more details on using hashes here.

File details

Details for the file wasmer-1.0.0_alpha3-cp35-cp35m-macosx_10_7_x86_64.whl.

File metadata

  • Download URL: wasmer-1.0.0_alpha3-cp35-cp35m-macosx_10_7_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: CPython 3.5m, macOS 10.7+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.5.10

File hashes

Hashes for wasmer-1.0.0_alpha3-cp35-cp35m-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 9b845e9395ef976be33ddc32074bcc9f5413fcf94c1883c47767e85915e72dae
MD5 5e461b57710c2409eea497c84c66920d
BLAKE2b-256 9ec452f9320fa8adbe9023899f08504d8ef34d1caae3c49caf9f92bea0bb2673

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