Who owns the async client?
Connection reuse and cleanup in Python libraries.
Creating a new HTTP client for every request can discard reusable connections. Keep one client alive for related operations, then close it when the work is complete.
Make ownership explicit
In SpotAPI, a catalogue context owns the client it creates. Both searches share that context:
from spotapi import Catalogue
async def search_music():
async with Catalogue() as catalogue:
first = await catalogue.search("Daft Punk")
second = await catalogue.search("Nina Simone")
return first, secondA helper that receives an existing client should borrow it rather than closing it. The caller remains responsible for its lifetime. An asynchronous context manager makes cleanup happen even when an operation raises an exception.
Retries belong at the request boundary
A timed-out write might already have succeeded. Check the resulting state before replaying a mutation. Respect rate limits and bound concurrency.
See SpotAPI's request policy for its specific guarantees.