{"id":13501271,"url":"https://github.com/bytecodealliance/wasmtime-py","last_synced_at":"2025-03-29T08:32:17.721Z","repository":{"id":37498180,"uuid":"250066411","full_name":"bytecodealliance/wasmtime-py","owner":"bytecodealliance","description":"Python WebAssembly runtime powered by Wasmtime","archived":false,"fork":false,"pushed_at":"2025-02-20T16:22:15.000Z","size":720,"stargazers_count":427,"open_issues_count":43,"forks_count":59,"subscribers_count":19,"default_branch":"main","last_synced_at":"2025-03-17T11:12:33.636Z","etag":null,"topics":["python","wasm","wasmtime"],"latest_commit_sha":null,"homepage":"https://bytecodealliance.github.io/wasmtime-py/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bytecodealliance.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-25T19:02:51.000Z","updated_at":"2025-03-16T12:56:04.000Z","dependencies_parsed_at":"2023-02-19T12:45:25.425Z","dependency_job_id":"49b8e667-f2a9-47b9-b1e0-a54a6486d762","html_url":"https://github.com/bytecodealliance/wasmtime-py","commit_stats":{"total_commits":271,"total_committers":19,"mean_commits":"14.263157894736842","dds":0.09963099630996308,"last_synced_commit":"e655f68c9bc99a09f5e1e83ffb48ae6ecffb9ac7"},"previous_names":[],"tags_count":69,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fwasmtime-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fwasmtime-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fwasmtime-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytecodealliance%2Fwasmtime-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bytecodealliance","download_url":"https://codeload.github.com/bytecodealliance/wasmtime-py/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246162092,"owners_count":20733351,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["python","wasm","wasmtime"],"created_at":"2024-07-31T22:01:31.205Z","updated_at":"2025-03-29T08:32:17.706Z","avatar_url":"https://github.com/bytecodealliance.png","language":"Python","readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e\u003ccode\u003ewasmtime-py\u003c/code\u003e\u003c/h1\u003e\n\n  \u003cp\u003e\n    \u003cstrong\u003ePython embedding of\n    \u003ca href=\"https://github.com/bytecodealliance/wasmtime\"\u003eWasmtime\u003c/a\u003e\u003c/strong\u003e\n  \u003c/p\u003e\n\n  \u003cstrong\u003eA \u003ca href=\"https://bytecodealliance.org/\"\u003eBytecode Alliance\u003c/a\u003e project\u003c/strong\u003e\n\n  \u003cp\u003e\n    \u003c!-- Badge links contain no whitespace, to eliminate underlines in rendered page --\u003e\n    \u003ca href=\"https://github.com/bytecodealliance/wasmtime-py/actions?query=workflow%3ACI\"\u003e\u003cimg src=\"https://github.com/bytecodealliance/wasmtime-py/workflows/CI/badge.svg\" alt=\"CI status\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/wasmtime/\"\u003e\u003cimg src=\"https://img.shields.io/pypi/v/wasmtime.svg\" alt=\"Latest Version\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/wasmtime/\"\u003e\u003cimg src=\"https://img.shields.io/pypi/pyversions/wasmtime.svg\" alt=\"Latest Version\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://bytecodealliance.github.io/wasmtime-py/\"\u003e\u003cimg src=\"https://img.shields.io/badge/docs-main-green\" alt=\"Documentation\"/\u003e\u003c/a\u003e\n    \u003ca href=\"https://bytecodealliance.github.io/wasmtime-py/coverage/\"\u003e\u003cimg src=\"https://img.shields.io/badge/coverage-main-green\" alt=\"Code Coverage\"/\u003e\u003c/a\u003e\n  \u003c/p\u003e\n\n\u003c/div\u003e\n\n## Installation\n\nTo install `wasmtime-py`, run this command in your terminal:\n\n```bash\n$ pip install wasmtime\n```\n\nThe package currently supports 64-bit builds of Python 3.9+ on Windows,\nmacOS, and Linux, for x86\\_64 and arm64 architectures.\n\n## Versioning\n\n`wasmtime-py` follows the Wasmtime versioning scheme, with a new major version being\nreleased every month. As with Wasmtime itself, new major versions of `wasmtime-py`\ncan contain changes that break code written against the previous major version.\n\nSince every installed Python package needs to agree on a single version of\n`wasmtime-py`, to use the upper bound on the major version in the dependency\nrequirement should be bumped reguarly, ideally as soon as a new `wasmtime-py`\nversion is released. To automate this process it is possible to use\nthe [whitequark/track-pypi-dependency-version][] script. [YoWASP/runtime][] is\nan example of a project that automatically publishes releases on PyPI once a new\nversion of `wasmtime-py` is released if it passes the testsuite.\n\n[whitequark/track-pypi-dependency-version]: https://github.com/whitequark/track-pypi-dependency-version\n[YoWASP/runtime]: https://github.com/YoWASP/runtime\n\n## Usage\n\nIn this example, we compile and instantiate a WebAssembly module and use it from Python:\n\n```python\nfrom wasmtime import Store, Module, Instance, Func, FuncType\n\nstore = Store()\nmodule = Module(store.engine, \"\"\"\n  (module\n    (func $hello (import \"\" \"hello\"))\n    (func (export \"run\") (call $hello))\n  )\n\"\"\")\n\ndef say_hello():\n    print(\"Hello from Python!\")\nhello = Func(store, FuncType([], []), say_hello)\n\ninstance = Instance(store, module, [hello])\nrun = instance.exports(store)[\"run\"]\nrun(store)\n```\n\nBe sure to check out the [`examples` directory], which has other usage patterns\nas well as the [full API documentation][apidoc] of the `wasmtime-py` package.\n\n[`examples` directory]: https://github.com/bytecodealliance/wasmtime-py/tree/main/examples\n[apidoc]: https://bytecodealliance.github.io/wasmtime-py/\n\nIf your WebAssembly module works this way, then you can also import the WebAssembly module\ndirectly into Python without explicitly compiling and instantiating it yourself:\n\n```python\n# Import the custom loader for `*.wasm` files\nimport wasmtime.loader\n\n# Assuming `your_wasm_file.wasm` is in the python load path...\nimport your_wasm_file\n\n# Now you're compiled and instantiated and ready to go!\nprint(your_wasm_file.run())\n```\n\n## Components\n\nThe `wasmtime` package has initial support for running WebAssembly components in\nPython with high-level bindings. WebAssembly components are defined by the\n[component model] and are a flagship feature under development for Wasmtime and\nits bindings. Components enable communication between the host and WebAssembly\nguests with richer types than the numerical primitives supported by core\nWebAssembly. For example with a component Python can pass a string to wasm and\nback.\n\nComponents are represented as `*.wasm` binaries in the same manner as core\nWebAssembly modules. With a component binary you can generate Python bindings\nwith:\n\n```sh\n$ python -m wasmtime.bindgen the-component.wasm --out-dir the-bindings\n```\n\nAn example of using this can be done with the [`wasm-tools`] repository. For\nexample with this core wasm module at `demo.wat`:\n\n```wasm\n(module\n  (import \"python\" \"print\" (func $print (param i32 i32)))\n  (memory (export \"memory\") 1)\n\n  (func (export \"run\")\n    i32.const 100   ;; base pointer of string\n    i32.const 13    ;; length of string\n    call $print)\n\n  (data (i32.const 100) \"Hello, world!\")\n)\n```\n\nand with this [`*.wit`] interface at `demo.wit`:\n\n```text\npackage my:demo;\n\nworld demo {\n  import python: interface {\n    print: func(s: string);\n  }\n\n  export run: func();\n}\n```\n\nAnd this `demo.py` script\n\n```python\nfrom demo import Root, RootImports, imports\nfrom wasmtime import Store\n\nclass Host(imports.Python):\n    def print(self, s: str):\n        print(s)\n\ndef main():\n    store = Store()\n    demo = Root(store, RootImports(Host()))\n    demo.run(store)\n\nif __name__ == '__main__':\n    main()\n```\n\n```sh\n$ wasm-tools component embed demo.wit demo.wat -o demo.wasm\n$ wasm-tools component new demo.wasm -o demo.component.wasm\n$ python -m wasmtime.bindgen demo.component.wasm --out-dir demo\n$ python demo.py\nHello, world!\n```\n\nThe generated package `demo` has all of the requisite exports/imports into the\ncomponent bound. The `demo` package is additionally annotated with types to\nassist with type-checking and self-documentation as much as possible.\n\n[component model]: https://github.com/WebAssembly/component-model\n[`wasm-tools`]: https://github.com/bytecodealliance/wasm-tools\n[`*.wit`]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/WIT.md\n\n## Contributing\n\nSee [`CONTRIBUTING.md`](./CONTRIBUTING.md).\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytecodealliance%2Fwasmtime-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytecodealliance%2Fwasmtime-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytecodealliance%2Fwasmtime-py/lists"}