Skip to main content

Python library for rapid GPU shader prototyping using Vulkan

Project description

Bazalt

Bazalt is a modern Python library for rapid prototyping and building graphical applications using the Vulkan API. It provides a clean, intuitive interface over a high-performance C++ core, allowing developers to create rendering applications quickly without the typical boilerplate.

Installation

You can install bazalt easily via pip:

pip install bazalt

Prebuilt wheels are provided for Windows and Linux. Building from source requires a C++23 compiler — GCC 14+ or MSVC 19.36+ (Visual Studio 17.6) — and the Vulkan SDK.

Key Features

  • Modern Graphics API: Built on top of Vulkan for optimal hardware utilization.
  • Easy to Use Interface: Write clear and concise code with an intuitive API.
  • Automatic Shader Compilation: Compile GLSL shaders (Vertex/Fragment) directly from your code.
  • Pipeline & Buffer Management: Easy builder pattern for graphics pipelines and unified buffer creation.
  • Command Buffers: Explicit, yet simple command recording — calls chain (cmd.bind_pipeline(p).draw(3)), and with cmd.rendering(target): closes the pass for you.
  • Asynchronous Texture Streaming: ctx.load_image() returns immediately while the decode and GPU copy run in the background; anything that samples the image waits for it automatically. ctx.upload_progress gives you a loading bar for free.
  • Headless Rendering: Draw into an offscreen RenderTarget and read the pixels back as a NumPy array — no window, no display required.
  • Render-to-Texture, MRT & Shadow Maps: Target attachments are ordinary Image objects in any supported Format — sample target.color[0] or a depth-only target's target.depth like any texture.
  • Runs Widely: Vulkan 1.2 baseline with 1.3 used where available, so bazalt runs on older integrated GPUs too. Capabilities are requested by name, never by version or extension.
  • Decoupled Architecture: Clean separation of concerns between Windowing (GLFW), Vulkan Context (GPU initialization), and render targets — a window is one target among others.

Quick Start: Rendering Without a Window

Everything below works with no display attached, which makes it usable from CI and tests:

import bazalt as bz

ctx = bz.Context()
target = bz.RenderTarget(ctx, 800, 600, depth=bz.Format.D32F)

pipeline = (ctx.pipeline_builder()
    .vertex_shader(ctx.compile_shader("triangle.vert", bz.ShaderStage.VERTEX))
    .fragment_shader(ctx.compile_shader("triangle.frag", bz.ShaderStage.FRAGMENT))
    .vertex_format([bz.VertexFormat.FLOAT3, bz.VertexFormat.FLOAT3])
    .build(target))

# Interleaved position (x,y,z) and color (r,g,b)
vbuf = ctx.create_buffer([
     0.0, -0.5, 0.0,   1.0, 0.0, 0.0,
    -0.5,  0.5, 0.0,   0.0, 1.0, 0.0,
     0.5,  0.5, 0.0,   0.0, 0.0, 1.0,
], bz.BufferType.VERTEX, bz.MemoryUsage.STATIC, bz.DataType.FLOAT)

cmd = ctx.create_command_buffer()
cmd.begin()
with cmd.rendering(target, clear_color=[0.1, 0.2, 0.3, 1.0]) as c:
    c.bind_pipeline(pipeline).bind_vertex_buffer(vbuf).draw(3)

ctx.submit(cmd)

pixels = target.read_pixels()   # numpy (600, 800, 4) uint8

Quick Start: Drawing a Triangle

Here is a minimal example demonstrating how to initialize the window, Vulkan Context, and SwapchainRenderer, compile shaders, create a pipeline, and draw a colorful triangle.

import bazalt as bz

# 1. Initialize Logger and register a callback.
#    Each message carries its severity and source as data, so you can filter
#    without parsing strings. This is optional: a Context created without one
#    reports warnings on stderr by default.
logger = bz.Logger(min_severity=bz.Severity.WARNING)
@logger.on_message
def on_message(msg):
    print(f"[{msg.severity}] {msg.text}")

# 2. Create the window, Vulkan Context, and SwapchainRenderer
window = bz.Window(1024, 720, "Bazalt Demo - Triangle", logger=logger)
ctx = bz.Context(logger)
renderer = bz.SwapchainRenderer(window, ctx)

