Skip to main content

Next generation GPU API for Python

Project description

Build Status

wgpu-py

Next generation GPU API for Python

Introduction

In short, this is a Python lib wrapping the Rust wgpu lib and exposing it with a Pythonic API similar to WebGPU.

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. Based on wgpu-native.

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

Status

This is experimental, work in progress, you probably don't want to use this just yet!

  • We have a few working examples!
  • Support for Windows and Linux. Support for MacOS is underway.
  • We have not fully implemented the API yet.
  • The API may change. We're still figuring out what works best.
  • The API may change more. Until WebGPU settles as a standard, its specification may change, and with that our API will probably too.

Installation

pip install wgpu
pip install python-shader  # optional - our examples use this to define shaders

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. Note that on Linux, the tk canvas does not work. 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. At the moment, we've not implemented drawing to a window yet (see #29).

Usage

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

GUI integration

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

# Tk is included with Python (though this canvas only seems to work on Windows)
from wgpu.gui.tk import WgpuCanvas

# 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.1.3.tar.gz (45.5 kB view details)

Uploaded Source

Built Distributions

wgpu-0.1.3-py3-none-win_amd64.whl (1.3 MB view details)

Uploaded Python 3 Windows x86-64

wgpu-0.1.3-py3-none-win32.whl (1.2 MB view details)

Uploaded Python 3 Windows x86

wgpu-0.1.3-py3-none-manylinux1_x86_64.whl (1.3 MB view details)

Uploaded Python 3

wgpu-0.1.3-py3-none-manylinux1_i686.whl (1.3 MB view details)

Uploaded Python 3

wgpu-0.1.3-py3-none-macosx_10_13_x86_64.whl (1.4 MB view details)

Uploaded Python 3 macOS 10.13+ x86-64

File details

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

File metadata

  • Download URL: wgpu-0.1.3.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.10

File hashes

Hashes for wgpu-0.1.3.tar.gz
Algorithm Hash digest
SHA256 9c19fb5758fd4a732afb73ee7fab3adb4cba97a7554ad4a416452d131f5a105c
MD5 e23afe69b0df9031afd9aebe751a7769
BLAKE2b-256 08b841124959b0ce9b35d4278f4e17c039a5db4d903068007f07ec7dee5c4d78

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.1.3-py3-none-win_amd64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.10

File hashes

Hashes for wgpu-0.1.3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 7a98657715e846711ba4c1d33686ceec92d603a3c2e5616be833a511ce02bde8
MD5 9af2fd39a793ad021821745acddc6f2f
BLAKE2b-256 1c70ae5155f8d5cf27cb8f0912aec6e6139ceb31b92378422adf54045d1aaa9d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wgpu-0.1.3-py3-none-win32.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.10

File hashes

Hashes for wgpu-0.1.3-py3-none-win32.whl
Algorithm Hash digest
SHA256 e50167fc1d9df5cb780158d0718a22603ede92d9733f8b26d45a1342873f65a7
MD5 ccbd11673d659a922fc6b5da4a33c443
BLAKE2b-256 3ca9fe9774a54de29890eb55a0d32beeb7c769f0e924ecaa79db3766797dffcc

See more details on using hashes here.

File details

Details for the file wgpu-0.1.3-py3-none-manylinux1_x86_64.whl.

File metadata

  • Download URL: wgpu-0.1.3-py3-none-manylinux1_x86_64.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.10

File hashes

Hashes for wgpu-0.1.3-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 da44a03875ba8394ee4d005b0aaea757f2f0ed9ed38868cf8703adadc227a9c1
MD5 f3063127b29b97005aad7e6957dd87f0
BLAKE2b-256 3452673274cd62563f05f4cd4a3d38a09404d4e0537cdf88014108ba81c46b6b

See more details on using hashes here.

File details

Details for the file wgpu-0.1.3-py3-none-manylinux1_i686.whl.

File metadata

  • Download URL: wgpu-0.1.3-py3-none-manylinux1_i686.whl
  • Upload date:
  • Size: 1.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.10

File hashes

Hashes for wgpu-0.1.3-py3-none-manylinux1_i686.whl
Algorithm Hash digest
SHA256 9addb3ea6ec2658b5664f48402e36237ba2aafe8f1d8d21babaf0721cca6e886
MD5 4297d1fbce22c2a53cae04c08c6e5767
BLAKE2b-256 175615be3f051097a0b0b2fbe26249d95471e236f4f3f89b9d5fe346285fd205

See more details on using hashes here.

File details

Details for the file wgpu-0.1.3-py3-none-macosx_10_13_x86_64.whl.

File metadata

  • Download URL: wgpu-0.1.3-py3-none-macosx_10_13_x86_64.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 3, macOS 10.13+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.10

File hashes

Hashes for wgpu-0.1.3-py3-none-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 2bf654060439b23064cfbdb368553dc1239a89d9d442e0fd2fd95da1f268510a
MD5 9446dbd7fc9153132a3d37652141c090
BLAKE2b-256 1e4e3bde85012eaf313811b7e82ddef7bc3d1257c5270760e10c64c84b50af24

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