Ics.py : iCalendar for Humans

Release 0.7.

Ics.py is a pythonic iCalendar (rfc5545) library. Its goals are to read and write ics data in a developer-friendly way.

It is written in Python 3 (3.6, 3.7 and 3.8 supported) and is Apache2 Licensed.

The iCalendar specification is complicated, you don’t like RFCs but you want/have to use the ics format and you love pythonic APIs? ics.py is for you!

Quickstart

Install using pip:

$ pip install ics

Import a calendar from a file

from ics import Calendar
import requests

url = "https://urlab.be/events/urlab.ics"
c = Calendar(requests.get(url).text)

c
# <Calendar with 118 events and 0 todo>
c.events
# {<Event 'Visite de "Fab Bike"' begin:2016-06-21T15:00:00+00:00 end:2016-06-21T17:00:00+00:00>,
# <Event 'Le lundi de l'embarqué: Adventure in Espressif Non OS SDK edition' begin:2018-02-19T17:00:00+00:00 end:2018-02-19T22:00:00+00:00>,
#  ...}
e = list(c.timeline)[0]
"Event '{}' started {}".format(e.name, e.begin.humanize())
# "Event 'Workshop Git' started 2 years ago"

Create a new calendar and add events

from ics import Calendar, Event
c = Calendar()
e = Event()
e.name = "My cool event"
e.begin = '20140101 00:00:00'
c.events.add(e)
c.events
# {<Event 'My cool event' begin:2014-01-01 00:00:00 end:2014-01-01 00:00:01>}

Export a Calendar to a file

with open('my.ics', 'w') as f:
    f.write(c)
# And it's done !

# iCalendar-formatted data is also available in a string
str(c)
# 'BEGIN:VCALENDAR\nPRODID:...