Skip to main content

WebGPU for Python

Project description

CI Documentation Status PyPI version Zenodo badge

wgpu-py

A Python implementation of WebGPU - the next generation GPU API. 🚀

Introduction

The purpose of wgpu-py is to provide Python with a powerful and reliable GPU API.

It serves as a basis to build a broad range of applications and libraries related to visualization and GPU compute. We use it in pygfx to create a modern Pythonic render engine.

To get an idea of what this API looks like have a look at triangle.py and the other examples.

Status

  • Until WebGPU settles as a standard, its specification may change, and with that our API will probably too. Check the changelog when you upgrade!
  • Coverage of the WebGPU spec is complete enough to build e.g. pygfx.
  • Test coverage of the API is close to 100%.
  • Support for Windows, Linux (x86 and aarch64), and MacOS (Intel and M1).

What is WebGPU / wgpu?

WGPU is the future for GPU graphics; the successor to OpenGL.

WebGPU is a JavaScript API with a well-defined spec, the successor to WebGL. The somewhat broader term "wgpu" is used to refer to "desktop" implementations of WebGPU in various languages.

OpenGL is old and showing its cracks. New API's like Vulkan, Metal and DX12 provide a modern way to control the GPU, but these are too low-level for general use. WebGPU follows the same concepts, but with a simpler (higher level) API. With wgpu-py we bring WebGPU to Python.

Technically speaking, wgpu-py is a wrapper for wgpu-native, exposing its functionality with a Pythonic API closely resembling the WebGPU spec.

Installation

# Just wgpu
pip install wgpu

# If you want to render to screen
pip install wgpu rendercanvas glfw

Linux users should make sure that pip >= 20.3. That should do the trick on most systems. See getting started for details.

Usage

Also see the online documentation and the examples.

The full API is accessible via the main namespace:

import wgpu

To render to the screen you can use a variety of GUI toolkits:

# The rendercanvas auto backend selects either the glfw, qt, wx, or jupyter backend
from rendercanvas.auto import RenderCanvas, loop

# Visualizations can be embedded as a widget in a Qt application.
# Import PySide6, PyQt6, PySide2 or PyQt5 before running the line below.
# The code will detect and use the library that is imported.
from rendercanvas.qt import RenderCanvas

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.

License

This code is distributed under the 2-clause BSD license.

Projects using wgpu-py

  • pygfx - A python render engine running on wgpu.
  • shadertoy - Shadertoy implementation using wgpu-py.
  • tinygrad - deep learning framework
  • fastplotlib - A fast plotting library
  • xdsl - A Python Compiler Design Toolkit (optional wgpu interpreter)

Contributing

See the contribution guide.

Development install

  • Clone the repo.
  • Install devtools using pip install -e .[dev].
  • Using pip install -e . will also download the upstream wgpu-native binaries.
    • You can use python tools/download_wgpu_native.py when needed. And run python codegen once to obtain the combined headerfile.
    • Or point the WGPU_LIB_PATH environment variable to a custom build of wgpu-native.

Quick tips

  • Use ruff format to apply autoformatting.
  • Use ruff check to check for linting errors.
  • Use pytest -v tests runs the unit tests.
  • Use pytest -v examples tests the examples.

Code of Conduct

This repository follows the PyGfx Code of Conduct

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wgpu-0.32.0.tar.gz (197.2 kB view details)

Uploaded Source

Built Distributions

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

wgpu-0.32.0-py3-none-win_arm64.whl (3.3 MB view details)

Uploaded Python 3Windows ARM64

wgpu-0.32.0-py3-none-win_amd64.whl (3.5 MB view details)

Uploaded Python 3Windows x86-64

wgpu-0.32.0-py3-none-win32.whl (3.3 MB view details)

Uploaded Python 3Windows x86

