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 black 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 = 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.

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

This version

4.6.0

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bleak_retry_connector-4.6.0.tar.gz
Algorithm Hash digest
SHA256 0645ca814fe9e0f2e0716ffdae5e54de25de75de6197145a1784f20f58e76844
MD5 af07afd73c41fbc2a00360fcc46aebe8
BLAKE2b-256 3202494f6a642b2aed04123a07071944681a0776259d656212133c10d0fb4b27

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for bleak_retry_connector-4.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b5ecab9dee8a67b1e64cccec47ffa8c55737b86550c366e02d11ce003d57ebd
MD5 89b07d34a25bedce538061694d7f507a
BLAKE2b-256 2338091973e8b930a551b5454f9a4d6fd3fed55a73d28769e75b1d7761b46572

See more details on using hashes here.

Provenance

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