Skip to main content

Declarative GUI framework for Python and Qt

Project description

Edifice
Declarative GUI framework for Python and Qt

Edifice is a Python library declarative framework for application user interfaces.

  • Modern declarative UI paradigm from web development.
  • 100% Python application development, no language inter-op.
  • A native Qt desktop app instead of a bundled web browser.
  • Fast iteration via hot-reloading.

Edifice uses PySide6 or PyQt6 as a backend. Edifice is like React, but with Python instead of JavaScript, and Qt Widgets instead of the HTML DOM.

If you have React experience, you’ll find Edifice easy to learn. Edifice has function Components, Props, and Hooks just like React.

Getting Started

Why Edifice?

Declarative

Most existing GUI libraries in Python, such as Tkinter and Qt, operate imperatively. To create a dynamic application using these libraries, you must not only think about what widgets to display to the user, but also how to issue the commands to modify the widgets.

With Edifice the developer need only declare what is rendered, not how the content is rendered.

User interactions update the application state, the state renders to a widget tree, and Edifice modifies the existing widget tree to reflect the new state.

Edifice code looks like this:

    number, set_number = use_state(0)

    with VBoxView():
        Button(title="Add 5", on_click=lambda event: set_number(number+5))
        Label(text=str(number))
        if number > 30 and number < 70:
            Label(
              text="Number is mid",
              style={"color": "green"},
            )

The GUI displays a button and a label with the current value of number. Clicking the button will add 5 to the number. If the number is “mid” then another label will reveal that fact.

Edifice vs. Qt Quick

Qt Quick is Qt’s declarative GUI framework for Qt.

Qt Quick programs are written in Python + the special QML language + JavaScript.

Edifice programs are written in Python.

Because Edifice programs are only Python, binding to the UI is much more straightforward. Edifice makes it easy to dynamically create, mutate, shuffle, and destroy sections of the UI. Qt Quick assumes a much more static interface.

Qt Quick is like DOM + HTML + JavaScript. Edifice is like React. QML and HTML are both declarative UI languages but they require imperative logic in another language for dynamism. Edifice and React allow fully dynamic applications to be specified declaratively in one language.

How it works

An Edifice component is a render function which declares a mapping from props and state to UI widgets. props are passed as arguments to the component when it renders. state is the component’s own internal state.

Changes to props or state will trigger a re-render of the component. The old and new component trees will be compared to one another, and a diffing algorithm (similar to the React diffing algorithm) will determine which UI widgets must be added, removed or modified. Then Edifice will issue the minimal commands to update the UI.

MANUFACIA-Vision_capture1

Development Tools

Dynamic hot-reload

Dyanamic hot-reload is very useful for fine-tuning the presentation styles of Elements deep within your application. You can test if the margin should be 10px or 15px instantly without closing the app, reopening it, and waiting for everything to load.

Element Inspector

Similar to the Inspect Elements tool of a browser, the Element Inspector will show you the tree of Elements in a running Edifice application, along with all of the props and state of the Elements.

License

Edifice is MIT Licensed.

Edifice uses Qt under the hood, and both PyQt6 and PySide6 are supported. Note that PyQt6 is distributed with the GPL license while PySide6 is distributed under the more flexible LGPL license.

See PyQt vs PySide Licensing.

Can I use PySide for commercial applications?

Yes, and you don't need to release your source code to customers. The LGPL only requires you to release any changes you make to PySide itself.

Version History / Change Log / Release Notes

See Release Notes (source: versions.rst)

Contribution

Contributions are welcome; please send Pull Requests! See DEVELOPMENT.md for development notes.

When submitting a Pull Request, think about adding tests to tests and adding a line to the Unreleased section of the change log versions.rst.

Setuptools Build System

The Setuptools pyproject.toml specifies the package dependecies.

Because Edifice supports PySide6 and PyQt6 at the same time, neither are required by dependencies. A project which depends on Edifice should also depend on either PySide6-Essentials or PySide6 or PyQt6.

Add an Edifice dependency to pyproject.toml:

dependencies = [
  "pyedifice",
  "PySide6-Essentials",
]

There are optional dependency groups provided for PySide6-Essentials and PyQt6:

dependencies = [
  "pyedifice [PySide6-Essentials]"
]

The requirements.txt is generated by

uv export --format requirements-txt --no-dev > requirements.txt

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

pyedifice-4.1.0.tar.gz (399.2 kB view details)

Uploaded Source

Built Distribution

pyedifice-4.1.0-py3-none-any.whl (855.6 kB view details)

Uploaded Python 3

File details

Details for the file pyedifice-4.1.0.tar.gz.

File metadata

  • Download URL: pyedifice-4.1.0.tar.gz
  • Upload date:
  • Size: 399.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for pyedifice-4.1.0.tar.gz
Algorithm Hash digest
SHA256 8ec93dcc2ccb029769740fc178408b7e60a6ee810611e005c2b4a0ef0154ee26
MD5 367303b0d36149132af1a396bca44979
BLAKE2b-256 b7c586121fa98a60e1a538bead6368aa02148c19b1b04163a2429086220c2987

See more details on using hashes here.

File details

Details for the file pyedifice-4.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyedifice-4.1.0-py3-none-any.whl
  • Upload date:
  • Size: 855.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.11

File hashes

Hashes for pyedifice-4.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 22ba1a142106c74c4d7d2e79ef91ec3cd5d139c1280f0cca170dfeb482f2faa1
MD5 dc1e5da43eeae693dafcfe0c21707f11
BLAKE2b-256 ef3a6c9ded96fdd320db2a26f2290c0fb88392f06643c99503ef4538bd119f91

See more details on using hashes here.

Supported by

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