A connector for Bleak Clients that handles transient connection failures
Project description
Bleak Retry Connector
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:
BleakClientWithServiceCachecaches 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0645ca814fe9e0f2e0716ffdae5e54de25de75de6197145a1784f20f58e76844
|
|
| MD5 |
af07afd73c41fbc2a00360fcc46aebe8
|
|
| BLAKE2b-256 |
3202494f6a642b2aed04123a07071944681a0776259d656212133c10d0fb4b27
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bleak_retry_connector-4.6.0.tar.gz -
Subject digest:
0645ca814fe9e0f2e0716ffdae5e54de25de75de6197145a1784f20f58e76844 - Sigstore transparency entry: 1054051803
- Sigstore integration time:
-
Permalink:
Bluetooth-Devices/bleak-retry-connector@6c5a22e2a1afe60f14051ca2372140fe512380a8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Bluetooth-Devices
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6c5a22e2a1afe60f14051ca2372140fe512380a8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bleak_retry_connector-4.6.0-py3-none-any.whl.
File metadata
- Download URL: bleak_retry_connector-4.6.0-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b5ecab9dee8a67b1e64cccec47ffa8c55737b86550c366e02d11ce003d57ebd
|
|
| MD5 |
89b07d34a25bedce538061694d7f507a
|
|
| BLAKE2b-256 |
2338091973e8b930a551b5454f9a4d6fd3fed55a73d28769e75b1d7761b46572
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bleak_retry_connector-4.6.0-py3-none-any.whl -
Subject digest:
6b5ecab9dee8a67b1e64cccec47ffa8c55737b86550c366e02d11ce003d57ebd - Sigstore transparency entry: 1054051842
- Sigstore integration time:
-
Permalink:
Bluetooth-Devices/bleak-retry-connector@6c5a22e2a1afe60f14051ca2372140fe512380a8 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Bluetooth-Devices
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@6c5a22e2a1afe60f14051ca2372140fe512380a8 -
Trigger Event:
push
-
Statement type: