Skip to main content

aioxlib

Human-friendly asyncio interface to the X11 protocol

aioxlib is a pure-Python library that talks the X11 wire protocol over asyncio.
It aims to make working with X displays, windows, graphics contexts, events, and images feel natural in modern async Python code—without blocking the event loop.

Inspired by the style of linuxpy (also by the same author), it provides a clean, high-level API while still exposing the underlying protocol details when you need them.

Features

  • Fully asynchronous connection to the X server (Unix socket or TCP)
  • High-level objects: Display, Screen, Window, GC, resources
  • Event stream via async for event in display.events()
  • Window creation, mapping, attributes, WM properties (WM_NAME, WM_PROTOCOLS, …)
  • Graphics Context (GC) drawing: rectangles, text (put_text), images
  • MIT-SHM support for high-performance image transfer
  • Atom interning, extensions querying, fonts listing
  • Python ≥ 3.12, GPLv3
  • No external dependencies
  • Code in a single file

Installation

From within your favorite python environment:

pip install aioxlib

Quick start

import asyncio
import aioxlib


async def main():
    display = await aioxlib.get_display()
    async with display:
        screen = display.default_screen()
        wnd = await screen.create_window(width=640, height=480)
        await wnd.map()
        await wnd.set_name("Hello from aioxlib")

        # Handle window close
        protocols = await display.get_atom("WM_PROTOCOLS")
        delete = await display.get_atom("WM_DELETE_WINDOW")
        await wnd.set_wm_protocols([delete])

        async for event in display.events():
            if (
                event["code"] == aioxlib.Event.ClientMessage
                and event["type"] == protocols
                and event["data"][0] == delete
            ):
                break


asyncio.run(main())

Examples

The examples/ directory contains several demos:

File Description
basic.py Minimal window + close handling
text.py Draw text on expose
grid.py Fill a grid of rectangles
point.py Points API
segments.py Line segments
3d.py Simulate 3d rendering
shm.py MIT-SHM image transfer
video.py Live video from a V4L2 camera
video_shm.py Video + shared-memory path

Run any of them with:

python examples/basic.py

API overview

display = await aioxlib.get_display()          # or get_display(":0")
async with display:
    screen = display.default_screen()

    wnd = await screen.create_window(...)      # or display.create_window(...)
    await wnd.map()
    await wnd.set_name("…")
    await wnd.set_wm_protocols([...])

    gc = await wnd.create_gc(foreground=…, background=…)
    await gc.poly_fill_rectangles([...])
    await gc.put_text(x, y, "text")
    await wnd.draw_image(gc, x, y, w, h, depth, data)

    async for event in display.events():
        ...

Events are plain dicts with a "code" field matching aioxlib.Event.*.

Requirements

  • Python ≥ 3.12
  • An X11 server (Xorg, Xwayland, …)
  • $DISPLAY set (or pass the display string explicitly)

License

GPLv3 or later — see LICENSE.

Author

José Tiago Macara Coutinho
https://codeberg.org/tiagocoutinho


Early beta (v0.0.2). Feedback and contributions welcome!

Release files for aioxlib 0.0.7

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

Source distribution (sdist)

Source distribution for aioxlib 0.0.7
File Size Uploaded
aioxlib-0.0.7.tar.gz 61.2 kB Details

Built distribution (wheel)

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

Total release size: 96.4 kB

Release files / aioxlib-0.0.7.tar.gz

Download URL aioxlib-0.0.7.tar.gz
Size 61.2 kB
Tags Source
SHA-256 checksum
How to use checksums
94a7879be9637ea1884438b2f10448a5db8c4e781be87e70a8ff8eadb0822828
BLAKE2b-256 checksum
How to use checksums
dfa8821a378e9bef2955a3a2d232ee7010d15c209aee264427345f97910f20e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / aioxlib-0.0.7-py3-none-any.whl

Download URL aioxlib-0.0.7-py3-none-any.whl
Size 35.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6fc8589b80971012cb93ccf350f9b4a87c9b02c869233af727943f575ec7ed71
BLAKE2b-256 checksum
How to use checksums
6458c9a3d6a43d699dae6b6f84e0f9357012fde24eb456392a0fdf8485d775e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release history Release notifications | RSS feed

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.8

2 release files

This release

0.0.7 This release

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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