wgpu-0.32.0-py3-none-manylinux_2_28_x86_64.whl (3.5 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

wgpu-0.32.0-py3-none-manylinux_2_28_aarch64.whl (3.5 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

wgpu-0.32.0-py3-none-macosx_11_0_arm64.whl (2.8 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

wgpu-0.32.0-py3-none-macosx_10_9_x86_64.whl (2.9 MB view details)

Uploaded Python 3macOS 10.9+ x86-64

File details

Details for the file wgpu-0.32.0.tar.gz.

File metadata

  • Download URL: wgpu-0.32.0.tar.gz
  • Upload date:
  • Size: 197.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for wgpu-0.32.0.tar.gz
Algorithm Hash digest
SHA256 cb23b2f225594258ccc8ba97458381e46c18e561c5d2d6fc25213e68a6d89985
MD5 74fdd6044cfc9f3e801eb3650971e76f
BLAKE2b-256 6052b7d5ef9c29bbb9f4e40bff9a5027482857fb225f962acec9c5bb6a2d4e44

See more details on using hashes here.

Provenance

The following attestation bundles were made for wgpu-0.32.0.tar.gz:

Publisher: cd.yml on pygfx/wgpu-py

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

File details

Details for the file wgpu-0.32.0-py3-none-win_arm64.whl.

File metadata

  • Download URL: wgpu-0.32.0-py3-none-win_arm64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: Python 3, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for wgpu-0.32.0-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 cb0414107825bd94538220cf3f329c83697b99b8e39c6e16e4e6726e427de75c
MD5 054dbb561d48ef0b6f96c6c3f896a542
BLAKE2b-256 6b164b097baac7c8d6e013e67f1483d100847b9ea350eb393c301a28a95c4bd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for wgpu-0.32.0-py3-none-win_arm64.whl:

Publisher: cd.yml on pygfx/wgpu-py

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

File details

Details for the file wgpu-0.32.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: wgpu-0.32.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 3.5 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for wgpu-0.32.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 493c8a0425c7d3cc728a2489bce40d1a016d800306e59763ff1b21e176e66323
MD5 268912c17205f8eaf32e778ccc31cf50
BLAKE2b-256 dc5a92d8ebd91d2e6e772a4d90656231472a8dad6ab050174336510fa9dff978

See more details on using hashes here.

Provenance

The following attestation bundles were made for wgpu-0.32.0-py3-none-win_amd64.whl:

Publisher: cd.yml on pygfx/wgpu-py

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

File details

Details for the file wgpu-0.32.0-py3-none-win32.whl.

File metadata

  • Download URL: wgpu-0.32.0-py3-none-win32.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for wgpu-0.32.0-py3-none-win32.whl
Algorithm Hash digest
SHA256 d51a17dbbeb37ef20d1c900d7c51bc71abba145792ad428763666a1bb91cf986
MD5 bf15f5e4c4c25b83328bf07ba72382a7
BLAKE2b-256 8fa8fca88e53ef7439bbb01d58c33e722508af19d762b9f8bf8810e208882af6

See more details on using hashes here.

Provenance

The following attestation bundles were made for wgpu-0.32.0-py3-none-win32.whl:

Publisher: cd.yml on pygfx/wgpu-py

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

File details

Details for the file wgpu-0.32.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for wgpu-0.32.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6499a31b5a29a10b4f1089fea4a0806411f42605fa86b6c0b543a07ca0de8568
MD5 bf33d31ed51b064f7c5cf6db12247f6b
BLAKE2b-256 99a98b00e9d0cbd1ec0766e5b3c8063e61f0335262afe07cef82c307899bcf01

See more details on using hashes here.

Provenance

The following attestation bundles were made for wgpu-0.32.0-py3-none-manylinux_2_28_x86_64.whl:

Publisher: cd.yml on pygfx/wgpu-py

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

File details

Details for the file wgpu-0.32.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for wgpu-0.32.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 00454ba1bc794d38c8365f4ad29f381b88ce0a7f115133bfaa6f1dfad7eb2764
MD5 8c160770c786d1724be352e5fd1145fc
BLAKE2b-256 405236819230b805b07fc4c3e92242aba7b73a0ce25e03b124992af79a6b1d4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for wgpu-0.32.0-py3-none-manylinux_2_28_aarch64.whl:

Publisher: cd.yml on pygfx/wgpu-py

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

File details

Details for the file wgpu-0.32.0-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: wgpu-0.32.0-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 2.8 MB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for wgpu-0.32.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6c3f654ea01ab2de8a2903354ced02a3c6ef161d0fba1aa4fea60aa86d021908
MD5 6cef66b79a7684696be31eccc7493392
BLAKE2b-256 d73ba21ac5d2c5fcc13c2709123f497f5e008726221c56dc83ba0850fc2d230d

See more details on using hashes here.

Provenance

The following attestation bundles were made for wgpu-0.32.0-py3-none-macosx_11_0_arm64.whl:

Publisher: cd.yml on pygfx/wgpu-py

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

File details

Details for the file wgpu-0.32.0-py3-none-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for wgpu-0.32.0-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cfd3967616a3c42e2b7a234407df38668c697f5aa505d56e0814d647b6746302
MD5 d64b3e094aaa5ae275b03cf7707d535a
BLAKE2b-256 1b4b173e7685a22edf2d33ed330a038c8859d2c62bff900eb637a702661333ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for wgpu-0.32.0-py3-none-macosx_10_9_x86_64.whl:

Publisher: cd.yml on pygfx/wgpu-py

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