Skip to main content

CI Documentation Status PyPI version EffVer Versioning Zenodo badge


rendercanvas

One canvas API, multiple backends 🚀

This project is part of pygfx.org

Introduction

See how the two windows above look the same? That's the idea; they also look the same to the code that renders to them. Yet, the GUI systems are very different (Qt vs glfw in this case). Now that's a powerful abstraction!

Purpose

Providing a generic API for:

  • managing a canvas window (BaseRenderCanvas).
  • presenting rendered results with wgpu (WgpuContext).
  • presenting rendered results as a bitmap (BitmapContext).
  • working with events that have standardized behavior.

The following backends are currently available:

  • auto - automatically selects an appropriate backend.
  • glfw - a native desktop window.
  • offscreen - for offscreen rendering.
  • terminal - to render in the terminal (e.g. over SSH).
  • qt (pyside6 / pyside2 / pyqt6 / pyqt5) - to embed a render canvas in a qt GUI.
  • wx - to embed a render canvas in a wx GUI.
  • anywidget - for notebooks like Jupyter, VSCode, and Marimo.
  • jupyter - previous backend for notebooks that uses jupyter_rfb.
  • http - for server side rendering, display in a browser connected via the internet.
  • pyodide - to run in the browser with Pyodide or PyScript.

In addition to the GUI libraries mentioned above, the following event loops are supported:

  • asyncio
  • trio
  • raw

Installation

pip install rendercanvas

To have at least one backend, we recommend:

pip install rendercanvas glfw

Usage

Also see the online documentation and the examples.

A minimal example that renders noise:

import numpy as np
from rendercanvas.auto import RenderCanvas, loop

canvas = RenderCanvas(update_mode="continuous")
context = canvas.get_bitmap_context()

@canvas.request_draw
def animate():
    w, h = canvas.get_logical_size()
    bitmap = np.random.uniform(0, 255, (h, w)).astype(np.uint8)
    context.set_bitmap(bitmap)

loop.run()

Run wgpu visualizations:

from rendercanvas.auto import RenderCanvas, loop
from rendercanvas.utils.cube import setup_drawing_sync


canvas = RenderCanvas(
    title="The wgpu cube example on $backend", update_mode="continuous"
)
draw_frame = setup_drawing_sync(canvas)
canvas.request_draw(draw_frame)

loop.run()

Embed in a Qt application:

from PySide6 import QtWidgets
from rendercanvas.qt import QRenderWidget

class Main(QtWidgets.QWidget):

    def __init__(self):
        super().__init__()

        splitter = QtWidgets.QSplitter()
        self.canvas = QRenderWidget(splitter)
        ...


app = QtWidgets.QApplication([])
main = Main()
app.exec()

Async or not async

We support both; a render canvas can be used in a fully async setting using e.g. Asyncio or Trio, or in an event-driven framework like Qt. If you like callbacks, loop.call_later() always works. If you like async, use loop.add_task(). See the docs on async for details.

License

This code is distributed under the 2-clause BSD license.

Contributing

See the contribution guide.

Development install

  • Clone the repo.
  • Install rendercanvas and developer deps using pip install -e .[dev].

Quick tips

  • Use ruff format to apply autoformatting.
  • Use ruff check to check for linting errors.
  • Use pytest tests to run the tests.
  • Use pytest examples to run a subset of the examples.

Code of Conduct

This repository follows the PyGfx Code of Conduct

Download files

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

Source Distribution

rendercanvas-2.7.0.tar.gz (117.9 kB view details)

Uploaded Source

Built Distribution

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

rendercanvas-2.7.0-py3-none-any.whl (138.0 kB view details)

Uploaded Python 3

File details

Details for the file rendercanvas-2.7.0.tar.gz.

File metadata

  • Download URL: rendercanvas-2.7.0.tar.gz
  • Upload date:
  • Size: 117.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rendercanvas-2.7.0.tar.gz
Algorithm Hash digest
SHA256 0bf1a69585afadc0d9735e2aa54b93a1585db1826d77bc96ee38de674141f65f
MD5 f9dd05e269bef421d41e080cbf48a297
BLAKE2b-256 a3aebcf5c213b8df774cd3fc5ecf57b57603ffd2e101aad40dcdaf0fa38ba264

See more details on using hashes here.

Provenance

The following attestation bundles were made for rendercanvas-2.7.0.tar.gz:

Publisher: ci.yml on pygfx/rendercanvas

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

File details

Details for the file rendercanvas-2.7.0-py3-none-any.whl.

File metadata

  • Download URL: rendercanvas-2.7.0-py3-none-any.whl
  • Upload date:
  • Size: 138.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rendercanvas-2.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6fb44e4c1a3597bc3f6b3061a1c7a8136c78a40d764bd4b607fbf51f1504760
MD5 74e2d25ea85e9b8ebe32630e25491adc
BLAKE2b-256 4da9bbd474593e536859a8fd4468f1e4393f5723fc0cf216b9b6b7a8c2aa108b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rendercanvas-2.7.0-py3-none-any.whl:

Publisher: ci.yml on pygfx/rendercanvas

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

Release history Release notifications | RSS feed

2.7.2

2 files

2.7.1

2 files

This release

2.7.0 This release

2 files

2.6.3

2 files

2.6.2

2 files

2.6.1

2 files

2.6.0

2 files

2.5.2

2 files

2.5.1

2 files

2.5.0

2 files

2.4.2

2 files

2.4.1

2 files

2.4.0

2 files

2.3.0

2 files

2.2.1

2 files

2.2.0

2 files

2.1.2

2 files

2.1.1

2 files

2.1.0

2 files

2.0.4

2 files

2.0.3

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

1.0.0

2 files

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