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

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 for drawing operations.
  • Decoupled Architecture: Clean separation of concerns between Windowing (GLFW), Vulkan Context (GPU initialization), and Surface Presenting (SwapchainRenderer).

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
logger = bz.Logger()
@logger.on_error
def error(msg):
    print(f"Error: {msg}")

# 2. Create the window, Vulkan Context, and SwapchainRenderer
window = bz.Window(1024, 720, "Bazalt Demo - Triangle")
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 via the Context's pipeline_builder and compiled against the renderer
    # to inherit compatible color/depth format options.
    pipeline = (ctx.pipeline_builder()
        .vertex_shader(vert_spv)
        .fragment_shader(frag_spv)
        .vertex_format([bz.Format.FLOAT3, bz.Format.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 = renderer.create_command_buffer()
    
    cmd.begin()
    
    # begin_rendering starts a render pass, automatically handling framebuffers
    # and clearing the screen to the specified color before drawing.
    cmd.begin_rendering(clear_color=[0.1, 0.2, 0.3, 1.0])
    cmd.set_viewport()
    cmd.set_scissor()
    
    # 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()

    # Main game/rendering loop
    while window.is_open():
        window.poll_events()
        
        # begin_frame returns True if the swapchain image is ready for rendering
        if renderer.begin_frame():
            renderer.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.3.0-cp313-cp313-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.13Windows x86-64

bazalt-0.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.2 MB view details)

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

bazalt-0.3.0-cp312-cp312-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.12Windows x86-64

bazalt-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.2 MB view details)

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

bazalt-0.3.0-cp311-cp311-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.11Windows x86-64

bazalt-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.2 MB view details)

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

bazalt-0.3.0-cp310-cp310-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.10Windows x86-64

bazalt-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (4.2 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.3.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: bazalt-0.3.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.3 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.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 011b03226c0c894499e8780b5fa3d1cf4a70745c5b25fa88335f5bbea92a100c
MD5 24eda9d73b65e847bb0585575362132d
BLAKE2b-256 6f63c557e4cadf156297054ec7f3d47ac81ce79ac49715c0e1703a98384b43e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.3.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.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bazalt-0.3.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 df04a7dfe0d063dac400ec021fc32a4916902e775f316401a274868d3fb186e4
MD5 2fc28bef30862fb8a33ea1aef46a6eca
BLAKE2b-256 4db547d003766ae16eaa27311f880715d20646d9349682d25fb8d074be3a8243

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.3.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.3.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: bazalt-0.3.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.3 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.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 62e0161c25312313af8cbfc0965be27f14ef9b534742135efc544a703902147b
MD5 0e3633507f968687935f63b3accf4f23
BLAKE2b-256 a19cf120d9d9e85c0aff1a3625ebdc2fb85ae2ca95517bd7890438d6f42a818f

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.3.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.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bazalt-0.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 586afe80683a8f3e16550bb9c1ddadee0e4c76ef04971ef9f407f44fab96ebf1
MD5 c492f7d8815c6e184d4e0efa7978fab8
BLAKE2b-256 ffb25891324877935680ec0607663fb6696eaf46b29fe78fc84a0baeca50db8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.3.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.3.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: bazalt-0.3.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.3 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.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 9676a4f1c9dcaada3bc290a9188b2ebfca62544df2f7a38dc2a09f5219c8f264
MD5 ada598c48de1fbbdeb61b9cad94892d7
BLAKE2b-256 1bfa2c19d07a1a5d60611c5a2f32639e9bca57657fab2a1e38d703eea8d275dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.3.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.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bazalt-0.3.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a756b5f1b08a0f015f7faddd0dd35c0afc477bd9eec28a9a471bc4bf7dfe89a5
MD5 b29193e8ac43772ecfc161199915fdf7
BLAKE2b-256 e8efd9b175c3fb6acfe2b6d6ef4fe9d6a321e1ae66c325da76d37b8c5e8f1558

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.3.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.3.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: bazalt-0.3.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.3 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.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1437da3d7bbbab44cf865bee0f64ef9935923e2f8249ed7025db0baf6d719bd7
MD5 c92de2ebb2e892998d1851f788241f9e
BLAKE2b-256 cab135bdbaf638554d4e3d0defbc2270070df8ff2b404f8492b8685129868536

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.3.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.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bazalt-0.3.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 acb15b12e9614fc595a50cf854bd94cd08ed21171329e15298a07e1fd849418d
MD5 c4d5c005ccae19846174e4e6678af722
BLAKE2b-256 92488fac8c4ba4a8eb8976d053e4e7aad4c92ec91a9032ef2df67179f2702291

See more details on using hashes here.

Provenance

The following attestation bundles were made for bazalt-0.3.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