Asynchronous generators yielding detected hotplug events on the USB buses
Project description
aio-usb-hotplug
aio-usb-hotplug is a Python library that provides asynchronous generators
yielding detected hotplug events on the USB buses.
Requires Python >= 3.8.
Installation
Use the package manager pip to install
aio-usb-hotplug.
pip install aio-usb-hotplug
aio-usb-hotplug depends on PyUSB, which
in turn requires libusb or
openusb. An easy way to satisfy
this requirement is to install
libusb-package, which supplies
pre-compiled binaries for most platforms:
pip install libusb-package
aio-usb-hotplug will make use of
libusb-package if it is installed in
the current Python environment.
Usage
Dump all hotplug events related to a specific USB device
from aio_usb_hotplug import HotplugDetector
from trio import run # ...or asyncio
async def dump_events():
detector = HotplugDetector.for_device(vid="1050", pid="0407")
async for event in detector.events():
print(repr(event))
trio.run(dump_events)
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))
try:
# Do something meaningful with the device. The task gets cancelled
# when the device is unplugged.
await sleep_forever()
finally:
# 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)
trio.run(handle_detected_devices)
Contributing
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.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aio_usb_hotplug-7.0.0.tar.gz.
File metadata
- Download URL: aio_usb_hotplug-7.0.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9f1c93b370aa1d602c5ae42686c3ada026781c34a2431e29f1b80726a112a34
|
|
| MD5 |
29a583377c981f2fb89b622fda62b5d2
|
|
| BLAKE2b-256 |
8b08d9e21bf0a97c0bc29d9ec59b1a7defde6af6d4b25bee614c01db77d5fde3
|
File details
Details for the file aio_usb_hotplug-7.0.0-py3-none-any.whl.
File metadata
- Download URL: aio_usb_hotplug-7.0.0-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aac06a554311a8ac69e015eacbc31888fb541e3c06dde27b06c666e028d34320
|
|
| MD5 |
defc149b7c9c1c3f693c21a7d5ab2ac9
|
|
| BLAKE2b-256 |
70fb71e100b1235e7dee9e0c1e072c82e1569432abb6dc593e03dc5af0910326
|