Skip to main content

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.

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.3.tar.gz (18.9 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.3-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bleak_retry_connector-4.6.3.tar.gz
Algorithm Hash digest
SHA256 c2fa859bc8b645b8eecde6dfefc49662765d4f43f0b0e2a18a50034660073201
MD5 c52ee41a14a3f317dc101b2843767393
BLAKE2b-256 2864acd7d6989a7f0294990c42f035698beccf3da04182b76c1180d3d35850fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for bleak_retry_connector-4.6.3.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.3-py3-none-any.whl.

File metadata

File hashes

Hashes for bleak_retry_connector-4.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d6bf724245d62667edf30b1fdb423a364eaf0a46825a2b7183b46eebc0f934b3
MD5 32073e21b3dd75030c2d5d2225b35f6c
BLAKE2b-256 5ff7f9592d6bb4a303d7a58cc097c788ccadec3ea127d56899db41fa4efab7fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for bleak_retry_connector-4.6.3-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.

Release history Release notifications | RSS feed

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