Ics.py : iCalendar for Humans¶
(Release 0.4)
Ics.py is a pythonic and easy iCalendar (rfc5545) library. It’s goals are to read and write ics data in a developer-friendly way.
It is written in Python (>=2.7 and >=3.3) and is Apache2 Licensed.
iCalendar 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 (or another method).
$ pip install ics
Import a calendar from a file¶
>>> from ics import Calendar
>>> try:
>>> from urllib2 import urlopen # py2
>>> except ImportError:
>>> from urllib.request import urlopen # py3
>>> url = "https://calendar.google.com/calendar/ical/en.usa%23holiday%40group.v.calendar.google.com/public/basic.ics"
>>> c = Calendar(urlopen(url).read().decode('iso-8859-1'))
>>> import requests # Alternative: use requests
>>> c = Calendar(requests.get(url).text)
>>> c
<Calendar with 42 events>
>>> c.events
[<Event 'SmartMonday #1' begin:2013-12-13 20:00:00 end:2013-12-13 23:00:00>,
<Event 'RFID workshop' begin:2013-12-06 12:00:00 end:2013-12-06 19:00:00>,
...]
>>> e = c.events[10]
>>> "Event '{}' started {}".format(e.name, e.begin.humanize())
"Event 'Mitch Altman soldering workshop' started 6 days 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.append(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.writelines(c)
>>> # And it's done !
iCalendar-formatted data is also available in a string
>>> str(c)
'BEGIN:VCALENDAR\nPRODID:...