bleak-retry-connector


Namebleak-retry-connector JSON
Version 4.4.3 PyPI version JSON
download
home_pageNone
SummaryA connector for Bleak Clients that handles transient connection failures
upload_time2025-08-29 00:43:40
maintainerNone
docs_urlNone
authorJ. Nick Koston
requires_python>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Bleak Retry Connector

<p align="center">
  <a href="https://github.com/bluetooth-devices/bleak-retry-connector/actions?query=workflow%3ACI">
    <img src="https://img.shields.io/github/workflow/status/bluetooth-devices/bleak-retry-connector/CI/main?label=CI&logo=github&style=flat-square" alt="CI Status" >
  </a>
  <a href="https://bleak-retry-connector.readthedocs.io">
    <img src="https://img.shields.io/readthedocs/bleak-retry-connector.svg?logo=read-the-docs&logoColor=fff&style=flat-square" alt="Documentation Status">
  </a>
  <a href="https://codecov.io/gh/bluetooth-devices/bleak-retry-connector">
    <img src="https://img.shields.io/codecov/c/github/bluetooth-devices/bleak-retry-connector.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">
  </a>
</p>
<p align="center">
  <a href="https://python-poetry.org/">
    <img src="https://img.shields.io/badge/packaging-poetry-299bd7?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJJSURBVHgBfZLPa1NBEMe/s7tNXoxW1KJQKaUHkXhQvHgW6UHQQ09CBS/6V3hKc/AP8CqCrUcpmop3Cx48eDB4yEECjVQrlZb80CRN8t6OM/teagVxYZi38+Yz853dJbzoMV3MM8cJUcLMSUKIE8AzQ2PieZzFxEJOHMOgMQQ+dUgSAckNXhapU/NMhDSWLs1B24A8sO1xrN4NECkcAC9ASkiIJc6k5TRiUDPhnyMMdhKc+Zx19l6SgyeW76BEONY9exVQMzKExGKwwPsCzza7KGSSWRWEQhyEaDXp6ZHEr416ygbiKYOd7TEWvvcQIeusHYMJGhTwF9y7sGnSwaWyFAiyoxzqW0PM/RjghPxF2pWReAowTEXnDh0xgcLs8l2YQmOrj3N7ByiqEoH0cARs4u78WgAVkoEDIDoOi3AkcLOHU60RIg5wC4ZuTC7FaHKQm8Hq1fQuSOBvX/sodmNJSB5geaF5CPIkUeecdMxieoRO5jz9bheL6/tXjrwCyX/UYBUcjCaWHljx1xiX6z9xEjkYAzbGVnB8pvLmyXm9ep+W8CmsSHQQY77Zx1zboxAV0w7ybMhQmfqdmmw3nEp1I0Z+FGO6M8LZdoyZnuzzBdjISicKRnpxzI9fPb+0oYXsNdyi+d3h9bm9MWYHFtPeIZfLwzmFDKy1ai3p+PDls1Llz4yyFpferxjnyjJDSEy9CaCx5m2cJPerq6Xm34eTrZt3PqxYO1XOwDYZrFlH1fWnpU38Y9HRze3lj0vOujZcXKuuXm3jP+s3KbZVra7y2EAAAAAASUVORK5CYII=" alt="Poetry">
  </a>
  <a href="https://github.com/ambv/black">
    <img src="https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square" alt="black">
  </a>
  <a href="https://github.com/pre-commit/pre-commit">
    <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">
  </a>
</p>
<p align="center">
  <a href="https://pypi.org/project/bleak-retry-connector/">
    <img src="https://img.shields.io/pypi/v/bleak-retry-connector.svg?logo=python&logoColor=fff&style=flat-square" alt="PyPI Version">
  </a>
  <img src="https://img.shields.io/pypi/pyversions/bleak-retry-connector.svg?style=flat-square&logo=python&amp;logoColor=fff" alt="Supported Python versions">
  <img src="https://img.shields.io/pypi/l/bleak-retry-connector.svg?style=flat-square" alt="License">
</p>

