Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

xnano

A fun, fast and incredibly flexible terminal UI library for Python, built on ratatui.

License Python Versions CodSpeed Built With Ratatui

Documentation · API Reference · Contributing


Quick start

import xnano
from xnano.context import Context
from xnano.expressions import ParentWidth, TimeElapsed, Width

with xnano.open(width=40, height=5) as terminal:
    terminal.write('Hello, world!', x='center', border='rounded')
    ball = terminal.write('●', y=4)
    ball.x = (ParentWidth - Width) * (TimeElapsed % 2 / 2)  # a formula, evaluated every frame

    @terminal.on_key('space')
    def toggle(context: Context) -> None:
        if terminal.time.is_paused:
            terminal.time.resume()
        else:
            terminal.time.pause()

    terminal.run(quit_on='q')

xnano.open() gives you a terminal. You write text, widgets, images and pixels to it, and every position and size can be a number, a word such as 'center', or a formula of time or of the terminal's size. Decorators named for what happens (on_key, on_click, every, after) react, terminal.input tells a game which keys are held, terminal.scene() gives pixel-art worlds a camera and collision, and terminal.play('C4 E4 G4:2') plays a melody written as text. There are no base classes to subclass and no layout tree to declare.

The examples/ folder has twenty-one runnable programs, from hello world to a playable pixel-art world, and examples/README.md shows what each one draws.

See it

Run the demo in your terminal with python -m xnano (or the xnano command). It opens with an animation, then fills the window with live panels that each use a different part of xnano.

The xnano demo

Every picture below is a real terminal window running one of the programs in examples/, photographed by make readme-images, so each picture and its source stay in step.

A playable world

A pixel-art character, a camera that follows it, collision and a clock you can stop: about one screen of code (20_world.py).

A playable pixel-art world

Pixel art that fits the window

Give an image a percentage and it refits whenever the window is resized, keeping its hard pixel edges; give it a number and it is locked. The thumbnail in the corner is locked (24_dusk.py). The art is "Mountain at Dusk" by Luis Zuno (ansimuz), CC0.

Pixel art that refits the window

Pixel art written as text

from_art turns a block of characters and a short palette into an image (23_sprites.py).

Sprites written as text

Images and animations

Pan and zoom over a large picture with the arrow keys and + / - (06_images.py).

An image viewer

Sound

Every built-in instrument, playable from the keyboard (10_audio.py), and a whole song written as text, played on the beat (22_song.py).

Playing every instrument A song written as text

Widgets

Charts, tables and gauges refreshed from a timer (14_dashboard.py).

A dashboard

Install

Install xnano with pip or uv. Sound and images are extras, so a program that needs neither installs neither:

pip install xnano                # the terminal, widgets, effects and events
pip install "xnano[audio]"       # adds notes, melodies, sounds and the microphone
pip install "xnano[image]"       # adds images and animations
pip install "xnano[audio,image]"
# or
uv add "xnano[audio,image]"

Using sound or images without their extra raises an ImportError that names the extra to install. On Linux, audio device playback requires ALSA; synthesis and melody scheduling work without an audio device.

Packages

The repository is a uv workspace with three installable backends and a small xnano metapackage that holds the terminal API. The backends can also be installed on their own.

Distribution Import Purpose
xnano xnano The terminal API: open, placements, hooks, input, pixels, scenes and sound.
xnano-core xnano_core The Rust-backed engine: buffers, widgets, layout, state, input, runtime and effects.
xnano-audio xnano_audio Audio synthesis, playback, capture and beat-based melodies.
xnano-image xnano_image Image and animation decoding, processing and terminal-cell conversion.

Names live in modules named for what they hold, so the top-level xnano stays small: xnano.widgets, xnano.expressions, xnano.effects, xnano.operations, xnano.styles, xnano.events, xnano.geometry, xnano.buffers, xnano.scene, xnano.types and xnano.errors, plus the optional xnano.audio and xnano.image.

xnano v1

xnano v1 (the declarative grid-and-field API) is not part of this branch. It is maintained on the v1 branch, and the latest release is v1.2.3 (PyPI):

pip install "xnano>=1.2.3,<2"

The v1 guides are kept in docs/v1, and their code imports from xnano, as v1 did. A program written for v1 must be rewritten for v2.

Development

The repository uses a uv workspace and Rust workspace. From the repository root, uv sync --all-extras installs the development environment and make help lists common build, test, lint, type-check, docs and release commands. Read CONTRIBUTING.md before opening a change.

License

xnano is released under the MIT License.

Metadata

Release files for xnano 2.0.0b3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xnano 2.0.0b3
File Size Uploaded Provenance
xnano-2.0.0b3.tar.gz 11.8 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for xnano 2.0.0b3
File Interpreter ABI Platform
xnano-2.0.0b3-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 MB

Release files / xnano-2.0.0b3.tar.gz

Download URL xnano-2.0.0b3.tar.gz
Size 11.8 MB
Tags Source
SHA-256 checksum
How to use checksums
e7f71f79d810356e632bbcd1c8b733efb84c2b3d92554d3fa308d7ac1be98d89
BLAKE2b-256 checksum
How to use checksums
58eb339a781c0e4539f9d849d615da0ab4081d0f11fbf65b36aebf335f28b351
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / xnano-2.0.0b3-py3-none-any.whl

Download URL xnano-2.0.0b3-py3-none-any.whl
Size 431.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fbea1767d3a9cf1d78ace0fdf8f787a05cbf5c6bd303b6ffb5a840275411550a
BLAKE2b-256 checksum
How to use checksums
2c7ae097fa0e06cbabf0825e7d89b99a44bcf656d6914812da603932aaeddab2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for xnano 2.0.0b3

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.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page