Aiosetups !!exclusive!! < 2025-2026 >
async def close_postgres(resource): print(f"Closing resource")
Below is a practical, ready-to-use content snippet / documentation-style explanation. aiosetups is a conceptual / utility module that provides reusable patterns to initialize, manage, and gracefully shut down async resources. Typical use case Instead of manually managing: aiosetups
def get(self, name: str): return self._resources.get(name) async def init_postgres(): # Imagine asyncpg.connect(...) return "conn": "fake pg connection" Common alternatives: async def setup_all(self): for task in
await setup.cleanup_all() if == " main ": asyncio.run(main()) Better: asynccontextmanager approach @asynccontextmanager async def aiosetup(*resources): """Context manager for async setup/cleanup.""" initialized = [] try: for res in resources: inst = await res["init"]() initialized.append((res["name"], inst, res.get("cleanup"))) yield name: inst for name, inst, _ in initialized finally: for name, inst, cleanup in reversed(initialized): if cleanup: await cleanup(inst) Usage async def main(): async with aiosetup( "name": "db", "init": init_postgres, "cleanup": close_postgres, "name": "redis", "init": init_redis ) as resources: db = resources["db"] redis = resources["redis"] # work with db & redis If you meant a real PyPI package No package named aiosetups exists on PyPI (checked as of 2026). Common alternatives: res.get("cleanup"))) yield name: inst for name
async def setup_all(self): for task in self._init_tasks: await task()
| Package | Purpose | |----------------|--------------------------------------| | async-lru | Async caching | | aiofiles | Async file I/O | | aioredis | Redis client | | asyncpg | PostgreSQL driver | | anyio / asyncio | Low-level async primitives |