cui-py
Cython bindings for CUI, an immediate-mode UI library in C99 with about 190 components. The distribution is cui-py; the import name is cui.
CUI 1.4.0 is vendored in thirdparty/cui and compiled into the extension, so there are no runtime dependencies. Linux needs the X11 development headers to build (libx11-dev).
Status: alpha. Tested on macOS (Cocoa, arm64, CPython 3.14). The CI workflows build on Linux and Windows, but those builds have not run yet.
import cui
clicks = 0
def frame(ui: cui.Context) -> None:
global clicks
with ui.column(pad=32, gap=16):
ui.heading("Hello, CUI", 2)
if ui.button("Click me", variant=cui.BUTTON_PRIMARY):
clicks += 1
ui.text(f"Clicked {clicks} times")
cui.App("Hello", 420, 300).run(frame)
examples/ has hello.py, todo.py (a port of CUI's tutorial app), dashboard.py and showcase.py (forms, charts, a node graph, a live Markdown editor and a console; --png DIR saves each page headless).
Install
git clone <this repo> && cd cui-py
uv sync # builds the extension
make test
How the C API maps to Python
-
Names.
cui_button_exisui.button.CUI_BUTTON_PRIMARYiscui.BUTTON_PRIMARY. Icons are strings:cui.ICON_PLUS. -
Options. The fields of a C options struct become keyword-only arguments. An argument you leave out keeps CUI's default.
-
Outputs. A pointer the component writes to becomes a return value, after the component's own result:
changed, value = ui.checkbox("Remember me", value) changed, index = ui.select("fruit", ["apple", "pear"], index)
-
Text fields. A text field edits a
cui.TextBuffer(capacity, value)in place. Capacity counts bytes, including the trailing NUL, as in C. -
Log and terminal.
ui.log_viewreads acui.LogBufferandui.terminalacui.TerminalBuffer. Both are rings that drop the oldest lines when full, and any thread may write to them:log = cui.LogBuffer(lines=4096) log.append("disk almost full", cui.LOG_WARN) # from any thread ui.log_view("log", log, timestamps=True) r = ui.terminal("term", term) if r.command is not None: term.write(f"\x1b[32mran\x1b[0m {r.command}\n")
A write made after the view in the same frame shows from the next frame. CUI cannot be woken from another thread, so call
ui.request_wakeup(seconds)while a thread is writing. -
Lists. A list of strings or floats replaces a C array and its count. A list of records replaces an array of structs. Each record can be a namedtuple (
cui.VizItem(label="a", value=3)), a tuple, or a dict. Missing fields are zero. -
Containers. A begin/end pair is a context manager. When
begincan decline, as a closed dialog does, the scope is falsy andendis skipped:with ui.dialog("Settings", open) as d: if d: ui.text("inside") open = d.open
The scope exposes the pair's outputs as attributes (
d.open,vl.first). The valueendreturns is in.result. -
Values.
-
Colors:
0xRRGGBB,(r, g, b[, a]),cui.rgb(), or theme tokens such ascui.COLOR_ACCENT. -
Sizes: a number in points,
cui.FILL,cui.pct(50)orcui.grow(2). -
Dates:
datetime.date, orNonefor unset.
-
-
Drawing.
ui.canvas(id, width, height, paint)callspaint(rect)after layout. Only there do thedraw_*methods work.
cui.Context() with no window renders headless with CUI's software renderer. Its parts:
-
input arrives through
ui.input_* -
render()andsave_png()read the pixels -
copy and paste use
ctx.clipboard
The tests use this.
Errors instead of crashes
Misuse that would be undefined behaviour in C raises an exception:
-
building outside a frame
-
building inside a paint callback
-
drawing outside one
-
ending a frame with a scope open
-
using a closed context
-
passing strings with NUL characters
-
passing arrays of unequal length
-
passing color channels outside 0..255
-
writing more text than a buffer holds
Strings and arrays passed to CUI stay alive until the frame is painted.
The vendored CUI carries one patch, for state shared by two component types with one id. A narrower case remains; see docs/dev/known-issues.md.
Coverage
The generator wraps 372 entries: 355 Context methods, including 48 scopes, and 17 module functions. Another 35 functions are wrapped by hand. docs/dev/coverage.md lists the 27 functions not wrapped yet and why, and the options that have no keyword argument.
Development
tools/gen_bindings.py reads CUI's headers with libclang and writes these files:
-
src/cui/_cui.pxd -
src/cui/_gen.pxi -
src/cui/_core.pyi -
docs/dev/coverage.md
The output is committed. Run make gen after updating thirdparty/cui. Hand-written code lives in src/cui/_core.pyx.
| Target | |
|---|---|
make build |
rebuild the extension |
make test |
headless tests, including one call to every generated method |
make test-window |
also open a hidden window |
make test-asan |
tests under AddressSanitizer (macOS) |
make qa |
lint, format check, mypy, tests |
License
MIT. The vendored CUI is MIT, with its fonts under OFL (Inter, Geist) and ISC (Lucide). See thirdparty/cui/LICENSE, thirdparty/cui/THIRD_PARTY.md and thirdparty/cui/assets/fonts/.
Metadata
Release files for cui-py 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 9.4 MB
Release files / cui_py-0.1.0-cp310-abi3-win_amd64.whl
| Download URL | cui_py-0.1.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
3c4b62129ebc7045156b321c663d442ca1676901ce7d45c68ac8655d4c0fafd9
|
|
BLAKE2b-256 checksum How to use checksums |
cde39f339122bc8cda5d95a62ebd99ca5884553de4af61daf46d5b164b99261c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / cui_py-0.1.0-cp310-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cui_py-0.1.0-cp310-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
bf843db32ef3dde5bc78fa490302f15b4a78ba1315173205d476d820030f6f14
|
|
BLAKE2b-256 checksum How to use checksums |
6bad35a97166f60c20c34a1302a451a8dd94b5c7fa47138bda4e584162c3f133
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / cui_py-0.1.0-cp310-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
| Download URL | cui_py-0.1.0-cp310-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.10 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
4dafcf1da945495e327dca5d0e902fbdbea5d7fe866ba5defbe83a2052bcc741
|
|
BLAKE2b-256 checksum How to use checksums |
10fa84f443b0147b4f4ab432fac580cff007e8d09f6557be2a38c18ad5844d3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / cui_py-0.1.0-cp310-abi3-macosx_26_0_arm64.whl
| Download URL | cui_py-0.1.0-cp310-abi3-macosx_26_0_arm64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.10 abi3 macOS 26.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b1e136e17b0757cf689e47f43b5bf7e5e9bd0742351d2d3cc61b34a3cf2d0013
|
|
BLAKE2b-256 checksum How to use checksums |
527700583c49986d4d135b819a75dda97a5cd5ba5cf138b8fdfc58cfef096fb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / cui_py-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | cui_py-0.1.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
66080c004db86c96430378a909b46575a69c6398303b4278fed0e4dda81980bd
|
|
BLAKE2b-256 checksum How to use checksums |
0b27836a4a8c760b3662cdfff72ef71ac468ddcf87420502d2499d829795bd10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / cui_py-0.1.0-cp310-abi3-macosx_10_9_x86_64.whl
| Download URL | cui_py-0.1.0-cp310-abi3-macosx_10_9_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.10 abi3 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
3cc25c53f5630108d37bc842f710b431df646ee05a390936e7dc7a9d7ec23260
|
|
BLAKE2b-256 checksum How to use checksums |
c8a4b6c90e5d9844b1f0d5e19b6e699ac2eeb20703ef4019fb5ecf962eae2671
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for cui-py 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.