Skip to main content

Liburing is Python + Zig wrapper around C Liburing, which is a helper to setup and tear-down io_uring instances.

Project description

Liburing

Python Zig PyPI - Downloads Test status

Liburing is Python + Zig wrapper around C Liburing, which is a helper to setup and tear-down io_uring instances.

  • Fast & scalable asynchronous I/O (storage, networking, ...) interface.
  • io_uring reduces number of syscalls overhead & context switches, thus improving speed.

Good(old) documentation Lord of the io_uring

Requires

  • Linux 6.14+
  • Python 3.10+

Includes (battery)

  • C liburing 2.15+

Install, update & uninstall (Alpha)

Use pip to install, upgrade & uninstall Python wrapper

python3 -m pip install liburing             # install

python3 -m pip install --upgrade liburing   # upgrade

python3 -m pip uninstall liburing           # uninstall

To compile & install directly from GitHub

# note: make sure you have Zig 0.15.2 installed on your system.

cd /tmp
git clone --recurse-submodules https://github.com/YoSTEALTH/Liburing
cd Liburing

python3 -m pip install pyoz
python3 -m pyoz build
python3 -m pip install dist/*.whl

# uninstall
python3 -m pip uninstall liburing pyoz

To find out all the class, functions and definitions

import liburing

# To see all the importable names
print(dir(liburing))

# To see all the help docs
help(liburing)

Find out which io_uring operations is supported by the kernel

# example/probe.py
import liburing

for k, v in liburing.probe().items():
    print(k, v)

Simple File Example

# example/open_write_read_close.py
from liburing import O_CREAT, O_RDWR, Ring, Cqe, io_uring_get_sqe, \
                     io_uring_prep_open, io_uring_prep_write, io_uring_prep_read, \
                     io_uring_prep_close, io_uring_submit, io_uring_wait_cqe, \
                     io_uring_cqe_seen, io_uring_queue_init, io_uring_queue_exit


def open(ring, cqe, path, flags):
    sqe = io_uring_get_sqe(ring)  # sqe(submission queue entry)
    io_uring_prep_open(sqe, path, flags)
    # set submit entry identifier as `1` which is returned back in `cqe.user_data`
    # so you can keep track of submit/completed entries.
    sqe.user_data = 1
    return _submit_and_wait(ring, cqe)  # returns fd


def write(ring, cqe, fd, data):
    sqe = io_uring_get_sqe(ring)
    io_uring_prep_write(sqe, fd, data)
    sqe.user_data = 2
    return _submit_and_wait(ring, cqe)  # returns length(s) of bytes written


def read(ring, cqe, fd, length):
    buffer = bytearray(length)  # where read data will be stored
    sqe = io_uring_get_sqe(ring)
    io_uring_prep_read(sqe, fd, buffer)
    sqe.user_data = 3
    _submit_and_wait(ring, cqe)  # get actual length of file read.
    return buffer


def close(ring, cqe, fd):
    sqe = io_uring_get_sqe(ring)
    io_uring_prep_close(sqe, fd)
    sqe.user_data = 4
    _submit_and_wait(ring, cqe)  # no error means success!


def _submit_and_wait(ring, cqe):
    io_uring_submit(ring)  # submit entry
    io_uring_wait_cqe(ring, cqe)  # wait for entry to finish
    entry = cqe[0]
    try:
        result = entry.res  # auto raises appropriate exception if failed
    except Exception as e:
        raise e  # do stuff with error
    # done with current entry so clear it from completion queue.
    io_uring_cqe_seen(ring, entry)
    return result  # type: int


def main():
    ring = Ring()
    cqe = Cqe()  # completion queue entry
    try:
        io_uring_queue_init(8, ring)

        fd = open(ring, cqe, "/tmp/liburing-test-file.txt", O_CREAT | O_RDWR)
        print("fd:", fd)

        length = write(ring, cqe, fd, b"hi... bye!")
        print("wrote:", length)

        content = read(ring, cqe, fd, length)
        print("read:", content)

        close(ring, cqe, fd)
        print("closed.")
    finally:
        io_uring_queue_exit(ring)


if __name__ == "__main__":
    main()

Note

  • This project has been moved to using Zig as back-end, thus leading to breaking changes from previous release.
  • Try using latest Linux if possible to enable all io_uring features.

Other Projects

License

Free, Public Domain (CC0). Read more

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

liburing-2026.3.30-cp38-abi3-manylinux_2_17_x86_64.whl (662.2 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

File details

Details for the file liburing-2026.3.30-cp38-abi3-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for liburing-2026.3.30-cp38-abi3-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 dc607ad9b5acfd8efcb2b969e267b5b6b9d4434bbb45df48a06c6ef65a2fad31
MD5 f8b227700a9552470b8622a4de46df81
BLAKE2b-256 de89e90f2b63fb5bd26a29f29a117ab8d4bcaebabd50d71949a429eba7e03295

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page