Skip to main content

PyPI version CI status Docs

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. Check out the documentation to get started.

Features

Write your Python interfaces in a declarative manner as single-file components with Vue-like syntax (.cgx files), but with Python!

  • Fine-grained 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)
  • Renderers for PySide6 and Pygfx, with support for custom renderers

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

Contents of counter.cgx:

<widget>
  <label>Count: {{ count }}</label>
  <button @clicked="bump">bump</button>
</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

To inspect the Python code that is compiled for a component, use the --show-code flag:

uv run collagraph --show-code examples/pyside/counter.cgx

For more examples, please take a look at the examples folder. For guides and API reference, visit the documentation.

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 prek install

Editor Integration

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

These plugins use collagraph-lsp for editor integration and ruff-cgx for formatting and linting capabilities.

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.10.0.tar.gz (192.8 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.10.0-py3-none-any.whl (80.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for collagraph-0.10.0.tar.gz
Algorithm Hash digest
SHA256 dcc682846f5ff272ee33a2db42b6dca3468d986798c2524f75b827c093fb9e31
MD5 8b004d47dd1478999df3eaa3e43f498a
BLAKE2b-256 10ff12929e321d0f22ce366f8a56fa5b24116cde7348287f7bda5d346ac78e81

See more details on using hashes here.

Provenance

The following attestation bundles were made for collagraph-0.10.0.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.10.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for collagraph-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 79bf8b4d8d2627f96c1b8fe6804d06cf6972ab24461236fcfd34abfa3533ca6d
MD5 332f46d5a2837c45eb92fe2cfdc66c52
BLAKE2b-256 911e63bf060ee63e8e95da1b53ff06d7c3197399d6e2d4405933e72ce06435b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for collagraph-0.10.0-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 Sentry Error logging StatusPage Status page