Skip to main content

Asynchronous generators yielding detected hotplug events on the USB buses

Project description


aio-usb-hotplug is a Python library that provides asynchronous generators yielding detected hotplug events on the USB buses.

Requires Python >= 3.7.

Works with asyncio, curio and trio.


Use the package manager pip to install aio-usb-hotplug.

pip install aio-usb-hotplug


Dump all hotplug events related to a specific USB device

from aio_usb_hotplug import HotplugDetector
from trio import run  # ...or asyncio, or curio

async def dump_events():
    detector = HotplugDetector.for_device(vid="1050", pid="0407")
    async for event in

Run an async task for each USB device matching a VID/PID pair

from aio_usb_hotplug import HotplugDetector
from trio import sleep_forever

async def handle_device(device):
    print("Handling device:", repr(device))
        # Do something meaningful with the device. The task gets cancelled
        # when the device is unplugged.
        await sleep_forever()
        # Device unplugged or an exception happened
        print("Stopped handling device:", repr(device))

async def handle_detected_devices():
    detector = HotplugDetector.for_device(vid="1050", pid="0407")
    await detector.run_for_each_device(handle_device)


Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.



Project details

Download files

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

Files for aio-usb-hotplug, version 3.0.1
Filename, size File type Python version Upload date Hashes
Filename, size aio_usb_hotplug-3.0.1-py3-none-any.whl (11.0 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aio-usb-hotplug-3.0.1.tar.gz (9.1 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page