Skip to main content

Next generation GPU API for Python

Project description

CI Documentation Status


Next generation GPU API for Python


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 and the other examples.


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!


pip install wgpu
pip install pyshader  # optional - our examples use this

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 or Metal, and eventually also DX12 or OpenGL.

On Windows 10, things should just work. On older Windows versions you may need to install the Vulkan drivers (or wait for the DX12 backend to become more 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.


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:


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

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.


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


  • Clone the repo.
  • Install devtools using pip install -r dev-requirements.txt (you can replace pip with pipenv to install to a virtualenv).
  • Install wgpu-py in editable mode by running python develop, this will also install our only runtime dependency cffi
  • Run python to download the upstream wgpu-native binaries.
    • Or alternatively point the WGPU_LIB_PATH environment variable to a custom build.
  • 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 --help to download a different version of the upstream wgpu-native binaries.
  • The file wgpu/resources/wgpu_native-version will be updated by the script to track which version we depend upon.

Project details

Download files

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

Files for wgpu, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size wgpu-0.3.0-py3-none-macosx_10_14_x86_64.whl (1.6 MB) File type Wheel Python version py3 Upload date Hashes View
Filename, size wgpu-0.3.0-py3-none-manylinux1_i686.whl (1.5 MB) File type Wheel Python version py3 Upload date Hashes View
Filename, size wgpu-0.3.0-py3-none-manylinux1_x86_64.whl (1.4 MB) File type Wheel Python version py3 Upload date Hashes View
Filename, size wgpu-0.3.0-py3-none-win32.whl (1.5 MB) File type Wheel Python version py3 Upload date Hashes View
Filename, size wgpu-0.3.0-py3-none-win_amd64.whl (1.6 MB) File type Wheel Python version py3 Upload date Hashes View
Filename, size wgpu-0.3.0.tar.gz (65.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page