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 (Intel and M1).
  • 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 wheels include the prebuilt binaries. If you want to use a custom build instead, you can set the environment variable WGPU_LIB_PATH. You probably also want to install glwf (for desktop) and/or jupyter_rfb (for Jupyter).

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:

# The auto backend selects either the glfw or jupyter backend
from wgpu.gui.auto import WgpuCanvas, run, call_later

# 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

# Visualizations can be embedded as a widget in a wx application.
from wgpu.gui.wx 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.

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 runtime dependencies as needed.
  • 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.
  • Use pip wheel --no-deps . to build a wheel.

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.7.1.tar.gz (86.5 kB view details)

Uploaded Source

Built Distributions

wgpu-0.7.1-py3-none-win_amd64.whl (5.1 MB view details)

Uploaded Python 3 Windows x86-64

wgpu-0.7.1-py3-none-win32.whl (4.7 MB view details)

Uploaded Python 3 Windows x86

wgpu-0.7.1-py3-none-manylinux_2_24_x86_64.whl (27.5 MB view details)

Uploaded Python 3 manylinux: glibc 2.24+ x86-64

wgpu-0.7.1-py3-none-manylinux_2_24_i686.whl (27.8 MB view details)

Uploaded Python 3 manylinux: glibc 2.24+ i686

wgpu-0.7.1-py3-none-macosx_11_0_arm64.whl (5.0 MB view details)

Uploaded Python 3 macOS 11.0+ ARM64

wgpu-0.7.1-py3-none-macosx_10_9_x86_64.whl (5.1 MB view details)

Uploaded Python 3 macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: wgpu-0.7.1.tar.gz
  • Upload date:
  • Size: 86.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wgpu-0.7.1.tar.gz
Algorithm Hash digest
SHA256 93951e8ec2245c7b38c082b7f35cb1cd3263a3b0430604797915b47f37b18108
MD5 ba0592bb0b82fa7ed78574affa3aa9d5
BLAKE2b-256 efae86bbd412207f0b1691078c3678686a1c52a88f14b94dc980a1e2e87d1260

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.7.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 5.1 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wgpu-0.7.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 3f0d096ad77edde3f6a9270e762e8cff29a51618071ed3a6f302aa28023b6f17
MD5 c77cdc8f7758d2daea3a4dee2c03b252
BLAKE2b-256 f79761f7a9a536e20689dd2f520197c039863818c4b33065e204c92cd18bc4e7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.7.1-py3-none-win32.whl
  • Upload date:
  • Size: 4.7 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wgpu-0.7.1-py3-none-win32.whl
Algorithm Hash digest
SHA256 6cabba1df13a21ba6bf30833ed357b2bd485ec7cdbb5fb331eaf45c5a68c40fd
MD5 57a0549bdaacab148f6b2951c7ef858b
BLAKE2b-256 278f06770dd41a5a34d4a9483ddfb2a3abf550b2179cbbff712e4e8c64abd421

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.7.1-py3-none-manylinux_2_24_x86_64.whl
  • Upload date:
  • Size: 27.5 MB
  • Tags: Python 3, manylinux: glibc 2.24+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wgpu-0.7.1-py3-none-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 fe388e37906fc5f6d562d188b7e67917eb9e6228b6a31f15032671656063cb83
MD5 dd49e8c54d4d857e7d4f6b2cd1be70a0
BLAKE2b-256 4875c5c6101980ca039cb6acbcf2b44d847f59d50d754917ef9a4cd69ca2c461

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.7.1-py3-none-manylinux_2_24_i686.whl
  • Upload date:
  • Size: 27.8 MB
  • Tags: Python 3, manylinux: glibc 2.24+ i686
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wgpu-0.7.1-py3-none-manylinux_2_24_i686.whl
Algorithm Hash digest
SHA256 c56a0cdc62bcdf2172184691b3628a8ea53b2385b88092f39a0afc453c2f00c3
MD5 f395757e901655cafce551719d612db6
BLAKE2b-256 155e9a4387215a72b5c4fb8211f648e56862d7ff574d37fe3e4a0977bdf1423b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.7.1-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 5.0 MB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wgpu-0.7.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d6774e2f9ea7303b0d9f940da194c34e47da9bb5216ddf7f9dedcea9ea8136b2
MD5 ec71439d1efe88f928195032be5a2dd0
BLAKE2b-256 4e9c46cbe28a69a87f7c29523db30ef856328e05793d4cbc933bf11a8036d830

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.7.1-py3-none-macosx_10_9_x86_64.whl
  • Upload date:
  • Size: 5.1 MB
  • Tags: Python 3, macOS 10.9+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for wgpu-0.7.1-py3-none-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d3655da7652726aa8335e3b2d8f64f35d9a05695f1150e78f6c42f8c43582f91
MD5 5381e9a7deaa15910136cdaef175b764
BLAKE2b-256 d6d953ac191cba3761b973a68a9dd3357aa6f192b4b3dce6e436a2e1184c29e2

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