{"id":13545702,"url":"https://github.com/pygfx/wgpu-py","last_synced_at":"2025-07-03T11:02:04.281Z","repository":{"id":37929899,"uuid":"228486057","full_name":"pygfx/wgpu-py","owner":"pygfx","description":"WebGPU for Python","archived":false,"fork":false,"pushed_at":"2025-05-19T11:21:31.000Z","size":2590,"stargazers_count":560,"open_issues_count":28,"forks_count":46,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-07-03T11:01:42.444Z","etag":null,"topics":["dx12","gpu","gui","metal","python","vulkan","webgpu","wgpu"],"latest_commit_sha":null,"homepage":"https://wgpu-py.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pygfx.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"pygfx"}},"created_at":"2019-12-16T22:19:14.000Z","updated_at":"2025-07-02T00:04:21.000Z","dependencies_parsed_at":"2023-10-13T05:13:56.966Z","dependency_job_id":"24bfa42a-b6b1-4d0e-aff0-3150e3bfe728","html_url":"https://github.com/pygfx/wgpu-py","commit_stats":{"total_commits":361,"total_committers":13,"mean_commits":27.76923076923077,"dds":0.5484764542936288,"last_synced_commit":"402961a04299a1518ac0fb7ad3dbb44636679dbb"},"previous_names":[],"tags_count":68,"template":false,"template_full_name":null,"purl":"pkg:github/pygfx/wgpu-py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pygfx%2Fwgpu-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pygfx%2Fwgpu-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pygfx%2Fwgpu-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pygfx%2Fwgpu-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pygfx","download_url":"https://codeload.github.com/pygfx/wgpu-py/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pygfx%2Fwgpu-py/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263314088,"owners_count":23447289,"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":["dx12","gpu","gui","metal","python","vulkan","webgpu","wgpu"],"created_at":"2024-08-01T11:01:10.325Z","updated_at":"2025-07-03T11:02:04.024Z","avatar_url":"https://github.com/pygfx.png","language":"Python","readme":"[![CI](https://github.com/pygfx/wgpu-py/workflows/CI/badge.svg)](https://github.com/pygfx/wgpu-py/actions)\n[![Documentation Status](https://readthedocs.org/projects/wgpu-py/badge/?version=stable)](https://wgpu-py.readthedocs.io)\n[![PyPI version](https://badge.fury.io/py/wgpu.svg)](https://badge.fury.io/py/wgpu)\n\n\n# wgpu-py\n\nA Python implementation of WebGPU - the next generation GPU API. 🚀\n\n\u003cdiv\u003e\n  \u003cimg width=320 src='https://raw.githubusercontent.com/pygfx/wgpu-py/main/examples/screenshots/triangle_auto.png' /\u003e\n  \u003cimg width=320 src='https://raw.githubusercontent.com/pygfx/wgpu-py/main/examples/screenshots/cube.png' /\u003e\n\u003c/div\u003e\n\n\n## Introduction\n\nThe purpose of wgpu-py is to provide Python with a powerful and reliable GPU API.\n\nIt serves as a basis to build a broad range of applications and libraries\nrelated to visualization and GPU compute. We use it in\n[pygfx](https://github.com/pygfx/pygfx) to create a modern Pythonic render\nengine.\n\nTo get an idea of what this API looks like have a look at\n[triangle.py](https://github.com/pygfx/wgpu-py/blob/main/examples/triangle.py)\nand the other [examples](https://github.com/pygfx/wgpu-py/blob/main/examples/).\n\n\n## Status\n\n* Until WebGPU settles as a standard, its specification may change, and with\n  that our API will probably too. Check the [changelog](CHANGELOG.md) when you\n  upgrade!\n* Coverage of the WebGPU spec is complete enough to build e.g.\n  [pygfx](https://github.com/pygfx/pygfx).\n* Test coverage of the API is close to 100%.\n* Support for Windows, Linux (x86 and aarch64), and MacOS (Intel and M1).\n\n\n## What is WebGPU / wgpu?\n\nWGPU is the future for GPU graphics; the successor to OpenGL.\n\nWebGPU is a JavaScript API with a well-defined\n[spec](https://gpuweb.github.io/gpuweb/), the successor to WebGL. The somewhat\nbroader term \"wgpu\" is used to refer to \"desktop\" implementations of WebGPU in\nvarious languages.\n\nOpenGL is old and showing its cracks. New API's like Vulkan, Metal and DX12\nprovide a modern way to control the GPU, but these are too low-level for general\nuse. WebGPU follows the same concepts, but with a simpler (higher level) API.\nWith wgpu-py we bring WebGPU to Python.\n\nTechnically speaking, wgpu-py is a wrapper for\n[wgpu-native](https://github.com/gfx-rs/wgpu-native), exposing its functionality with a Pythonic\nAPI closely resembling the [WebGPU spec](https://gpuweb.github.io/gpuweb/).\n\n\n## Installation\n\n```\npip install wgpu glfw\n```\n\nLinux users should make sure that **pip \u003e= 20.3**. That should do the\ntrick on most systems. See [getting started](https://wgpu-py.readthedocs.io/en/stable/start.html)\nfor details.\n\n\n## Usage\n\nAlso see the [online documentation](https://wgpu-py.readthedocs.io) and the [examples](https://github.com/pygfx/wgpu-py/tree/main/examples).\n\nThe full API is accessible via the main namespace:\n```py\nimport wgpu\n```\n\nTo render to the screen you can use a variety of GUI toolkits:\n\n```py\n# The auto backend selects either the glfw, qt or jupyter backend\nfrom wgpu.gui.auto import WgpuCanvas, run, call_later\n\n# Visualizations can be embedded as a widget in a Qt application.\n# Import PySide6, PyQt6, PySide2 or PyQt5 before running the line below.\n# The code will detect and use the library that is imported.\nfrom wgpu.gui.qt import WgpuCanvas\n\n# Visualizations can be embedded as a widget in a wx application.\nfrom wgpu.gui.wx import WgpuCanvas\n```\n\nSome functions in the original `wgpu-native` API are async. In the Python API,\nthe default functions are all sync (blocking), making things easy for general use.\nAsync versions of these functions are available, so wgpu can also work\nwell with Asyncio or Trio.\n\n\n## License\n\nThis code is distributed under the 2-clause BSD license.\n\n\n## Projects using `wgpu-py`\n\n* [pygfx](https://github.com/pygfx/pygfx) - A python render engine running on wgpu.\n* [shadertoy](https://github.com/pygfx/shadertoy) - Shadertoy implementation using wgpu-py.\n* [tinygrad](https://github.com/tinygrad/tinygrad) - deep learning framework\n* [fastplotlib](https://github.com/fastplotlib/fastplotlib) - A fast plotting library\n* [xdsl](https://github.com/xdslproject/xdsl) - A Python Compiler Design Toolkit (optional wgpu interpreter)\n\n\n## Developers\n\n* Clone the repo.\n* Install devtools using `pip install -e .[dev]`.\n* Using `pip install -e .` will also download the upstream wgpu-native\n  binaries.\n  * You can use `python tools/download_wgpu_native.py` when needed.\n  * Or point the `WGPU_LIB_PATH` environment variable to a custom build of `wgpu-native`.\n* Use `ruff format` to apply autoformatting.\n* Use `ruff check` to check for linting errors.\n* Optionally, if you install [pre-commit](https://github.com/pre-commit/pre-commit/) hooks with `pre-commit install`, lint fixes and formatting will be automatically applied on `git commit`.\n\n\n### Updating to a later version of WebGPU or wgpu-native\n\nTo update to upstream changes, we use a combination of automatic code\ngeneration and manual updating. See [the codegen utility](codegen/README.md)\nfor more information.\n\n\n## Testing\n\nThe test suite is divided into multiple parts:\n\n* `pytest -v tests` runs the unit tests.\n* `pytest -v examples` tests the examples.\n* `pytest -v wgpu/__pyinstaller` tests if wgpu is properly supported by pyinstaller.\n* `pytest -v codegen` tests the code that autogenerates the API.\n* `pytest -v tests_mem` tests against memoryleaks.\n\nThere are two types of tests for examples included:\n\n### Type 1: Checking if examples can run\n\nWhen running the test suite, pytest will run every example in a subprocess, to\nsee if it can run and exit cleanly. You can opt out of this mechanism by\nincluding the comment `# run_example = false` in the module.\n\n### Type 2: Checking if examples output an image\n\nYou can also (independently) opt-in to output testing for examples, by including\nthe comment `# test_example = true` in the module. Output testing means the test\nsuite will attempt to import the `canvas` instance global from your example, and\ncall it to see if an image is produced.\n\nTo support this type of testing, ensure the following requirements are met:\n\n* The `WgpuCanvas` class is imported from the `wgpu.gui.auto` module.\n* The `canvas` instance is exposed as a global in the module.\n* A rendering callback has been registered with `canvas.request_draw(fn)`.\n\nReference screenshots are stored in the `examples/screenshots` folder, the test\nsuite will compare the rendered image with the reference.\n\nNote: this step will be skipped when not running on CI. Since images will have\nsubtle differences depending on the system on which they are rendered, that\nwould make the tests unreliable.\n\nFor every test that fails on screenshot verification, diffs will be generated\nfor the rgb and alpha channels and made available in the\n`examples/screenshots/diffs` folder. On CI, the `examples/screenshots` folder\nwill be published as a build artifact so you can download and inspect the\ndifferences.\n\nIf you want to update the reference screenshot for a given example, you can grab\nthose from the build artifacts as well and commit them to your branch.\n\n### Testing Locally\n\nTesting locally is possible, however pixel perfect results will differ from\nthose on the CIs due to discrepencies in hardware, and driver (we use llvmpipe)\nversions.\n\nOn linux, it is possible to force the usage of LLVMPIPE in the test suite\nand compare the generated results of screenshots. Beware, the results on your machine\nmay differ to those on the CI. We always include the CI screenshots in the test suite\nto improve the repeatability of the tests.\n\nIf you have access to a linux machine with llvmpipe installed, you may run the\nexample pixel comparison testing by setting the WGPUPY_WGPU_ADAPTER_NAME\nenvironment variable appropriately. For example\n\n\n```\nWGPUPY_WGPU_ADAPTER_NAME=llvmpipe pytest -v examples/\n```\n\nThe `WGPUPY_WGPU_ADAPTER_NAME` variable is modeled after the\nhttps://github.com/gfx-rs/wgpu?tab=readme-ov-file#environment-variables\nand should only be used for testing the wgpu-py library itself.\nIt is not part of the supported wgpu-py interface.\n","funding_links":["https://github.com/sponsors/pygfx"],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpygfx%2Fwgpu-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpygfx%2Fwgpu-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpygfx%2Fwgpu-py/lists"}