Skip to content

mxm, IT's mad science

Personal tools
You are here: Home » Products » Open Source » iCalendar package
You can download mxm products here.

Due to it's technical and international nature, this section is in english.

Max M Has a blog too.

og er glad for mad


iCalendar package for Python

The iCalender package is a parser/generator of iCalender files for use with Python. It follows the RFC 2445 spec.


Visit codespeak instead


I have often needed to parse and generate iCalendar files. Finally I got tired of writing ad-hoc tools.

So this is my attempt at making an iCalendar package for Python. The inspiration has come from the email package in the standard lib, which I think is pretty simple, yet efficient and powerfull.

The aim is to make a package that is fully compliant to RFC 2445, well designed, simple to use and well documented.

Look in doc/ for introductory doctests and explanations.

All modules and classes have doctest that shows how they work, so it is all pretty well documented.

It can generate and parse iCalender files, and can easily be used as is.

But it does needs a bit more polish before i will considder it finished. I would say that it's about 95% done.


To open and parse a file:

        >>> from iCalendar import Calendar, Event
        >>> cal = Calendar.from_string(open('test.ics','rb').read())
        >>> cal
        VCALENDAR({'VERSION': '2.0', 'METHOD': 'Request', 'PRODID': '-//My product//'})

        >>> for component in cal.walk():

To create a calendar and write it to disc:

        >>> cal = Calendar()
        >>> from datetime import datetime
        >>> from iCalendar import UTC # timezone
        >>> cal.add('prodid', '-//My calendar product//')
        >>> cal.add('version', '2.0')

        >>> event = Event()
        >>> event.add('summary', 'Python meeting about calendaring')
        >>> event.add('dtstart', datetime(2005,4,4,8,0,0,tzinfo=UTC()))
        >>> event.add('dtend', datetime(2005,4,4,10,0,0,tzinfo=UTC()))
        >>> event.add('dtstamp', datetime(2005,4,4,0,10,0,tzinfo=UTC()))
        >>> event['uid'] = '20050115T101010/'
        >>> event.add('priority', 5)

        >>> cal.add_component(event)

        >>> f = open('example.ics', 'wb')
        >>> f.write(cal.as_string())
        >>> f.close()


This is the first public release, so it is most likely buggy in some degree. But it is usable for production.

It is dependent on the datetime package, so it requires Python >= 2.2


If you have any comments or feedback on the module, please contact me at:

I would love to hear use cases, or get ideas for improvements.


Get the latest version from the download page


LGPL (I have changed the license, the readme will reflect this in the next release.)

Created by maxm
Last modified 2005-08-26 10:53 PM


Posted by Anonymous User at 2005-02-09 10:56 PM
This looks very nice; would you coinsider LGPL? Lots of open source developers (who do the 50/50% thing)
can't use GPL on our "paying" projects, but LGPL usually works. I'd like to say money is involved, but
that's not an option, as mixed-licensing causes the legal department headaches. Our product itself is
on the fast track to LGPL (or BSD).

iCal parsing - newlines

Posted by Anonymous User at 2005-07-10 06:34 PM
i think it would be good to have an option to modify the newline parsing/writing so it can use \n as well as \r\n. Or are there some other way of getting the icals work with for example MS Outlook?


Posted by Anonymous User at 2006-06-21 03:15 PM
Hello there, I've found that this has some issues with recurrent events. Sorry for not posting to the mailing-list, but I don't think that subscribing to a mailing-list to report _one_ issue is very optimal...

Here's a test case, from an event generated by Microsoft Exchange and that _looks_ like it ought to be RFC-compliant (at least from what I could gather from reading the RFC...)

>>> vr = vRecur.from_ical('FREQ=DAILY;COUNT=5;INTERVAL=1;BYDAY=MO, TU, WE, TH, FR;WKST=SU')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "./icalendar/", line 932, in from_ical
raise ValueError, 'Error in recurrence rule: %s' % ical

(Rui Carmo, from