Quickstart#

This tutorial syncs one calendar from a CalDAV server into a SQLite file, then lists what the sync brought in. You need an account on a CalDAV server with at least one calendar, and calendaring-sync installed with the caldav extra, as Install shows.

Sync a calendar#

from caldav.davclient import DAVClient

from calendaring_sync import Replica, SQLiteStore
from calendaring_sync.adapters.caldav import CalDAVAdapter

URL = "https://caldav.example.com/"
USERNAME = "alice"
PASSWORD = "secret"

with (
    SQLiteStore("sync.db") as store,
    DAVClient(url=URL, username=USERNAME, password=PASSWORD) as client,
):
    calendar = client.get_calendars()[0]
    replica = Replica(store)
    adapter = CalDAVAdapter(replica, calendar)
    adapter.sync()

    for entry in replica.read_feed():
        print(entry.kind, entry.object_id)

Replace the URL, username, and password with your own, then run the script. It prints a line for each event in your first calendar, such as changed /calendars/alice/work/meeting.ics.

Change an event in your calendar app and run the script again. This sync fetches only that event, and the feed gains one entry for it.

What happened#

SQLiteStore keeps the sync state in sync.db, so each run continues where the last one stopped. On the first run, CalDAVAdapter listed the calendar in full and stored each event as a record. Later runs ask the server only for what changed since the sync token it stored. Every change also went into the change feed, which read_feed() returns from its first entry.

Only the lines that open the client and create the adapter are about CalDAV. With any other adapter, including one you write, the rest of the script stays the same.

Next steps#

Last updated on 2026-10-27.