Skip to main content

A connector for Bleak Clients that handles transient connection failures

Project description

Bleak Retry Connector

CI Status Documentation Status Test coverage percentage

Poetry ruff pre-commit

PyPI Version Supported Python versions License

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:

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 = client.services
        print(f"Connected! Found {len(list(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.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

Credits

This package was created with Cookiecutter and the browniebroke/cookiecutter-pypackage project template.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

bleak_retry_connector-4.6.1.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bleak_retry_connector-4.6.1-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file bleak_retry_connector-4.6.1.tar.gz.

File metadata

  • Download URL: bleak_retry_connector-4.6.1.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for bleak_retry_connector-4.6.1.tar.gz
Algorithm Hash digest
SHA256 ac2d19362f96757708dff2b0fedfefd5a8d8efb724027a777e54cc8ac2fc5a3d
MD5 b203a1ab2ae812bc7dcbdfeff43eb464
BLAKE2b-256 7afc5de052d5995bfea6f5237b4e848e3fd2978777e5371d92dbce725d21181a

See more details on using hashes here.

Provenance

The following attestation bundles were made for bleak_retry_connector-4.6.1.tar.gz:

Publisher: ci.yml on Bluetooth-Devices/bleak-retry-connector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bleak_retry_connector-4.6.1-py3-none-any.whl.

File metadata

File hashes

Hashes for bleak_retry_connector-4.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 018ba421babe05785e5a6497c73f3894772fad0f7fa5b054d48beb3d180ce0c4
MD5 8313ebf9c769d5b024ef093e840bf9fb
BLAKE2b-256 987c4490be0547296648e4dfb77c0a1949c3cdc8963c9b621aecc168f1d4cb76

See more details on using hashes here.

Provenance

The following attestation bundles were made for bleak_retry_connector-4.6.1-py3-none-any.whl:

Publisher: ci.yml on Bluetooth-Devices/bleak-retry-connector

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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