This module uses bleak backend API to implement a compatible solution for Pythonista iOS app.
It uses Pythonista built-in _cb module, that is wrapper to iOS CoreBluetooth.
Caution
This project is in beta, use it with caution
- This backend refers to Pythonista.cb docs
- This backend refers to existing
macOS CoreBluetooth bleak backendwas used as a reference - It also provides stub files for pythonista built-in modules as
_cbandpythonista.cb, and fake_cb.pyimplementation for testing on unsupported platforms - Use
Bleakdocs to explore how to useBleak
pip install bleak-pythonistaDirect import
import asyncio
from bleak_pythonista import BleakScanner, BleakClient
async def main():
devices = await BleakScanner.discover(
service_uuids=["<some-service-uuid>"] # optional
)
for d in devices:
print(d)
client = BleakClient(d)
await client.connect()
print(client.services)
asyncio.run(main())With bleak itself
import asyncio
from bleak import BleakScanner, BleakClient
from bleak_pythonista import BleakScannerPythonistaCB, BleakClientPythonistaCB
async def main():
devices = await BleakScanner.discover(
service_uuids=["<some-service-uuid>"], # optional
backend=BleakScannerPythonistaCB,
)
for d in devices:
print(d)
client = BleakClient(d, backend=BleakClientPythonistaCB)
await client.connect()
print(client.services)
asyncio.run(main())Warning
DO NOT NAME YOUR SCRIPT bleak.py or bleak_pythonista! It will cause a circular import error.
- CentralManagerDelegate (for now for scanning purpose only)
- client.BleakClientPythonistaCB
- scanner.BleakScannerPythonistaCB
_cbandpythonista.cbstubs- fake
cb.pyfor testing with backend simulation on unsupported platforms
Tip
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.