asyncusb
The goal of this library is to be an efficient and pythonic asynchronous usb library written in pure python.
Here's an example that sends some data to a predetermined device endpoint.
import asyncio
from asyncusb.core import *
async def main():
with Context() as ctx:
devices = ctx.get_device_list()
# Inspect device attributes and choose a device. We'll just take the
# first device for the purposes of this example.
dev = devices[0]
async with dev.open() as handle:
# Handle kernel drivers automatically.
handle.set_auto_detach_kernel_driver(True)
# Claim the interface for the duration of this with block. This
# example assumes we're using interface 1.
with handle.bind_interface(1):
# Create and submit the transfer. This example assumes
# we're just sending some data to endpoint 0x02.
transfer = handle.fill_bulk_transfer(0x02, b'hello world!')
transfer.submit()
# Wait for transfer completion. If we don't, the dev.open()
# context manager might cancel our transfer before it
# finishes!
await transfer.wait()
asyncio.run(main())
That's it! No manual resouce cleanup is required, as all cleanup is handled by the context managers.
Built-in Termux Compatibility
There are two built-in methods for accessing devices on Termux. The simplest method is using the termux_compatibility_hook method from the compat module, like so:
dev_path = "/dev/bus/usb/001/002"
# This function gets the device from Termux:API and sets the TERMUX_USB_FD
# environment variable for the Termux patch of libusb.
termux_compatibility_hook(dev_path)
# Then use the context as normal.
with Context() as ctx:
devices = ctx.get_device_list()
# ...
This only allows using one device per Context, however. For more advanced cases, termux_get_device and Context.wrap_sys_device can be used, in conjunction with the no_discovery context option, like so:
dev_path = "/dev/bus/usb/001/002"
# Get the system device handle (a file descriptor) from Termux:API.
sys_dev = termux_get_device(dev_path)
# Create a context with the 'no_discovery' option. This creates the context
# without searching for devices. This also means that ctx.get_device_list()
# will return an empty list.
with Context(no_discovery=True) as ctx:
# Open the device.
async with ctx.wrap_sys_device(sys_dev) as handle:
# Get a Device instance, if needed.
dev = handle.get_device()
# ...
These methods aren't just limited to this library. termux_compatibility_hook will work for any library that uses libusb, and termux_get_device will work for any library that implements a way to call libusb_wrap_sys_device.
The compat module also provides other functions, such as is_termux(), has_termux_api(), and termux_list_devices().
Current Features:
- async event handling
- thread-safe transfer creation and submission
- automated resource handling
- Termux compatibility
Planned Features:
- async endpoint read/write streams
Metadata
Release files for asyncusb 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| asyncusb-0.1.1.tar.gz | 42.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| asyncusb-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 84.9 kB
Release files / asyncusb-0.1.1.tar.gz
| Download URL | asyncusb-0.1.1.tar.gz |
|---|---|
| Size | 42.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
edd1d931481c93bcd259a6bd7bd8718a5c6831ae6505862a873bd459b957a8b9
|
|
BLAKE2b-256 checksum How to use checksums |
bb0a985da3f242ac44bdf0cb7d03591bac97fa6c2a59fe9011202ed45e236da0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 27, 2026.
Transparency logRelease files / asyncusb-0.1.1-py3-none-any.whl
| Download URL | asyncusb-0.1.1-py3-none-any.whl |
|---|---|
| Size | 42.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d19698a242b3f1c98c067dc6de941bac3980bfada586db3b86e135f7c2acf761
|
|
BLAKE2b-256 checksum How to use checksums |
5ace962d70680e9b52b75783f4353c5c048bb96dee69128bf2411bfb883be014
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 27, 2026.
Transparency log