slint
Native GUI toolkit for Python: build desktop and embedded apps with a declarative UI language and live preview
Downloads & Community Adoption
Health & Engineering Analysis (5 Pillars)
1. Governance & Community150 / 200 ▾
2. PEP Metadata & Packaging200 / 200 ▾
3. Security & Supply Chain200 / 200 ▾
4. Documentation, SEO & Ecosystem155 / 200 ▾
5. Engineering, CI & Quality165 / 200 ▾
Official Documentation & Usage Guide — slint
Show full original documentation (English README) ▾
Slint-python (Beta)
Slint is a GUI toolkit to build native user interfaces for any device,
with Python, Rust, C++, or JavaScript.
Slint-python is the Python API for desktop and embedded Linux apps.
Describe your UI in the .slint language and connect it to your Python code.
Warning Slint-python is in a beta phase of development: the APIs, while mostly stable, may be subject to further changes. Any changes will be documented in the ChangeLog.
You can track the progress of the Python integration in the python-labeled issues.
Slint Language Manual
The Slint Language Documentation covers the Slint UI description language in detail.
Prerequisites
Installation
Install Slint with uv or pip from the Python Package Index:
uv add slint
The installation uses binaries provided for macOS, Windows, and Linux for various architectures. If your target platform
isn't covered by binaries, uv automatically builds Slint from source. In that case, you need some
software development tools on your machine, as well as Rust.
Quick Start
- Create a new project with
uv init. - Add the Slint Python package to your Python project:
uv add slint - Create a file called
app-window.slint:
import { Button, VerticalBox } from "std-widgets.slint";
export component AppWindow inherits Window {
in-out property<int> counter: 42;
callback request-increase-value();
VerticalBox {
Text {
text: "Counter: \{root.counter}";
}
Button {
text: "Increase value";
clicked => {
root.request-increase-value();
}
}
}
}
- Create a file called
main.py:
import slint
# slint.loader looks in `sys.path` for `app-window.slint`.
class App(slint.loader.app_window.AppWindow):
@slint.callback
def request_increase_value(self):
self.counter = self.counter + 1
app = App()
app.run()
- Run it with
uv run main.py.
API Overview
Instantiating a Component
The following example shows how to instantiate a Slint component in Python:
app.slint
export component MainWindow inherits Window {
callback clicked <=> i-touch-area.clicked;
in property <int> counter;
width: 400px;
height: 200px;
i-touch-area := TouchArea {}
}
The exported component is exposed as a Python class. To access this class, you have two options:
-
Call
slint.load_file("app.slint"). The returned object is a namespace that provides theMainWindowclass as well as any other explicitly exported component that inheritsWindow:import slint components = slint.load_file("app.slint") main_window = components.MainWindow() -
Use Slint's auto-loader, which lazily loads
.slintfiles fromsys.path:import slint # Look for `app.slint` in `sys.path`: main_window = slint.loader.app.MainWindow()slint.loadersearchessys.pathfor any attribute you look up. If a directory with that name exists, the loader returns it as a loader object; subsequent attribute lookups follow the same logic.If the name matches a file with the
.slintextension, the loader loads it withload_fileand returns the namespace.If the file name contains a dash, like
app-window.slint, an attribute lookup forapp_windowtries to locateapp_window.slintand then falls back toapp-window.slint.To load your project file (
slint-project.json), look upslint_projectin its directory. The loader passes the directory toload_file, which compiles your project'smainfile with the project's settings:# Look for `ui/slint-project.json` in `sys.path`: main_window = slint.loader.ui.slint_project.MainWindow()Note: Other
.slintfiles in that directory load without the project file, so its include paths and library paths don't apply to them.
Accessing Properties
Properties declared as out or in-out in .slint files are visible as
properties on the component instance.
main_window.counter = 42
print(main_window.counter)
Accessing Globals
You can access global singletons in Python as properties of the component instance.
For example, this Slint code declares a PrinterJobQueue singleton:
export global PrinterJobQueue {
in-out property <int> job-count;
}
Access it as a property on the component instance by its name:
print("job count:", instance.PrinterJobQueue.job_count)
Note: Global singletons are instantiated once per component. When you export multiple components to Python, each instance has its own associated global singletons.
Setting and Invoking Callbacks
Callbacks declared in .slint files are visible as callable properties on the
component instance. Call them as functions to invoke the callback, and assign a Python callable to set the callback handler.
In Slint, you define callbacks with the callback keyword and connect them to another component's callback with
the <=> syntax.
my-component.slint
export component MyComponent inherits Window {
callback clicked <=> i-touch-area.clicked;
width: 400px;
height: 200px;
i-touch-area := TouchArea {}
}
The callbacks are exposed as properties that you can call as functions:
main.py
import slint
component = slint.loader.my_component.MyComponent()
# Connect to a callback.
def clicked():
print("hello")
component.clicked = clicked
# Invoke a callback.
component.clicked()
Another way to set callbacks is to subclass the component and use the @slint.callback decorator:
import slint
class Component(slint.loader.my_component.MyComponent):
@slint.callback
def clicked(self):
print("hello")
component = Component()
If the name of your method doesn't match the name of the callback in the .slint file, pass a name argument to the
@slint.callback() decorator. Similarly, to bind a method to a callback in a global singleton, pass a global_name
argument.
Type Mappings
Each type used for properties in the Slint language translates to a specific type in Python. See the type mappings table in the Slint Python documentation for the complete list.
Arrays and Models
You can set array properties from Python by passing subclasses of
slint.Model.
Use the slint.ListModel class to construct a model from an iterable:
component.model = slint.ListModel([1, 2, 3])
component.model.append(4)
del component.model[0]
When sub-classing slint.Model, provide the following methods:
def row_count(self):
"""Return the number of rows in your model"""
def row_data(self, row):
"""Return data at specified row"""
def set_row_data(self, row, data):
"""For read-write models, store data in the given row. When done, call notify_row_changed."""
...
self.notify_row_changed(row)
When adding or inserting rows, call notify_row_added(row, count) on the superclass. Similarly, when removing rows, notify
Slint by calling notify_row_removed(row, count).
Structs
Structs that you declare and export in Slint are accessible in the namespace that's returned
when instantiating a component.
app.slint
export struct MyData {
name: string,
age: int
}
export component MainWindow inherits Window {
in-out property <MyData> data;
}
main.py
The exported MyData struct can be constructed as follows:
import slint
# Look for for `app.slint` in `sys.path`:
main_window = slint.loader.app.MainWindow()
data = slint.loader.app.MyData(name="Simon")
data.age = 10
main_window.data = data
Enums
Enums that you declare and export in Slint are accessible in the namespace that's returned
when instantiating a component. The enums are subclasses of enum.Enum.
app.slint
export enum MyOption {
Variant1,
Variant2
}
export component MainWindow inherits Window {
in-out property <MyOption> data;
}
main.py
Variants of the exported MyOption enum can be constructed as follows:
import slint
# Look for for `app.slint` in `sys.path`:
main_window = slint.loader.app.MainWindow()
value = slint.loader.app.MyOption.Variant2
main_window.data = value
Asynchronous I/O
Use Python's asyncio library to write concurrent Python code with the async/await syntax.
Slint's event loop is a full-featured asyncio event loop. While
the event loop is running, asyncio.get_running_loop() returns
a valid loop. To run an async function when starting the loop, pass a coroutine to slint.run_event_loop().
For the common use case of interacting with REST APIs, we recommend the aiohttp library.
Known Limitations
- Pipes and sub-processes are only supported on Unix-like platforms.
Type Hints
PEP 484 introduces a standard syntax for type annotations to Python, enabling static analysis for type checking, refactoring, and code completion. Popular type checkers include mypy, Pyre, and Astral's ty.
Use Slint's slint-compiler to generate .py files with type annotations for your .slint files.
They replace calls to load_file and any use of slint.loader.
- Create a new project with
uv init. - Add the Slint Python package to your Python project:
uv add slint - Create a file called
app-window.slint:
import { Button, VerticalBox } from "std-widgets.slint";
export component AppWindow inherits Window {
in-out property<int> counter: 42;
callback request-increase-value();
VerticalBox {
Text {
text: "Counter: \{root.counter}";
}
Button {
text: "Increase value";
clicked => {
root.request-increase-value();
}
}
}
}
-
Run the slint-compiler to generate
app_window.py:uvx slint-compiler -f python -o app_window.py app-window.slintIf your
slint-project.jsonsets"main": "app-window.slint", pass the project file or its directory:uvx slint-compiler -f python -o app_window.py slint-project.json. The generated module loads that project at run time, too. -
Create a file called
main.py:
import slint
import app_window
class App(app_window.AppWindow):
@slint.callback
def request_increase_value(self):
self.counter = self.counter + 1
app = App()
app.run()
- Run it with
uv run main.py.
License
Slint is open source and available under three licenses: you pick the one that fits your app.
- If your app is open source, use the GNU GPLv3, a widely used, OSI-approved open-source license. It covers any platform, including embedded devices.
- If your app is closed source and runs on desktop, mobile, or the web,
use the Royalty-free License.
It's free of charge, and only asks you to credit Slint, with the
AboutSlintwidget or the Slint badge on your website. - If your app is closed source and runs on an embedded device, buy a commercial license. See the pricing.
Your own code can stay under a permissive license such as MIT or Apache-2.0. Anyone who forks it chooses their own Slint license, so they can reuse it in a closed-source app. The Licensing FAQ covers the details.
Third-Party Licenses
For a list of the third-party licenses of all dependencies, see the separate Third-Party Licenses page.