A connector for Bleak Clients that handles transient connection failures
Maintained. Last release 3 months ago, commits in 3 of the last 26 weeks. Weaker on commit activity.
pip install bleak-retry-connectorA connector for Bleak Clients that handles transient connection failures
Maintained. Last release 3 months ago, commits in 3 of the last 26 weeks. Weaker on commit activity.
pip install bleak-retry-connectorA connector for Bleak Clients that handles transient connection failures
Install this via pip (or your favourite package manager):
pip install bleak-retry-connector
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())
BleakClientWithServiceCache caches services for faster reconnectionsFor detailed documentation and advanced usage, see the full documentation.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
This package was created with Cookiecutter and the browniebroke/cookiecutter-pypackage project template.
Use together with bleak-retry-connector: extensions, drivers, servers and companion tools.