Skip to main content

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.7.

Works with asyncio, curio and trio.

Installation

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

pip install aio-usb-hotplug

Usage

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 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

MIT

Project details


Download files

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

Source Distribution

aio-usb-hotplug-3.0.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

aio_usb_hotplug-3.0.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file aio-usb-hotplug-3.0.1.tar.gz.

File metadata

  • Download URL: aio-usb-hotplug-3.0.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.0 Darwin/19.6.0

File hashes

Hashes for aio-usb-hotplug-3.0.1.tar.gz
Algorithm Hash digest
SHA256 e3ed19ed451ef65b4df7628f726b2f0747f7eea98ff4e1e7ee6776505223a070
MD5 fbfc8824bdd7fdec8a181dfdf541d434
BLAKE2b-256 ff7ca3bba07b1c247934548ea8188b397f3cd4f4f90e27a232dbba7ef0ca6e72

See more details on using hashes here.

File details

Details for the file aio_usb_hotplug-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: aio_usb_hotplug-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.0 Darwin/19.6.0

File hashes

Hashes for aio_usb_hotplug-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 59ad7f835776be016b62f2e0eddab82b89b92dee5322e4983b0293375ba65ce0
MD5 e7b781e8d51f7cec1f91c2d5ac504cec
BLAKE2b-256 1406c7123a36674cc2b78400a3bd3ed717cce1df1669912c10ad5aef3a53f573

See more details on using hashes here.

Supported by

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