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

  1. Write async methods using async def and await

  2. Add @smartasync decorator to make them work everywhere

  3. Call without await in sync contexts (CLI, scripts)

  4. Call with await in async contexts (FastAPI, aiohttp)

Next Steps