if __name__ == "__main__":
    # Load and compile shaders. The vertex shader processes our geometry,
    # and the fragment shader determines the final color of the pixels.
    # Shaders are compiled through the Context.
    vert_spv = ctx.compile_shader("triangle.vert", bz.ShaderStage.VERTEX)
    frag_spv = ctx.compile_shader("triangle.frag", bz.ShaderStage.FRAGMENT)

    # The pipeline is a baked state object that tells the GPU how to interpret our data.
    # It is built against a render target, which supplies the color/depth formats.
    # A SwapchainRenderer is one, so is an offscreen RenderTarget — same call.
    pipeline = (ctx.pipeline_builder()
        .vertex_shader(vert_spv)
        .fragment_shader(frag_spv)
        .vertex_format([bz.VertexFormat.FLOAT3, bz.VertexFormat.FLOAT3]) # Position + Color
        .build(renderer))

    # We interleave Position (x,y,z) and Color (r,g,b) in a single flat array.
    # Vulkan's Normalized Device Coordinates (NDC) range from -1 to 1,
    # where Y points downwards and X points to the right.
    vertices = [
         0.0, -0.5, 0.0,   1.0, 0.0, 0.0, # Top / Red
        -0.5,  0.5, 0.0,   0.0, 1.0, 0.0, # Bottom-Left / Green
         0.5,  0.5, 0.0,   0.0, 0.0, 1.0, # Bottom-Right / Blue
    ]
    
    # Create Vertex Buffer through the Context
    vbuf = ctx.create_buffer(vertices, bz.BufferType.VERTEX, bz.MemoryUsage.STATIC, bz.DataType.FLOAT)
    
    # Create Index Buffer through the Context
    ibuf = ctx.create_buffer([0, 1, 2], bz.BufferType.INDEX, bz.MemoryUsage.STATIC, bz.DataType.UINT32)

    # Command buffers store a sequence of commands for the GPU.
    # For a static triangle, we can record this buffer once during initialization 
    # and submit the same pre-recorded buffer every frame to save CPU time.
    cmd = ctx.create_command_buffer()

    cmd.begin()

    # begin_rendering names the target you are drawing into, clears it, and sets
    # a viewport and scissor covering it. Naming the target is what lets the same
    # code render to a window or to an offscreen image.
    cmd.begin_rendering(renderer, clear_color=[0.1, 0.2, 0.3, 1.0])

    # Bind the baked pipeline and the geometry buffers
    cmd.bind_pipeline(pipeline)
    cmd.bind_vertex_buffer(vbuf)
    cmd.bind_index_buffer(ibuf)

    # Draw 3 indices (1 triangle)
    cmd.draw_indexed(3)
    cmd.end_rendering(renderer)

    # Main game/rendering loop
    while window.is_open():
        window.poll_events()
        
        # begin_frame returns a Frame, or None when this frame should be
        # skipped (window minimized, mid-resize)
        if frame := renderer.begin_frame():
            frame.submit(cmd)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

bazalt-0.5.0-cp313-cp313-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.13Windows x86-64

bazalt-0.5.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

bazalt-0.5.0-cp312-cp312-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.12Windows x86-64

bazalt-0.5.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

bazalt-0.5.0-cp311-cp311-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.11Windows x86-64

bazalt-0.5.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

bazalt-0.5.0-cp310-cp310-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.10Windows x86-64

bazalt-0.5.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file bazalt-0.5.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: bazalt-0.5.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bazalt-0.5.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c83468271ef5137895aac486c18ff72317b8332c9f99713297c5adf83128f830
MD5 fc7d38c0fbc1708bfc370005abf493e6
BLAKE2b-256 035758b5a009799c9eaa3e035e0bfe0827dcd21882691533c5adefc73e8ba416

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.5.0-cp313-cp313-win_amd64.whl:

Publisher: build.yml on SzamockiP/bazalt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bazalt-0.5.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bazalt-0.5.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d1a3a7a8661ba878a0ff2c026b067d8638a1115a39e49138653a4ce7f9dfcecc
MD5 f8dafbdc9e728e0bd7f266d53e5d0522
BLAKE2b-256 6f65f6c108389a4a9a54183ecc16a2b1059548a040878e578dd1e845ebc9d9a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.5.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on SzamockiP/bazalt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bazalt-0.5.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: bazalt-0.5.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bazalt-0.5.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 dabcc2826b6108e9f90eafabfc72876f72bdfdf230553153f40f596cb565091c
MD5 1d74c180a616cab820a7a72f12185f71
BLAKE2b-256 2238b64e8849e9d933362ce1c74ff5bf0b929d8df54732ad8f183619edf3a24e

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.5.0-cp312-cp312-win_amd64.whl:

Publisher: build.yml on SzamockiP/bazalt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bazalt-0.5.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bazalt-0.5.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 21ed9133f192733a0fa530ac14b1ffce8d84c27928bbf07a131cabbe8e35969c
MD5 8d0c9a7c8ec86a6881c8b3833c80e7a9
BLAKE2b-256 dc060efd4fe2ab734eff3fd15b4550fa1832e39329f8917eb8a3aaef8a794e63

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.5.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on SzamockiP/bazalt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bazalt-0.5.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: bazalt-0.5.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bazalt-0.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ec67ec6d50386678f765109d55b9c890a4de41f6056ddcade2600da62ec7a40a
MD5 1fb5ad75044367831dca71084e376b6a
BLAKE2b-256 8d9c0ddb7dd732ccf8daf453d3aa46e8aa7ee918a86c7846e8f8587c7494a305

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.5.0-cp311-cp311-win_amd64.whl:

Publisher: build.yml on SzamockiP/bazalt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bazalt-0.5.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bazalt-0.5.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4daf441d6a82dcd2583858cb1233e741ac718b68f544ca9c9209fa9fff4daef4
MD5 f037d792225e0d3c0f679849c0c3d4bf
BLAKE2b-256 26f0b34971ad5660e936f62ce235ef02709f57f16e5a346dbdb36d21499e90f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.5.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on SzamockiP/bazalt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bazalt-0.5.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: bazalt-0.5.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.5 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bazalt-0.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4d2f47bc9c0c66d2b1e4450cd6c6f9cd5daca6353ec20c70217403714a7530e3
MD5 4d47f98e0e646274b947423fb065324a
BLAKE2b-256 b0f7f5049844a0875d6ac184a3752257dc99bc79a257bc8832044b3fe1d8f0f4

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.5.0-cp310-cp310-win_amd64.whl:

Publisher: build.yml on SzamockiP/bazalt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bazalt-0.5.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bazalt-0.5.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 75c115429eb6b749397b7ce61383693f7e4049136d649ebd8668feaf167a517e
MD5 2ff4a24a3f3467d4fbfb938897ebdffb
BLAKE2b-256 04cd0063d7e283f972aebc74ba37fb2f3ba84a9f42d6ab4a4617137408ccb0c6

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.5.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: build.yml on SzamockiP/bazalt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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