wgpu-py
Next generation GPU API for Python
Introduction
In short, this is a Python lib wrapping wgpu-native and exposing it with a Pythonic API similar to the WebGPU spec.
The OpenGL API is old and showing it's cracks. New API's like Vulkan,
Metal and DX12 provide a modern way to control the GPU, but these API's
are too low-level for general use. The WebGPU API follows the same concepts, but with
a simpler (higher level) spelling. The Python wgpu library brings the
WebGPU API to Python.
To get an idea of what this API looks like have a look at triangle.py and the other examples.
Status
The wgpu-API has not settled yet, use with care!
- Coverage of the WebGPU spec is nearly complete.
- Test coverage of the API is 100%.
- Support for Windows, Linux and MacOS.
- Until WebGPU settles as a standard, its specification may change, and with that our API will probably too. Check the changelog when you upgrade!
Installation
pip install wgpu
The library ships with Rust binaries for Windows, MacOS and Linux. If you want to use
a custom build instead, you can set the environment variable WGPU_LIB_PATH.
Platform requirements
Under the hood, wgpu runs on Vulkan, Metal, or DX12. The wgpu-backend is selected automatically, but can be overridden by setting the WGPU_BACKEND_TYPE environment variable to "Vulkan", "Metal", "D3D12", "D3D11", or "OpenGL".
On Windows 10, things should just work. On older Windows versions you may need to install the Vulkan drivers. You may want to force "Vulkan" while "D3D12" is less mature.
On Linux, it's advisable to install the proprietary drivers of your GPU
(if you have a dedicated GPU). You may need to apt install mesa-vulkan-drivers.
Wayland currently only works with the GLFW canvas (and is unstable).
On MacOS you need at least 10.13 (High Sierra) to have Vulkan support.
Usage
Also see the online documentation.
The full API is accessable via the main namespace:
import wgpu
But to use it, you need to select a backend first. You do this by importing it. There is currently only one backend:
import wgpu.backend.rs
To render to the screen you can use a variety of GUI toolkits:
# GLFW is a great lightweight windowing toolkit. Install with `pip install glfw`
from wgpu.gui.glfw import WgpuCanvas
# Visualizations can be embedded as a widget in a Qt application.
# Import PySide2, PyQt5, PySide or PyQt4 before running the line below.
# The code will detect and use the library that is imported.
from wgpu.gui.qt import WgpuCanvas
# You can also show wgpu visualizations in Jupyter
from wgpu.gui.jupyter import WgpuCanvas
Some functions in the original wgpu-native API are async. In the Python API,
the default functions are all sync (blocking), making things easy for general use.
Async versions of these functions are available, so wgpu can also work
well with Asyncio or Trio.
Web support
We are considering future support for compiling (Python) visualizations to the web via PScript and Flexx. We try to keep that option open as long as it does not get in the way too much. No promises.
License
This code is distributed under the 2-clause BSD license.
Developers
- Clone the repo.
- Install devtools using
pip install -r dev-requirements.txt(you can replacepipwithpipenvto install to a virtualenv). - Install wgpu-py in editable mode by running
python setup.py develop, this will also install our only runtime dependencycffi - Run
python download-wgpu-native.pyto download the upstream wgpu-native binaries.- Or alternatively point the
WGPU_LIB_PATHenvironment variable to a custom build.
- Or alternatively point the
- Use
black .to apply autoformatting. - Use
flake8 .to check for flake errors. - Use
pytest .to run the tests.
Changing the upstream wgpu-native version
- Use the optional arguments to
python download-wgpu-native.py --helpto download a different version of the upstream wgpu-native binaries. - The file
wgpu/resources/wgpu_native-versionwill be updated by the script to track which version we depend upon.
Metadata
Release files for wgpu 0.5.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wgpu-0.5.5.tar.gz | 74.7 kB | Without provenance | Details for wgpu-0.5.5.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| wgpu-0.5.5-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for wgpu-0.5.5-py3-none-win_amd64.whl |
| wgpu-0.5.5-py3-none-win32.whl | Python 3 | none | Windows x86-32 | Details for wgpu-0.5.5-py3-none-win32.whl |
| wgpu-0.5.5-py3-none-manylinux_2_24_x86_64.whl | Python 3 | none | Linux glibc 2.24+ x86-64 | Details for wgpu-0.5.5-py3-none-manylinux_2_24_x86_64.whl |
| wgpu-0.5.5-py3-none-macosx_10_14_x86_64.whl | Python 3 | none | macOS 10.14+ x86-64 | Details for wgpu-0.5.5-py3-none-macosx_10_14_x86_64.whl |
Total release size: 36.6 MB
Release files / wgpu-0.5.5.tar.gz
| Download URL | wgpu-0.5.5.tar.gz |
|---|---|
| Size | 74.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6ae70bd8ba7e943f8cc71d0b51a278f12b4a02e76cb5be8e451ef8b188201a7a
|
|
BLAKE2b-256 checksum How to use checksums |
7cff855743f08315d11bcf2d9e191af14a0dc3bb407f0c33eb9ffabf321039e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
|
Release files / wgpu-0.5.5-py3-none-win_amd64.whl
| Download URL | wgpu-0.5.5-py3-none-win_amd64.whl |
|---|---|
| Size | 4.4 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
bc15c1873dd59ba03e8499ad4ac7876c03d3fadf0f1a089f4448cecb275eec32
|
|
BLAKE2b-256 checksum How to use checksums |
cf0520e355823e3de63eff9d4da30bb7ba59890aea27e7589e20ecdd6f84616d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
|
Release files / wgpu-0.5.5-py3-none-win32.whl
| Download URL | wgpu-0.5.5-py3-none-win32.whl |
|---|---|
| Size | 4.1 MB |
| Tags | Python 3 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
9059af78788418b7ee3dc61f04773afe2fe5241c5fa0021ac95a8dda020c0d68
|
|
BLAKE2b-256 checksum How to use checksums |
5bc4d6abaf5257ba893a3be4759c48ca891af761f79ae3f3504655ada22a6f49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
|
Release files / wgpu-0.5.5-py3-none-manylinux_2_24_x86_64.whl
| Download URL | wgpu-0.5.5-py3-none-manylinux_2_24_x86_64.whl |
|---|---|
| Size | 23.6 MB |
| Tags | Linux glibc 2.24+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
11811e29f107b2cfd6a2fd4f8811e5650cd07bc8ff6eddab1fa58225ebf83278
|
|
BLAKE2b-256 checksum How to use checksums |
0f3d8b69d920de26ca150dfefda98879bbcc268630f54700fb75a396e7c3d9e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
|
Release files / wgpu-0.5.5-py3-none-macosx_10_14_x86_64.whl
| Download URL | wgpu-0.5.5-py3-none-macosx_10_14_x86_64.whl |
|---|---|
| Size | 4.5 MB |
| Tags | Python 3 macOS 10.14+ x86-64 |
|
SHA-256 checksum How to use checksums |
d0cbe6aa5e5b63856c3248eebfbba061135b576a8f07a5816e011781dfa6e546
|
|
BLAKE2b-256 checksum How to use checksums |
04156beb6a416f78ec5a2b52f59589698f8c37493c073aefa49181e16470db13
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
|
Security for wgpu 0.5.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.