Skip to main content

No project description provided

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

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-1.0.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

aio_usb_hotplug-1.0.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file aio_usb_hotplug-1.0.0.tar.gz.

File metadata

  • Download URL: aio_usb_hotplug-1.0.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for aio_usb_hotplug-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d1fe374bcf330559fdecbbc857f7fc609a6d8133c2343391962436138d6fa6ef
MD5 eb9c31425ef85637f86c5a51d7a9774b
BLAKE2b-256 fcfde4a1a75c0d14b68fafe4600fed939a5e918688dde1d0836d06a2aaca2c9b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aio_usb_hotplug-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for aio_usb_hotplug-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bdffdb4780a88eb20116e155af3e73f921cbc499a24ada350976a55d4155e065
MD5 3ff4cb73dce1ad44b3f5ad55eac33145
BLAKE2b-256 c9a413ffdaa6d60da5b72c616bfba4dbbb00b1b26be999f3e9997965af56ec52

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