Python library to access a CalDAV server

hildwin picture hildwin · Jul 13, 2013 · Viewed 9.8k times · Source

I run ownCloud on my webspace for a shared calendar. Now I'm looking for a suitable python library to get read only access to the calendar. I want to put some information of the calendar on an intranet website.

I have tried http://trac.calendarserver.org/wiki/CalDAVClientLibrary but it always returns a NotImplementedError with the query command, so my guess is that the query command doesn't work well with the given library.

What library could I use instead?

Answer

de fl0r picture de fl0r · Jun 24, 2015

I recommend the library, caldav.

Read-only is working really well with this library and looks straight-forward to me. It will do the whole job of getting calendars and reading events, returning them in the iCalendar format. More information about the caldav library can also be obtained in the documentation.

import caldav

client = caldav.DAVClient(<caldav-url>, username=<username>,
                          password=<password>)
principal = client.principal()
for calendar in principal.calendars():
    for event in calendar.events():
        ical_text = event.data

From this on you can use the icalendar library to read specific fields such as the type (e. g. event, todo, alarm), name, times, etc. - a good starting point may be this question.