Skip to main content

Python bindings for the Wasmer sandbox SDK

Project description

Wasmer SDK for Python

Run Wasmer packages in lightweight, composable sandboxes from Python. The public API is handwritten and typed; a Python-independent UniFFI library calls the Rust wasmer-sdk underneath.

Install

pip install wasmer-sdk

Published wheels support macOS and Linux on arm64 and x86_64. One wheel works across supported Python 3 versions on the same platform because the native boundary does not use the CPython ABI.

Run Python inside Wasmer

import asyncio

from wasmer_sdk import Wasmer


async def main() -> None:
    wasmer = Wasmer()
    sandbox = await wasmer.sandboxes.create(
        packages=["python/python@3.13.5"],
        files={
            "main.py": "print(sum(n * n for n in range(10)))",
        },
    )
    output = await sandbox.command(
        "python", ["/workspace/main.py"]
    ).run()
    print(output.text())


asyncio.run(main())

Constructing Wasmer() is synchronous. Operations that perform I/O are awaited. A wasmer instance can be reused across multiple sandboxes. For long-lived applications and tests, use async with for deterministic cleanup:

async def main() -> None:
    async with Wasmer() as wasmer:
        sandbox = await wasmer.sandboxes.create(
            packages=["python/python@3.13.5"],
        )
        async with sandbox:
            output = await sandbox.command(
                "python", ["--version"]
            ).run()
            print(output.text())


asyncio.run(main())

run() raises ProcessExitError for a non-zero exit, termination, or timeout by default. Pass check=False when the outcome is expected and should be inspected as an Output. Spawned-process wait() remains unchecked by default.

Live processes expose asynchronous stdin, stdout, and stderr streams. process.stdout.lines() is an async iterator suitable for servers and agent loops.

Networking and caching

Network access is an explicit sandbox capability:

sandbox = await wasmer.sandboxes.create(
    packages=["wasmer/edgejs-quickjs@0.1.0"],
    network="host",
)

Packages and native compiled artifacts are cached in .wasmer by default:

wasmer = Wasmer(cache_root=".cache/wasmer")

The registry and downloaded package layout is shared with Node.js and Rust. Compiled artifacts remain target-specific.

Examples

Run the same guest programs used by the JavaScript and Rust SDK examples:

python3 python/examples/python.py
python3 python/examples/multiple_runtimes.py
python3 python/examples/edgejs_http.py
python3 python/examples/postgres_psql.py

The PostgreSQL example requires psql on PATH; pass --psql /path/to/psql otherwise. The common guest inputs live in ../fixtures/.

Build and test locally

From the repository root, install Rust 1.94 and build the UniFFI module:

rustup toolchain install 1.94.0 --profile minimal
python3 python/scripts/build.py --release

Run the Python suite against that local module:

PYTHONPATH=python/src \
  python3 -m unittest discover -s python/tests -v

Run an individual example against the local build:

PYTHONPATH=python/src python3 python/examples/python.py

The PostgreSQL tests require native psql. Set PSQL=/path/to/psql when it is not on PATH.

The generated _native.py module and platform library are private implementation details. Applications should import only from wasmer_sdk.

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_sdk-0.1.2-py3-none-manylinux_2_34_x86_64.whl (14.1 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ x86-64

wasmer_sdk-0.1.2-py3-none-manylinux_2_34_aarch64.whl (13.5 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ ARM64

wasmer_sdk-0.1.2-py3-none-macosx_11_0_arm64.whl (12.4 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

wasmer_sdk-0.1.2-py3-none-macosx_10_13_x86_64.whl (13.1 MB view details)

Uploaded Python 3macOS 10.13+ x86-64

File details

Details for the file wasmer_sdk-0.1.2-py3-none-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for wasmer_sdk-0.1.2-py3-none-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 69f9d41c605420c7d3cb0c075b189bcc40db5c2c038a11a03c267e9def7100a5
MD5 d8eba5a42ff7d0d122773ef28adf26a5
BLAKE2b-256 caddd74c29cb2223bf13f6ba041bdfbbe666846f8fec12ede0512e6d4337b663

See more details on using hashes here.

Provenance

The following attestation bundles were made for wasmer_sdk-0.1.2-py3-none-manylinux_2_34_x86_64.whl:

Publisher: release.yml on wasmerio/wasmer-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wasmer_sdk-0.1.2-py3-none-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for wasmer_sdk-0.1.2-py3-none-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 736fb35455e126a30aabad4d80defe86768a74091a49be08b947d5c0ab962c3a
MD5 325312435e94a0cc7fae82ba49c9f542
BLAKE2b-256 123fa5e48b1d62ddccc6118c409d2a7586389c9e47e352578a96c1b3eed7d58c

See more details on using hashes here.

Provenance

The following attestation bundles were made for wasmer_sdk-0.1.2-py3-none-manylinux_2_34_aarch64.whl:

Publisher: release.yml on wasmerio/wasmer-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wasmer_sdk-0.1.2-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for wasmer_sdk-0.1.2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 71dd5529b36551e15563e20828382496c7a9aa0616eb92b4b6d80c5d00b03ebf
MD5 3f9ebebe7b3d13b68e8286657474f7d6
BLAKE2b-256 9a7429521c6f9379777f092440a8174f72785f46823f2e1f2811e0c4264e1624

See more details on using hashes here.

Provenance

The following attestation bundles were made for wasmer_sdk-0.1.2-py3-none-macosx_11_0_arm64.whl:

Publisher: release.yml on wasmerio/wasmer-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wasmer_sdk-0.1.2-py3-none-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for wasmer_sdk-0.1.2-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 fda0d441e7e2df6e0873dd1e2cea06c0588d32ad3566da88fedfe86e136b6985
MD5 edc63d459ce7aeb4d6045cd6b92fe543
BLAKE2b-256 bf5008d068781ca84495902048269aa9d39eb544b8a013bb6563020c946804cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for wasmer_sdk-0.1.2-py3-none-macosx_10_13_x86_64.whl:

Publisher: release.yml on wasmerio/wasmer-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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