BSUML
BSUML runs User Mode Linux (UML) guests on simulation time from a Python asyncio program. UML's time-travel=ext mode hands the guest kernel's clock to an external calendar, so the guest runs only when the simulation lets it. BSUML implements that calendar and a vhost-user backend for the guest's Virtio devices. Your code supplies the devices, which connect the guest to the rest of the simulation, and decides when each guest runs and how far it may run on its own. BSUML does not start the kernel, build a root filesystem, or schedule guests.
BSUML has two modules, and neither imports the other. Use the calendar alone for a guest without devices, or the backend with any devices you write.
| Module | Contents |
|---|---|
bsuml.timetravel |
TimeTravelCalendar, the GuestDevices protocol and UML_TIMEOUT |
bsuml.vhost |
VhostUserBackend, which speaks the vhost-user dialect of UML's virtio_uml driver: two queues per device, one shared memory region, and in-band notifications, so the calendar controls when each interrupt arrives |
Install the Python package
Use Linux and Python 3.11 or newer. The guest kernel needs CONFIG_UML_TIME_TRAVEL_SUPPORT, and CONFIG_VIRTIO_UML for vhost-user devices.
python3 -m venv .venv
. .venv/bin/activate
python -m pip install bsuml
Run the sample
samples/README.md sets up a UML kernel and runs a guest with a Virtio console. The sample types date, sleep 5 and echo into the guest's shell, and the 5 seconds of simulation time pass at once.
Run a guest
A guest needs a calendar and, optionally, devices. The calendar listens on a Unix socket, and the kernel connects to it when it boots. The sample follows these steps with one Virtio console.
- Create a
bsuml.timetravel.TimeTravelCalendaron a socket path and calllisten(). - Start a
bsuml.vhost.VhostUserBackendfor each Virtio device and calllisten()on it. - Start the kernel with
time-travel=ext:<calendar socket>andvirtio_uml.device=<backend socket>:<Virtio device ID>for each device. - Call
calendar.connect(loop, now_ns=..., alive=..., devices=..., on_ready=...).now_ns()returns the current simulation time. It blocks until the guest first waits for simulation time. - When the guest is done, stop the kernel, then close the calendar. UML panics when the calendar socket closes while it runs.
Write the devices
devices implements the GuestDevices protocol. It wraps your backends and whatever they connect to, such as a socket or a log. While the guest runs, the event loop is blocked, so the calendar services the devices itself: a guest can block on a device until its host side answers.
| Member | Use |
|---|---|
transport_read_fds |
Descriptors to service while the guest runs: only those the guest may block on, such as the backends' sockets. Input from outside, such as a peer's socket, belongs in read_fds only, so it reaches the guest when it next waits. |
read_fds, write_fds |
Descriptors the calendar watches in the event loop while the guest waits. |
service(readable, writable) |
Handle the ready descriptors without advancing simulation time. |
has_notifications |
A device completed a request and needs to interrupt the guest. |
flush_notifications() |
Send those interrupts. The calendar calls it when the guest can take them. |
notifications_pending |
The guest has not taken the interrupts yet. |
A VhostUserBackend provides the parts for one device: read_fds, write_fds, service(readable, writable), which returns the queues the guest kicked, pop(queue) and complete(queue, buffer, length) for the guest's requests, and has_notifications, notifications_pending and flush_notifications().
Schedule the guest
The calendar never runs the guest on its own: your code decides when it runs, whether guests run one at a time, and how far each one may run without reporting its events.
| Member | Use |
|---|---|
request_ns |
The time the guest asked to run, or None. |
next_ns |
The earliest time the guest needs a turn, including device interrupts, or None. |
resume(free_until_ns, deadline) |
Run the guest at request_ns until it waits again. |
service_idle(deadline) |
Service the devices of a waiting guest, and deliver interrupts that are due. |
devices_changed() |
Report device input queued by your code, such as console input. It calls on_ready. |
close() |
Disconnect the guest. Afterwards it is never due. |
on_ready runs when the devices of a waiting guest have input. Give the guest a turn then, or at next_ns, by calling service_idle(). When simulation time reaches request_ns, call resume(). free_until_ns becomes the guest's FREE_UNTIL: it handles its own events before that time without reporting them, so pick the earliest time another participant may need to act. The calendar injects later interrupts no earlier than that time, so guest time never moves back. deadline is a time.monotonic() limit for the guest to yield. The event loop is blocked meanwhile, so simulation time stands still.
API
| Name | Use |
|---|---|
bsuml.timetravel.TimeTravelCalendar(path, *, on_failure=None) |
The calendar side of the time-travel protocol for one guest. on_failure receives the error when the guest fails after boot. |
bsuml.timetravel.GuestDevices |
The protocol described above. |
bsuml.timetravel.UML_TIMEOUT |
Wall-clock seconds a guest may take to connect or yield, 60 by default. |
bsuml.vhost.VhostUserBackend(path, *, config=None) |
A vhost-user device backend with split virtqueues. config is the device's configuration space. |
Develop from source
Install the package and its test tools from components/bsuml in the repository checkout.
python -m pip install -e '.[test]'
Run the tests and build the distributions. The tests play the guest's side of the sockets and need no kernel.
python -m pytest
python -m build
License
Licensed under the Apache License 2.0.
Metadata
Release files for bsuml 0.1.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 |
|---|---|---|---|---|
| bsuml-0.1.0.tar.gz | 27.0 kB | With provenance | Details for bsuml-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bsuml-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for bsuml-0.1.0-py3-none-any.whl |
Total release size: 45.4 kB
Release files / bsuml-0.1.0.tar.gz
| Download URL | bsuml-0.1.0.tar.gz |
|---|---|
| Size | 27.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
66f6d0c3adf3ad94bf60868033e4a01e88cd39cfd3a67fe065b33bbfde1df2dc
|
|
BLAKE2b-256 checksum How to use checksums |
4a0fe4dc5a421eda4c707dd91b07dc78795ef2a69a806dd22b5ba6de70834d6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Transparency logRelease files / bsuml-0.1.0-py3-none-any.whl
| Download URL | bsuml-0.1.0-py3-none-any.whl |
|---|---|
| Size | 18.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b8b50c8e5701d9e474ea2433e8254c3d5cf2688a3dd3fb71ae5c1984b0881b96
|
|
BLAKE2b-256 checksum How to use checksums |
452db2a22e8481e80527bd30257f219e20b26c5b9b9c2c8407ceb18355d9fd35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Transparency logSecurity for bsuml 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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for bsuml-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Transparency logA 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.