Skip to main content

wesl-py

Python bindings for the Rust WESL compiler. WESL adds imports and conditional compilation to WGSL. Run shader tests with pytest. Compilation needs no GPU.

Installation

Requires Python 3.12 or later.

The distribution name is wesl-py; import it as wesl.

pip install wesl-py

To run shader tests, install the testing extra. It adds pytest and wgpu.

pip install "wesl-py[testing]"

Compile a shader

Save as shaders/exposure.wesl:

fn apply_exposure(color: vec3f, stops: f32) -> vec3f {
    let adjusted = color * exp2(stops);
    @if(clamp_output) return clamp(adjusted, vec3f(0.0), vec3f(1.0));
    @if(!clamp_output) return adjusted;
}

Import it from shaders/main.wesl:

import package::exposure::apply_exposure;

@fragment
fn main(@location(0) color: vec4f) -> @location(0) vec4f {
    return vec4f(apply_exposure(color.rgb, 1.0), color.a);
}

Enable a shader feature at compile time:

import wesl

result = wesl.compile_file(
    "shaders/main.wesl",
    features={"clamp_output": True},
)
print(result.wgsl)

Pass result.wgsl to your renderer, such as device.create_shader_module(code=result.wgsl) in wgpu-py. The GPU runtime validates the WGSL. Use compile_source() for a string or compile() for a mapping of modules. See the API reference for options, library imports, and diagnostics.

compile_file() resolves imports from the shader file's parent directory. Use Compiler.from_project() for a wesl.toml project.

Read buffer layouts

wesl.reflect reads sizes, bindings, and workgroup sizes from the shader, so the Python side does not repeat them:

from wesl.reflect import var_reflection

particles = var_reflection(compiler, "package::simulation::particles")
buffer_size = particle_count * particles.dtype.itemsize

See Reflection for structures, entry points, and buffer decoding.

Test a shader

Save this as shaders/math.test.wesl:

import wgsl_test::expectEq;

@test
fn addition() {
    expectEq(3u + 4u, 7u);
}

Run pytest:

python -m pytest shaders -q

The plugin collects @test functions and reports failures at the shader file and line. Assertion shaders are bundled. Execution requires a hardware or software WebGPU adapter. See the shader testing guide for Python fixtures, compute tests, and image comparisons.

License

MIT.

Metadata

Release files for wesl-py 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wesl-py 0.2.0
File Size Uploaded Provenance Actions
wesl_py-0.2.0.tar.gz 631.4 kB With provenance Details for wesl_py-0.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for wesl-py 0.2.0
File Actions
wesl_py-0.2.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for wesl_py-0.2.0-cp312-abi3-win_amd64.whl
wesl_py-0.2.0-cp312-abi3-manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64 Details for wesl_py-0.2.0-cp312-abi3-manylinux_2_28_x86_64.whl
wesl_py-0.2.0-cp312-abi3-manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.28+ ARM64 Details for wesl_py-0.2.0-cp312-abi3-manylinux_2_28_aarch64.whl
wesl_py-0.2.0-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for wesl_py-0.2.0-cp312-abi3-macosx_11_0_arm64.whl

Total release size: 7.6 MB

Release files / wesl_py-0.2.0.tar.gz

Download URL wesl_py-0.2.0.tar.gz
Size 631.4 kB
Tags Source
SHA-256 checksum
How to use checksums
806eb602b6bb68feedfd78a45c97381547c11f286d182503d3bd25f10e54bcca
BLAKE2b-256 checksum
How to use checksums
872bb08c2ff7e1b16529c11b7816be70e0a85bc8d258ecb59b4a732d09ce59dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / wesl_py-0.2.0-cp312-abi3-win_amd64.whl

Download URL wesl_py-0.2.0-cp312-abi3-win_amd64.whl
Size 1.9 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
badc9b5d9a8e0716de9f7c1a0a90ef976a5dcf93a25edb4aa7ecd27d318526a0
BLAKE2b-256 checksum
How to use checksums
93e9bde83a66676dd88da4f8d7d0ae40a1f9696addd3b34fce2cb992a66c5762
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / wesl_py-0.2.0-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL wesl_py-0.2.0-cp312-abi3-manylinux_2_28_x86_64.whl
Size 1.8 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
e469cf7f075e34e8d6855a13700624963e0955f7e85ece5102f526551bc57942
BLAKE2b-256 checksum
How to use checksums
31316953fe94e335c7d47b4cf6e485fc584a3005658dd6315635c7a4612b31e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / wesl_py-0.2.0-cp312-abi3-manylinux_2_28_aarch64.whl

Download URL wesl_py-0.2.0-cp312-abi3-manylinux_2_28_aarch64.whl
Size 1.7 MB
Tags CPython 3.12 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
2862f12e4661a8e133290783c81b07e40f1fac3ce14a26ce5b17f35faadc6014
BLAKE2b-256 checksum
How to use checksums
171dc9c4662be118efa54976a349a458dc382780fd41176d1e8225db4023f825
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Release files / wesl_py-0.2.0-cp312-abi3-macosx_11_0_arm64.whl

Download URL wesl_py-0.2.0-cp312-abi3-macosx_11_0_arm64.whl
Size 1.6 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
58ef1e434193abd51b65edd1f3819bf9c5791142e7d559b53a93670e5067eeda
BLAKE2b-256 checksum
How to use checksums
ac20ff37e73d07a7fef273fd6b72d912f647ae009a96b8f4b6c10aa660c43443
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

Security for wesl-py 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for wesl_py-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

5 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page