Sync / async parity¶
The library provides two clients with identical APIs:
RainbowMinerClient— async-first, built onaiohttpSyncRainbowMinerClient— blocking wrapper around the async client
Every public async method on RainbowMinerClient has a corresponding sync
method on SyncRainbowMinerClient with the same name and signature (minus
async/await). This parity is enforced by an automated test — when a new
async method is added, the sync counterpart is added in the same change.
Which should I use?¶
| Use case | Client |
|---|---|
| Home Assistant integration | RainbowMinerClient (async) |
Any asyncio application |
RainbowMinerClient (async) |
| CLI scripts | SyncRainbowMinerClient (sync) |
| Jupyter notebooks | SyncRainbowMinerClient (sync) |
| Existing synchronous codebase | SyncRainbowMinerClient (sync) |
Side-by-side comparison¶
How the sync client works¶
SyncRainbowMinerClient owns a private asyncio event loop and an internal
RainbowMinerClient instance. Each sync method call runs the corresponding
async method on that private loop, so callers never need to touch
asyncio.run().
This means:
- No event loop conflicts — the sync client manages its own loop, so it works inside environments that already have a running loop (though you'd typically use the async client in those cases).
- Same error types — both clients raise the same
RainbowMinerErrorhierarchy. - Same models — both return the same Pydantic model types.
Parity enforcement¶
Parity is enforced by tests/test_sync_client.py. If you add a new async
method to RainbowMinerClient, add the sync counterpart to
SyncRainbowMinerClient in the same change — the test will fail otherwise.