A connector for Bleak Clients that handles transient connection failures

## Installation

Install this via pip (or your favourite package manager):

`pip install bleak-retry-connector`

## Usage

### Quick Start

Replace your direct `BleakClient.connect()` calls with `establish_connection()` for automatic retry logic and better error handling:

```python
import asyncio
from bleak import BleakScanner
from bleak_retry_connector import establish_connection, BleakClientWithServiceCache

async def connect_to_device():
    # Find your device
    device = await BleakScanner.find_device_by_address("AA:BB:CC:DD:EE:FF")

    if device is None:
        print("Device not found!")
        return

    # Establish connection with automatic retry logic
    client = await establish_connection(
        BleakClientWithServiceCache,  # Use BleakClientWithServiceCache for service caching
        device,
        device.name or "Unknown Device",
        max_attempts=3  # Will retry up to 3 times with backoff
    )

    try:
        # Use the connected client normally
        services = await client.get_services()
        print(f"Connected! Found {len(services)} services")

        # Read a characteristic
        value = await client.read_gatt_char("00002a00-0000-1000-8000-00805f9b34fb")
        print(f"Read value: {value}")

    finally:
        await client.disconnect()

# Run the example
asyncio.run(connect_to_device())
```

### Why Use bleak-retry-connector?

- **Automatic Retry Logic**: Handles transient connection failures automatically
- **Intelligent Backoff**: Uses appropriate delays between retry attempts
- **Service Caching**: `BleakClientWithServiceCache` caches services for faster reconnections
- **Better Error Messages**: Provides clear, actionable error messages
- **Platform-Specific Handling**: Manages quirks across different operating systems
- **Connection Slot Management**: Handles limited connection slots on some devices

### Common Connection Issues This Solves

- Device not found errors that resolve on retry
- Connection timeouts on first attempt
- "Out of connection slots" errors on ESP32 devices
- Interference from other Bluetooth operations
- Platform-specific connection quirks

