Sync from asyncio code#
Each adapter that ships with calendaring-sync has an asynchronous variant for an asynchronous client, such as AsyncCalDAVAdapter. Its methods are the same, as coroutines. An adapter you write gets its variant from AsyncAdapter, as Write an adapter shows.
import asyncio
from caldav.aio import AsyncDAVClient
from calendaring_sync.adapters.caldav import AsyncCalDAVAdapter
async def sync() -> None:
async with AsyncDAVClient(url=URL, username=USERNAME, password=PASSWORD) as client:
calendar = (await client.get_calendars())[0]
adapter = AsyncCalDAVAdapter(replica, calendar)
await adapter.sync()
asyncio.run(sync())
The adapter keeps the event loop free during a sync, as AsyncAdapter describes. The replica itself is synchronous: call its methods, such as read_feed(), directly, or through asyncio.to_thread() when they read a lot.