Skip to main content

Reactive user interfaces

Project description

PyPI version CI status

Collagraph 📓

Reactive user interfaces.

The word Collagraphy is derived from the Greek word koll or kolla, meaning glue, and graph, meaning the activity of drawing.

Inspired by Vue and React.

Features

Write your Python interfaces in a declarative manner with plain render functions, component classes or even single-file components using Vue-like syntax, but with Python!

  • Reactivity (made possible by leveraging observ)
  • Class components with local state and life-cycle methods/hooks
  • Single-file components with Vue-like template syntax (.cgx files)
  • Custom renderers

Here is an example that shows a counter, made with a component with Vue-like syntax:

Contents of counter.cgx:

<widget>
  <label
    :text="f'Count: {count}'"
  />
  <button
    text="bump"
    @clicked="bump"
  />
</widget>

<script>
import collagraph as cg


class Counter(cg.Component):
    def init(self):
        self.state["count"] = 0

    def bump(self):
        self.state["count"] += 1
</script>

Contents of app.py:

from PySide6 import QtWidgets
import collagraph as cg

# After importing collagraph, it's possible to import
# components directly from .cgx files
from counter import Counter

# Create a Collagraph instance with a PySide renderer
# and register with the Qt event loop
gui = cg.Collagraph(renderer=cg.PySideRenderer())
# Render the component into a container
# (in this case the app but can be another widget)
app = QtWidgets.QApplication()
gui.render(Counter, app)
app.exec()

Which looks something like this:

collagraph example

Instead of using a python file as an entry point to run components, you can run them directly using the collagraph CLI:

uv run collagraph examples/pyside/counter.cgx

For more examples, please take a look at the examples folder.

Currently there are two renderers:

It is possible to create a custom Renderer using the Renderer interface, to render to other UI frameworks, for instance wxPython.

Development

To try out Collagraph or start development, run:

# Basic dev setup (no pygfx or pyside)
uv sync
# Full dev setup
uv sync --all-groups
# Run example:
uv run python examples/pyside/layout-example.py
# Run test suite:
uv run pytest
# Install git pre-commit hooks to make sure tests/linting passes before committing
uv run pre-commit install

Syntax Highlighting

Syntax highlighting for single-file components (.cgx) is supported for VSCode and Sublime Text:

Formatting and linting

Linting and formatting cgx files is possible with: ruff-cgx.

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

collagraph-0.8.8.tar.gz (84.7 kB view details)

Uploaded Source

Built Distribution

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

collagraph-0.8.8-py3-none-any.whl (50.5 kB view details)

Uploaded Python 3

File details

Details for the file collagraph-0.8.8.tar.gz.

File metadata

  • Download URL: collagraph-0.8.8.tar.gz
  • Upload date:
  • Size: 84.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for collagraph-0.8.8.tar.gz
Algorithm Hash digest
SHA256 67b499d5785b1317b06de99d134c93ff66f9827b66f9591782e622225dfb0a83
MD5 b6b5aed673d95712caa64788f60a6b8a
BLAKE2b-256 e4720b7246be22efe4be7640fe0d43e54c677466ee17189d1498bfada40816e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for collagraph-0.8.8.tar.gz:

Publisher: ci.yml on fork-tongue/collagraph

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

File details

Details for the file collagraph-0.8.8-py3-none-any.whl.

File metadata

  • Download URL: collagraph-0.8.8-py3-none-any.whl
  • Upload date:
  • Size: 50.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for collagraph-0.8.8-py3-none-any.whl
Algorithm Hash digest
SHA256 f653f33c5e445b6c345849b6cdbca5bfe81fc59088ae7ea003ef7d8f9e6fd89b
MD5 494d6e84386379c850b20931d4cbe60b
BLAKE2b-256 8fedc41b08ae06e16c7d3c2cd78a3d386cfc9bb983eb1f65ce03b4cc712dd76d

See more details on using hashes here.

Provenance

The following attestation bundles were made for collagraph-0.8.8-py3-none-any.whl:

Publisher: ci.yml on fork-tongue/collagraph

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