Skip to main content

Next generation GPU API for Python

Project description

CI Documentation Status PyPI version

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 PySide6, PyQt6, 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 replace pip with pipenv to install to a virtualenv).
  • Install wgpu-py in editable mode by running pip install -e ., this will also install our only runtime dependency cffi
  • Run python download-wgpu-native.py 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 download-wgpu-native.py --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.

Source Distribution

wgpu-0.5.9.tar.gz (81.4 kB view details)

Uploaded Source

Built Distributions

wgpu-0.5.9-py3-none-win_amd64.whl (4.6 MB view details)

Uploaded Python 3 Windows x86-64

wgpu-0.5.9-py3-none-win32.whl (4.2 MB view details)

Uploaded Python 3 Windows x86

wgpu-0.5.9-py3-none-manylinux_2_24_x86_64.whl (25.7 MB view details)

Uploaded Python 3 manylinux: glibc 2.24+ x86-64

wgpu-0.5.9-py3-none-manylinux_2_24_i686.whl (26.0 MB view details)

Uploaded Python 3 manylinux: glibc 2.24+ i686

wgpu-0.5.9-py3-none-macosx_11_0_arm64.whl (4.5 MB view details)

Uploaded Python 3 macOS 11.0+ ARM64

wgpu-0.5.9-py3-none-macosx_10_9_x86_64.whl (4.6 MB view details)

Uploaded Python 3 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: wgpu-0.5.9.tar.gz
  • Upload date:
  • Size: 81.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for wgpu-0.5.9.tar.gz
Algorithm Hash digest
SHA256 d9e1c45918c5d9a4845c2e4b8b471db64b593cc3f2ce9ddfd30aef56e97f456a
MD5 6a32a1992bbecbc65612fea76556b275
BLAKE2b-256 92a7f41d903c59c3ccdbcbb600d334d650045893a004f94746760397822f9437

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.5.9-py3-none-win_amd64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for wgpu-0.5.9-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 cd06448b36a776b88bca4d988d7e56e3a2efd806da80eaec47422a33c9055162
MD5 359a920cf54075593a02bbba4232657d
BLAKE2b-256 f0a7f4313f7be8da480aa204075a5b8a134b7a3488f931608b988f805c022f28

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.5.9-py3-none-win32.whl
  • Upload date:
  • Size: 4.2 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for wgpu-0.5.9-py3-none-win32.whl
Algorithm Hash digest
SHA256 92f9eab6762e8ac3bb8c1f6c78e87fedbd7bca7621aaa4092e15a9f14df6f8fa
MD5 2a20429f9d3ebb497120470a26ab3bef
BLAKE2b-256 fcd4083601bfdaf70dc15495e38ed8cb92998e378d11ded3c32c364f6a85d1bb

See more details on using hashes here.

File details

Details for the file wgpu-0.5.9-py3-none-manylinux_2_24_x86_64.whl.

File metadata

  • Download URL: wgpu-0.5.9-py3-none-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 25.7 MB
  • Tags: Python 3, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for wgpu-0.5.9-py3-none-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 f91e5b34ab22267ef8eb6ed06919b7254e0087336e7518c336b7cb8b8d117009
MD5 d421cc10d8e69e917e5526ae46970a0d
BLAKE2b-256 080e0ed17f55d5043cb182261dbf1f1a56db8b2b8ae7106ac04c094ce8232e79

See more details on using hashes here.

File details

Details for the file wgpu-0.5.9-py3-none-manylinux_2_24_i686.whl.

File metadata

  • Download URL: wgpu-0.5.9-py3-none-manylinux_2_24_i686.whl
  • Upload date:
  • Size: 26.0 MB
  • Tags: Python 3, manylinux: glibc 2.24+ i686
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for wgpu-0.5.9-py3-none-manylinux_2_24_i686.whl
Algorithm Hash digest
SHA256 a4c063028c883b700a062efe786fdd4cb6450bb3f375a3aeee116e24be8150a2
MD5 d73e4a0c50aa28d830dfa2850a9f765a
BLAKE2b-256 158e0ade6a71b7c27c424e083d9d55bd19615bc7c2cdc5c65474d83f1e72ec69

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.5.9-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 4.5 MB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for wgpu-0.5.9-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b06bb0ce932ec432577e716227210167d9903230435deb357426264d5984f854
MD5 fb2ba3d35ca48c64c8c50ab3e7ceaff7
BLAKE2b-256 ebe96455506dd9292c821bc2835f4d7d4824a0ea8570c5ee71e7f003a53bccea

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.5.9-py3-none-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 4.6 MB
  • Tags: Python 3, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for wgpu-0.5.9-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 80764cdbb9c2e2bae3ef548a92f81b0e44201e26fc8d7d9b424d3ac4bbae89d1
MD5 c3101eb5c4283279cf0a5cb303dab230
BLAKE2b-256 c95b278c21f6d514f0769ffe23cade618d4fe002c5f6ff1f1a49af5da9bda70a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page