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.5.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 macos, Linux and Windows.
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
cui-py needs CPython 3.11 or later. One abi3 wheel per platform covers every later version. The macOS wheels need macOS 13 or later.
pip install cui-py
or if you want to build from source:
git clone https://github.com/shakfu/cui-py && 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)
-
Option pointers. An option C reads and writes takes a
cui.Ref. Read.valueafter the frame, since some components write it at the end of a scope:sel = cui.Ref(-1) ui.treemap("t", items, selected=sel) if sel.value >= 0: ...
An option array takes a list. cui-py sets its count from the list, or checks the list against the length CUI reads, such as one icon per segment.
-
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.
-
-
Images.
image_createandimage_updatetake any C-contiguous buffer of RGBA bytes:bytes,memoryview, or a NumPy(h, w, 4)uint8 array. -
Drawing.
ui.canvas(id, width, height, paint)callspaint(rect)after layout. Only there do thedraw_*methods work.focusable=Truemakes it a Tab stop. Withcomponent_input=Trueit also receives keys and text throughctx.dispatch_input(event, route), replaying events an input hook (ctx.set_input_hook) captured.
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.
Terminal on a pty
cui.Pty runs a child process on a pseudo-terminal, and ui.pty(id, p) shows it. libghostty-vt 1.0.0 parses the output. The view code comes from cui-repl. The Linux and macOS wheels include it. Windows has no pty, and cui.PTY_AVAILABLE is false there.
A source build leaves it off. To turn it on you need Zig 0.17 and CMake 3.19 or later:
make build-pty # from a checkout
pip install cui-py --no-binary cui-py -C cmake.define.CUI_PY_PTY=ON
The first build downloads libghostty-vt (SHA-256 pinned in CMakeLists.txt).
with cui.Pty(["python3", "-q"]) as p:
for ui in app.frames():
ui.pty("repl", p)
if p.exited:
break
- The view reads the child's output each frame. A Pty no view shows stalls a child that writes a lot.
p.write()sends input, andp.screen()reads the screen as text.- A Pty works only on the thread that made it.
examples/term.py is a terminal window.
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, or of a length CUI would read past
-
building UI or injecting input inside an input hook or route
-
updating a region outside an image, or a texture that is not one
-
passing color channels outside 0..255
-
writing more text than a buffer holds
Strings, arrays and Refs 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 421 entries: 403 Context methods, including 53 scopes, and 18 module functions. Another 48 functions are wrapped by hand. docs/dev/coverage.md lists the 34 functions not wrapped yet and why, and the 12 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 build-pty |
rebuild with cui.Pty (needs Zig 0.17) |
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/. A CUI_PY_PTY build also links cui-repl and libghostty-vt, both MIT. Their licenses go in cui/licenses/.
Metadata
Release files for cui-py 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cui_py-0.2.0.tar.gz | 1.5 MB | Without provenance | Details for cui_py-0.2.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| cui_py-0.2.0-cp311-abi3-win_amd64.whl | CPython 3.11 | abi3 | Windows x86-64 | Details for cui_py-0.2.0-cp311-abi3-win_amd64.whl |
| cui_py-0.2.0-cp311-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.11 | abi3 | Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 | Details for cui_py-0.2.0-cp311-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
| cui_py-0.2.0-cp311-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl | CPython 3.11 | abi3 | Linux glibc 2.27+ ARM64, Linux glibc 2.28+ ARM64 | Details for cui_py-0.2.0-cp311-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl |
| cui_py-0.2.0-cp311-abi3-macosx_13_0_x86_64.whl | CPython 3.11 | abi3 | macOS 13.0+ x86-64 | Details for cui_py-0.2.0-cp311-abi3-macosx_13_0_x86_64.whl |
| cui_py-0.2.0-cp311-abi3-macosx_13_0_arm64.whl | CPython 3.11 | abi3 | macOS 13.0+ ARM64 | Details for cui_py-0.2.0-cp311-abi3-macosx_13_0_arm64.whl |
Total release size: 14.6 MB
Release files / cui_py-0.2.0.tar.gz
| Download URL | cui_py-0.2.0.tar.gz |
|---|---|
| Size | 1.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
64179bb8cc3776a7ec4ba37d3cf438bd151000e5a9e16632ac6011934872ac29
|
|
BLAKE2b-256 checksum How to use checksums |
ba5cc1cb2eb4636f0920360ea187139d5fef7bf6b38d3512d5a5e2038760421d
|
| 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.2.0-cp311-abi3-win_amd64.whl
| Download URL | cui_py-0.2.0-cp311-abi3-win_amd64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.11 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
70cc001807266756e80f0a4002135341aa4bc100e554d99a2281c58b4e14fd28
|
|
BLAKE2b-256 checksum How to use checksums |
d6b5c6d77871cecf9ca036592ad9685bb0c23c10fd18c63d78a457e0e3ef4a0a
|
| 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.2.0-cp311-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | cui_py-0.2.0-cp311-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c77429231827a37585879f4b833fa1eca331860c8bdf8be5b6cdf2072c58867b
|
|
BLAKE2b-256 checksum How to use checksums |
556754ac19151d926152a01b50734b88918e8acd3c8d785ebcbee1b7943db71d
|
| 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.2.0-cp311-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
| Download URL | cui_py-0.2.0-cp311-abi3-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 2.9 MB |
| Tags | CPython 3.11 Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
8f31fdab63992f5b7cdf0dacb005e9f12aa3d59361a5db5b8381739bf05a81f5
|
|
BLAKE2b-256 checksum How to use checksums |
d96f0cd34e9871a4af6ef6d30ecf82a79d3d104afc3bcb08b853edb5a5ec4d60
|
| 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.2.0-cp311-abi3-macosx_13_0_x86_64.whl
| Download URL | cui_py-0.2.0-cp311-abi3-macosx_13_0_x86_64.whl |
|---|---|
| Size | 2.8 MB |
| Tags | CPython 3.11 abi3 macOS 13.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
822b061b73d1efc16dc9900bd5daead136b46fb86a0e2efd6bfe4e37f5614500
|
|
BLAKE2b-256 checksum How to use checksums |
95e637c8204d15583a52405fb4f5ed835c10a6fecac177f36b33948bdea83626
|
| 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.2.0-cp311-abi3-macosx_13_0_arm64.whl
| Download URL | cui_py-0.2.0-cp311-abi3-macosx_13_0_arm64.whl |
|---|---|
| Size | 2.6 MB |
| Tags | CPython 3.11 abi3 macOS 13.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0f47629959445966bc9af326a0af62b766703b5f1d193ce4916150f8dd130153
|
|
BLAKE2b-256 checksum How to use checksums |
41e3e27cd5624616ded2ac3021170fedaa1e7122f7bd2f02a36db0ab21a0a656
|
| 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.2.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.