For detailed documentation and advanced usage, see the [full documentation](https://bleak-retry-connector.readthedocs.io/en/latest/usage.html).

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- prettier-ignore-start -->
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- markdownlint-disable -->
<!-- markdownlint-enable -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
<!-- prettier-ignore-end -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

## Credits

This package was created with
[Cookiecutter](https://github.com/audreyr/cookiecutter) and the
[browniebroke/cookiecutter-pypackage](https://github.com/browniebroke/cookiecutter-pypackage)
project template.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "bleak-retry-connector",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": "J. Nick Koston",
    "author_email": "nick@koston.org",
    "download_url": "https://files.pythonhosted.org/packages/b6/08/8a62e114d5c1a7a0b4fee1c21a845061b0cc03bf617cc8ee7c27b2f164f9/bleak_retry_connector-4.4.3.tar.gz",
    "platform": null,
    "description": "# Bleak Retry Connector\n\n<p align=\"center\">\n  <a href=\"https://github.com/bluetooth-devices/bleak-retry-connector/actions?query=workflow%3ACI\">\n    <img src=\"https://img.shields.io/github/workflow/status/bluetooth-devices/bleak-retry-connector/CI/main?label=CI&logo=github&style=flat-square\" alt=\"CI Status\" >\n  </a>\n  <a href=\"https://bleak-retry-connector.readthedocs.io\">\n    <img src=\"https://img.shields.io/readthedocs/bleak-retry-connector.svg?logo=read-the-docs&logoColor=fff&style=flat-square\" alt=\"Documentation Status\">\n  </a>\n  <a href=\"https://codecov.io/gh/bluetooth-devices/bleak-retry-connector\">\n    <img src=\"https://img.shields.io/codecov/c/github/bluetooth-devices/bleak-retry-connector.svg?logo=codecov&logoColor=fff&style=flat-square\" alt=\"Test coverage percentage\">\n  </a>\n</p>\n<p align=\"center\">\n  <a href=\"https://python-poetry.org/\">\n    <img src=\"https://img.shields.io/badge/packaging-poetry-299bd7?style=flat-square&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAASCAYAAABrXO8xAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAJJSURBVHgBfZLPa1NBEMe/s7tNXoxW1KJQKaUHkXhQvHgW6UHQQ09CBS/6V3hKc/AP8CqCrUcpmop3Cx48eDB4yEECjVQrlZb80CRN8t6OM/teagVxYZi38+Yz853dJbzoMV3MM8cJUcLMSUKIE8AzQ2PieZzFxEJOHMOgMQQ+dUgSAckNXhapU/NMhDSWLs1B24A8sO1xrN4NECkcAC9ASkiIJc6k5TRiUDPhnyMMdhKc+Zx19l6SgyeW76BEONY9exVQMzKExGKwwPsCzza7KGSSWRWEQhyEaDXp6ZHEr416ygbiKYOd7TEWvvcQIeusHYMJGhTwF9y7sGnSwaWyFAiyoxzqW0PM/RjghPxF2pWReAowTEXnDh0xgcLs8l2YQmOrj3N7ByiqEoH0cARs4u78WgAVkoEDIDoOi3AkcLOHU60RIg5wC4ZuTC7FaHKQm8Hq1fQuSOBvX/sodmNJSB5geaF5CPIkUeecdMxieoRO5jz9bheL6/tXjrwCyX/UYBUcjCaWHljx1xiX6z9xEjkYAzbGVnB8pvLmyXm9ep+W8CmsSHQQY77Zx1zboxAV0w7ybMhQmfqdmmw3nEp1I0Z+FGO6M8LZdoyZnuzzBdjISicKRnpxzI9fPb+0oYXsNdyi+d3h9bm9MWYHFtPeIZfLwzmFDKy1ai3p+PDls1Llz4yyFpferxjnyjJDSEy9CaCx5m2cJPerq6Xm34eTrZt3PqxYO1XOwDYZrFlH1fWnpU38Y9HRze3lj0vOujZcXKuuXm3jP+s3KbZVra7y2EAAAAAASUVORK5CYII=\" alt=\"Poetry\">\n  </a>\n  <a href=\"https://github.com/ambv/black\">\n    <img src=\"https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square\" alt=\"black\">\n  </a>\n  <a href=\"https://github.com/pre-commit/pre-commit\">\n    <img src=\"https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square\" alt=\"pre-commit\">\n  </a>\n</p>\n<p align=\"center\">\n  <a href=\"https://pypi.org/project/bleak-retry-connector/\">\n    <img src=\"https://img.shields.io/pypi/v/bleak-retry-connector.svg?logo=python&logoColor=fff&style=flat-square\" alt=\"PyPI Version\">\n  </a>\n  <img src=\"https://img.shields.io/pypi/pyversions/bleak-retry-connector.svg?style=flat-square&logo=python&amp;logoColor=fff\" alt=\"Supported Python versions\">\n  <img src=\"https://img.shields.io/pypi/l/bleak-retry-connector.svg?style=flat-square\" alt=\"License\">\n</p>\n\nA connector for Bleak Clients that handles transient connection failures\n\n## Installation\n\nInstall this via pip (or your favourite package manager):\n\n`pip install bleak-retry-connector`\n\n## Usage\n\n### Quick Start\n\nReplace your direct `BleakClient.connect()` calls with `establish_connection()` for automatic retry logic and better error handling:\n\n```python\nimport asyncio\nfrom bleak import BleakScanner\nfrom bleak_retry_connector import establish_connection, BleakClientWithServiceCache\n\nasync def connect_to_device():\n    # Find your device\n    device = await BleakScanner.find_device_by_address(\"AA:BB:CC:DD:EE:FF\")\n\n    if device is None:\n        print(\"Device not found!\")\n        return\n\n    # Establish connection with automatic retry logic\n    client = await establish_connection(\n        BleakClientWithServiceCache,  # Use BleakClientWithServiceCache for service caching\n        device,\n        device.name or \"Unknown Device\",\n        max_attempts=3  # Will retry up to 3 times with backoff\n    )\n\n    try:\n        # Use the connected client normally\n        services = await client.get_services()\n        print(f\"Connected! Found {len(services)} services\")\n\n        # Read a characteristic\n        value = await client.read_gatt_char(\"00002a00-0000-1000-8000-00805f9b34fb\")\n        print(f\"Read value: {value}\")\n\n    finally:\n        await client.disconnect()\n\n# Run the example\nasyncio.run(connect_to_device())\n```\n\n### Why Use bleak-retry-connector?\n\n- **Automatic Retry Logic**: Handles transient connection failures automatically\n- **Intelligent Backoff**: Uses appropriate delays between retry attempts\n- **Service Caching**: `BleakClientWithServiceCache` caches services for faster reconnections\n- **Better Error Messages**: Provides clear, actionable error messages\n- **Platform-Specific Handling**: Manages quirks across different operating systems\n- **Connection Slot Management**: Handles limited connection slots on some devices\n\n### Common Connection Issues This Solves\n\n- Device not found errors that resolve on retry\n- Connection timeouts on first attempt\n- \"Out of connection slots\" errors on ESP32 devices\n- Interference from other Bluetooth operations\n- Platform-specific connection quirks\n\nFor detailed documentation and advanced usage, see the [full documentation](https://bleak-retry-connector.readthedocs.io/en/latest/usage.html).\n\n## Contributors \u2728\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- prettier-ignore-start -->\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- markdownlint-disable -->\n<!-- markdownlint-enable -->\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n<!-- prettier-ignore-end -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n## Credits\n\nThis package was created with\n[Cookiecutter](https://github.com/audreyr/cookiecutter) and the\n[browniebroke/cookiecutter-pypackage](https://github.com/browniebroke/cookiecutter-pypackage)\nproject template.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A connector for Bleak Clients that handles transient connection failures",
    "version": "4.4.3",
    "project_urls": {
        "Bug Tracker": "https://github.com/bluetooth-devices/bleak-retry-connector/issues",
        "Changelog": "https://github.com/bluetooth-devices/bleak-retry-connector/blob/main/CHANGELOG.md",
        "Documentation": "https://bleak-retry-connector.readthedocs.io",
        "Repository": "https://github.com/bluetooth-devices/bleak-retry-connector"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "db0f445cbd2cd41ca6af16bcecce50eeda984d49b98e53ece1e80ad5b7fc98e4",
                "md5": "0f6f6992eb5666ab78818d0102fa9cbb",
                "sha256": "17a478d525706488973b181fc789e960bc3fb4bcd94ccb0eee7b7b682442577b"
            },
            "downloads": -1,
            "filename": "bleak_retry_connector-4.4.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0f6f6992eb5666ab78818d0102fa9cbb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 18610,
            "upload_time": "2025-08-29T00:43:39",
            "upload_time_iso_8601": "2025-08-29T00:43:39.260685Z",
            "url": "https://files.pythonhosted.org/packages/db/0f/445cbd2cd41ca6af16bcecce50eeda984d49b98e53ece1e80ad5b7fc98e4/bleak_retry_connector-4.4.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b6088a62e114d5c1a7a0b4fee1c21a845061b0cc03bf617cc8ee7c27b2f164f9",
                "md5": "98be935def6b47a9c3aca8ec735a8c5c",
                "sha256": "70aa305dbd26eaf0586dd24723daac93ee3dd6a465e9782bf02b711fcbc4a527"
            },
            "downloads": -1,
            "filename": "bleak_retry_connector-4.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "98be935def6b47a9c3aca8ec735a8c5c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 18652,
            "upload_time": "2025-08-29T00:43:40",
            "upload_time_iso_8601": "2025-08-29T00:43:40.716073Z",
            "url": "https://files.pythonhosted.org/packages/b6/08/8a62e114d5c1a7a0b4fee1c21a845061b0cc03bf617cc8ee7c27b2f164f9/bleak_retry_connector-4.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-29 00:43:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bluetooth-devices",
    "github_project": "bleak-retry-connector",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "bleak-retry-connector"
}
        
Elapsed time: 0.42941s