Skip to main content

Python bindings for the Wasmer sandbox SDK

Project description

Wasmer SDK for Python

The Python package is a typed, handwritten façade over the Rust wasmer-sdk, exported through UniFFI. Package resolution, sandbox state, commands, live processes, streams, files, and ports follow the same model as the Rust and JavaScript SDKs. Constructing Wasmer() is synchronous; only operations that perform I/O and deterministic shutdown are awaited.

from wasmer_sdk import Wasmer

client = Wasmer(cache_root=".wasmer")
python = await client.packages.load("python/python@3.12")
sandbox = await client.sandboxes.create(
    packages=[python],
    files={"main.py": "print('hello from WASIX')"},
)
output = await sandbox.command(
    "python", ["/workspace/main.py"]
).run(check=True)
print(output.text())

For long-lived applications and tests, await client.close() or async with Wasmer() as client provides deterministic cleanup.

Build the local native package and run the executable tests from the repository root:

python3 python/scripts/build.py --release
PYTHONPATH=python/src \
  python3 -m unittest discover -s python/tests -v

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

Examples

Run a Python package:

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

Serve HTTP with wasmer/edgejs-quickjs:

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

Run wasmer/pglite under Wasmer, then query it with the standard native psql client:

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

The example accepts --psql /path/to/psql when the client is not on PATH.

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 Distribution

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

wasmer_sdk-0.0.1-py3-none-macosx_11_0_arm64.whl (12.3 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for wasmer_sdk-0.0.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4324f896eac71b3c4010743289e14b826847a72cc924f14f6782b366e4736da5
MD5 93d940efcf173daa2c2e835fc7e62f1f
BLAKE2b-256 33d410447b1aa34e44f400dc7cbb57daa1a037ef782f78f924800233225e6931

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