Quick Start
This guide will get you up and running with SmartAsync in 5 minutes.
Installation
pip install smartasync
Your First SmartAsync Method
from smartasync import smartasync
import httpx
class APIClient:
@smartasync
async def fetch_data(self, url: str):
async with httpx.AsyncClient() as client:
response = await client.get(url)
return response.json()
Using in Sync Context
# CLI tool or script
client = APIClient()
data = client.fetch_data("https://api.example.com/data")
print(data)
No await needed! SmartAsync automatically runs it with asyncio.run().
Using in Async Context
# FastAPI or async application
async def handler():
client = APIClient()
data = await client.fetch_data("https://api.example.com/data")
return data
Use await normally - SmartAsync returns a coroutine.
Key Points
Write async methods using
async defandawaitAdd
@smartasyncdecorator to make them work everywhereCall without await in sync contexts (CLI, scripts)
Call with await in async contexts (FastAPI, aiohttp)