{"id":17148597,"url":"https://github.com/ntamas/aio-usb-hotplug","last_synced_at":"2025-07-25T23:32:17.305Z","repository":{"id":57092623,"uuid":"222700569","full_name":"ntamas/aio-usb-hotplug","owner":"ntamas","description":"Asynchronous USB hotplug event generator for Python 3.7 and above","archived":false,"fork":false,"pushed_at":"2024-04-12T08:43:14.000Z","size":200,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-18T10:55:21.628Z","etag":null,"topics":["asyncio","curio","hotplug","python","python-library","trio","usb"],"latest_commit_sha":null,"homepage":"https://github.com/ntamas/aio-usb-hotplug","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ntamas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-11-19T13:17:49.000Z","updated_at":"2021-10-08T15:35:20.000Z","dependencies_parsed_at":"2023-02-16T20:30:51.014Z","dependency_job_id":null,"html_url":"https://github.com/ntamas/aio-usb-hotplug","commit_stats":{"total_commits":70,"total_committers":2,"mean_commits":35.0,"dds":"0.014285714285714235","last_synced_commit":"ddeb3a0981a615355a11bf82c9f6c0b69da35dd2"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ntamas%2Faio-usb-hotplug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ntamas%2Faio-usb-hotplug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ntamas%2Faio-usb-hotplug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ntamas%2Faio-usb-hotplug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ntamas","download_url":"https://codeload.github.com/ntamas/aio-usb-hotplug/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227630184,"owners_count":17796231,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncio","curio","hotplug","python","python-library","trio","usb"],"created_at":"2024-10-14T21:29:12.659Z","updated_at":"2025-07-25T23:32:17.240Z","avatar_url":"https://github.com/ntamas.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aio-usb-hotplug\n\n`aio-usb-hotplug` is a Python library that provides asynchronous generators\nyielding detected hotplug events on the USB buses.\n\nRequires Python \u003e= 3.9.\n\nWorks with [`asyncio`](https://docs.python.org/3/library/asyncio.html)\nand [`trio`](https://trio.readthedocs.io/en/stable/).\n\n## Installation\n\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install\n`aio-usb-hotplug`.\n\n```bash\npip install aio-usb-hotplug\n```\n\n`aio-usb-hotplug` depends on [PyUSB](https://pypi.org/pypi/pyusb), which\nin turn requires [libusb](https://libusb.info) or\n[openusb](https://sourceforge.net/projects/openusb/). An easy way to satisfy\nthis requirement is to install\n[libusb-package](https://pypi.org/pypi/libusb-package), which supplies\npre-compiled binaries for most platforms:\n\n```bash\npip install libusb-package\n```\n\n`aio-usb-hotplug` will make use of\n[libusb-package](https://pypi.org/pypi/libusb-package) if it is installed in\nthe current Python environment.\n\n## Usage\n\n### Dump all hotplug events related to a specific USB device\n\n```python\nfrom aio_usb_hotplug import HotplugDetector\nfrom trio import run  # ...or asyncio\n\nasync def dump_events():\n    detector = HotplugDetector.for_device(vid=\"1050\", pid=\"0407\")\n    async for event in detector.events():\n        print(repr(event))\n\ntrio.run(dump_events)\n```\n\n### Run an async task for each USB device matching a VID/PID pair\n\n```python\nfrom aio_usb_hotplug import HotplugDetector\nfrom trio import sleep_forever\n\n\nasync def handle_device(device):\n    print(\"Handling device:\", repr(device))\n    try:\n        # Do something meaningful with the device. The task gets cancelled\n        # when the device is unplugged.\n        await sleep_forever()\n    finally:\n        # Device unplugged or an exception happened\n        print(\"Stopped handling device:\", repr(device))\n\n\nasync def handle_detected_devices():\n    detector = HotplugDetector.for_device(vid=\"1050\", pid=\"0407\")\n    await detector.run_for_each_device(handle_device)\n\n\ntrio.run(handle_detected_devices)\n```\n\n## Contributing\n\nPull requests are welcome. For major changes, please open an issue first to\ndiscuss what you would like to change.\n\nPlease make sure to update tests as appropriate.\n\n## License\n\n[MIT](https://choosealicense.com/licenses/mit/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fntamas%2Faio-usb-hotplug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fntamas%2Faio-usb-hotplug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fntamas%2Faio-usb-hotplug/lists"}