aio-usb-hotplug


Nameaio-usb-hotplug JSON
Version 6.0.0 PyPI version JSON
download
home_pagehttps://github.com/ntamas/aio-usb-hotplug/
SummaryAsynchronous generators yielding detected hotplug events on the USB buses
upload_time2023-09-18 19:12:10
maintainer
docs_urlNone
authorTamas Nepusz
requires_python>=3.8,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.

Works with [`asyncio`](https://docs.python.org/3/library/asyncio.html)
and [`trio`](https://trio.readthedocs.io/en/stable/).

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install
`aio-usb-hotplug`.

```bash
pip install aio-usb-hotplug
```

`aio-usb-hotplug` depends on [PyUSB](https://pypi.org/pypi/pyusb), which
in turn requires [libusb](https://libusb.info) or
[openusb](https://sourceforge.net/projects/openusb/). An easy way to satisfy
this requirement is to install
[libusb-package](https://pypi.org/pypi/libusb-package), which supplies
pre-compiled binaries for most platforms:

```bash
pip install libusb-package
```

`aio-usb-hotplug` will make use of
[libusb-package](https://pypi.org/pypi/libusb-package) if it is installed in
the current Python environment.

## Usage

### Dump all hotplug events related to a specific USB device

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

```python
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](https://choosealicense.com/licenses/mit/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ntamas/aio-usb-hotplug/",
    "name": "aio-usb-hotplug",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Tamas Nepusz",
    "author_email": "tamas@collmot.com",
    "download_url": "https://files.pythonhosted.org/packages/6e/88/f86cdf626ef3a40bee73c6b3ff2148aba0936dc9594fc57116bea75e9f73/aio_usb_hotplug-6.0.0.tar.gz",
    "platform": null,
    "description": "# 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 >= 3.8.\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",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Asynchronous generators yielding detected hotplug events on the USB buses",
    "version": "6.0.0",
    "project_urls": {
        "Homepage": "https://github.com/ntamas/aio-usb-hotplug/",
        "Repository": "https://github.com/ntamas/aio-usb-hotplug/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "441499a0025277d0fd4d602d1aea6a2da4951a6e6603bcea3f47a5f3d17ff66a",
                "md5": "bf7d6c8837a5726ebc24c0560e1d923b",
                "sha256": "7fa402ea0e60ed0bebdc38cf61ee0d3095252544bed0c2489fbeb2851f7d0dea"
            },
            "downloads": -1,
            "filename": "aio_usb_hotplug-6.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bf7d6c8837a5726ebc24c0560e1d923b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 11733,
            "upload_time": "2023-09-18T19:12:09",
            "upload_time_iso_8601": "2023-09-18T19:12:09.148508Z",
            "url": "https://files.pythonhosted.org/packages/44/14/99a0025277d0fd4d602d1aea6a2da4951a6e6603bcea3f47a5f3d17ff66a/aio_usb_hotplug-6.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6e88f86cdf626ef3a40bee73c6b3ff2148aba0936dc9594fc57116bea75e9f73",
                "md5": "6039743cb016dfeb3e7d82c0802f5c1c",
                "sha256": "544e9e4289f9c34b71a49054c7b1744291b8f55a1681847aae89a062d95c0b1a"
            },
            "downloads": -1,
            "filename": "aio_usb_hotplug-6.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6039743cb016dfeb3e7d82c0802f5c1c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 9102,
            "upload_time": "2023-09-18T19:12:10",
            "upload_time_iso_8601": "2023-09-18T19:12:10.853232Z",
            "url": "https://files.pythonhosted.org/packages/6e/88/f86cdf626ef3a40bee73c6b3ff2148aba0936dc9594fc57116bea75e9f73/aio_usb_hotplug-6.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-18 19:12:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ntamas",
    "github_project": "aio-usb-hotplug",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aio-usb-hotplug"
}
        
Elapsed time: 0.15512s