Skip to main content

Next generation GPU API for Python

Project description

CI Documentation Status

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 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.

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

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 python setup.py develop, 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.1.tar.gz (89.9 kB view details)

Uploaded Source

Built Distributions

wgpu-0.5.1-py3-none-win_amd64.whl (7.9 MB view details)

Uploaded Python 3 Windows x86-64

wgpu-0.5.1-py3-none-win32.whl (7.0 MB view details)

Uploaded Python 3 Windows x86

wgpu-0.5.1-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (29.3 MB view details)

Uploaded Python 3 manylinux: glibc 2.12+ x86-64

wgpu-0.5.1-py3-none-macosx_10_14_x86_64.whl (8.6 MB view details)

Uploaded Python 3 macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: wgpu-0.5.1.tar.gz
  • Upload date:
  • Size: 89.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for wgpu-0.5.1.tar.gz
Algorithm Hash digest
SHA256 2574a35cb1e5df6d77035fffecd7ca2a49be8e512f63ece0608a9ccda37909fe
MD5 3fcfcc387b30854fe0f5eaa63b2eba0f
BLAKE2b-256 4570c215ba57d67ad0831107999527197b13821b939168c24eb7c7946779c655

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.5.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 7.9 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for wgpu-0.5.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 6d95e90b46bd660a29eedfe9496c96cc49e4cec2cf2a32577ac14e5c5a3c8372
MD5 3dbb45662809a8e2f252e58b5b7eb0ac
BLAKE2b-256 09a693b19b0dbdad04db27f613f39a9771c778c16191818d39e2a7c0e13dbfd8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.5.1-py3-none-win32.whl
  • Upload date:
  • Size: 7.0 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for wgpu-0.5.1-py3-none-win32.whl
Algorithm Hash digest
SHA256 bdca1b8e7a0b780ab6ab9cfe539bf5d8d8663c2f992d6cd7ace518083657a83b
MD5 5534e615b145142347dc1a8b28ad55d6
BLAKE2b-256 ee20b8d0683a4ba54d975d30f70877f3129799c37749c44dad93becd247b28bb

See more details on using hashes here.

File details

Details for the file wgpu-0.5.1-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for wgpu-0.5.1-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 e5e4b6b842af7f7fdc18a91cd85a2caefe5c32eee6e04268dcfaea7e16f877cb
MD5 23eb0b8b9cd97092cc8769215f251353
BLAKE2b-256 7b2589914802baa3aa66ab491b945d319b16c754a473773fd349f0db737ade65

See more details on using hashes here.

File details

Details for the file wgpu-0.5.1-py3-none-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: wgpu-0.5.1-py3-none-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 8.6 MB
  • Tags: Python 3, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for wgpu-0.5.1-py3-none-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 b3856dc6a4ee828203c2ed6e99bf1381f96fa0fe9cc82ff72164f6516ee4b588
MD5 2b9e44dcd7f0b8d4588e251d5d87af25
BLAKE2b-256 ad78d4661c291b74ce6ad8af17cf8a4bbc2b3ed7ba6f239e12b0ddeac6131074

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