Aiosetups

async def main(): db = await init_db() redis = await init_redis() http_client = await init_http() # ... cleanup code scattered you use a setup registry. # aiosetups.py import asyncio from contextlib import asynccontextmanager from typing import Any, AsyncGenerator, Callable, Dict, List class AsyncSetup: """Register and manage async initializers and cleaners.""" def init (self): self._init_tasks: List[Callable[[], Any]] = [] self._cleanup_tasks: List[Callable[[], Any]] = [] self._resources: Dict[str, Any] = {}

# ... your app logic here ...

Since there is no widely known official package named aiosetups , I’ll provide the most useful interpretation: — common patterns in asyncio projects for initializing resources (databases, HTTP clients, message queues, etc.) in Python. aiosetups

async def close_postgres(resource): print(f"Closing resource") async def main(): db = await init_db() redis

async def setup_all(self): for task in self._init_tasks: await task() your app logic here

await setup.setup_all() print("Resources ready:", setup._resources)

def get(self, name: str): return self._resources.get(name) async def init_postgres(): # Imagine asyncpg.connect(...) return "conn": "fake pg connection"

aiosetups