API

Calendar

class ics.icalendar.Calendar(imports=None, events=None, creator=None)[source]

Represents an unique rfc5545 iCalendar.

__init__(imports=None, events=None, creator=None)[source]

Instanciates a new Calendar.

Parameters:
  • imports (string or list of lines/strings) – data to be imported into the Calendar(),
  • events (list of Events or EventList) – will be casted to ics.eventlist.EventList
  • creator (string) – uid of the creator program.

If imports is specified, __init__ ignores every other argument.

__iter__()[source]

Returns: iterable: an iterable version of __str__, line per line (with line-endings).

Example

Can be used to write calendar to a file:

>>> c = Calendar(); c.append(Event(name="My cool event"))
>>> open('my.ics', 'w').writelines(c)
__urepr__()[source]
Returns:representation (__repr__) of the calendar.
Return type:unicode

Should not be used directly. Use self.__repr__ instead.

clone()[source]
Returns:an exact deep copy of self
Return type:Calendar
creator[source]

Get or set the calendar’s creator.

Will return a string.
May be set to a string.
Creator is the PRODID iCalendar property.
It uniquely identifies the program that created the calendar.
events[source]

Get or set the list of calendar’s events.

Will return an EventList object (similar to python list).
May be set to a list or an EventList (otherwise will raise a ValueError).
If setted, will override all pre-existing events.

Event

class ics.event.Event(name=None, begin=None, end=None, duration=None, uid=None, description=None, created=None, location=None)[source]

A calendar event.

Can be full-day or between two instants. Can be defined by a beginning instant and a duration or end instant.

__eq__(other)[source]

Two events are considered equal if they have the same uid.

__hash__()[source]
Returns:hash of self. Based on self.uid.
Return type:int
__init__(name=None, begin=None, end=None, duration=None, uid=None, description=None, created=None, location=None)[source]

Instanciates a new ics.event.Event.

Parameters:
  • (string) (location) –
  • (Arrow-compatible) (created) –
  • (Arrow-compatible)
  • (datetime.timedelta) (duration) –
  • uid (string) – must be unique
  • (string)
  • (Arrow-compatible)
  • (string)
Raises:

ValueError – if end and duration are specified at the same time

__urepr__()[source]

Should not be used directly. Use self.__repr__ instead.

Returns:a unicode representation (__repr__) of the event.
Return type:unicode
clone()[source]
Returns:an exact copy of self
Return type:Event
has_end()[source]
Returns:self has an end
Return type:bool
make_all_day()[source]

Transforms self to an all-day event.

The day will be the day of self.begin.

all_day[source]
Returns:self is an all-day event
Return type:bool
begin[source]

Get or set the beginning of the event.

Will return an Arrow object.
May be set to anything that Arrow.get() understands.
If an end is defined (not a duration), .begin must not be set to a superior value.
duration[source]

Get or set the duration of the event.

Will return a timedelta object.
May be set to anything that timedelta() understands.
May be set with a dict ({“days”:2, “hours”:6}).
If set to a non null value, removes any already existing end time.
end[source]

Get or set the end of the event.

Will return an Arrow object.
May be set to anything that Arrow.get() understands.
If set to a non null value, removes any already existing duration.
Setting to None will have unexpected behavior if begin is not None.
Must not be set to an inferior value than self.begin.

EventList

class ics.eventlist.EventList(arg=[])[source]

EventList is a subclass of the standard list.

It can be used as a list but also has super slicing capabilities and some helpers.

__add__(*args, **kwargs)[source]

Add 2 ics.eventlist.EventList.

Returns:a new EventList containing a copy of each ics.event.Event in the union of both EventList
Return type:EventList
__getitem__(sl)[source]

Slices ics.eventlist.EventList.

Note : an ics.eventlist.EventList is always sorted and the slices returned by this method will be sorted too.

If sl is conventional (like [10], [4:12], [3:100:2], [::-1], …), it slices the ics.eventlist.EventList like a classical list(). If one of the 3 arguments ([start:stop:step]) is not None or an int, slicing differs.

In that case, start and stop are considerated like instants (or None) and step like a modificator. start and stop will be converted to Arrow objects (or None) with arrow.get().

  • start (Arrow-convertible): lower included bond,
  • stop (Arrow-convertible): upper, non included, bond.
Modificators:
  • begin: the beginning of the events has to be between the bonds.
  • end: the end of the events has to be between the bonds.
  • both: both the end and the beginning have to be between the bonds.
  • any: either (or both) the start of the beginning has to be between the bonds.
  • inc: the events have to include be bonds (start < event.begin < event.end < stop).
__init__(arg=[])[source]

Instanciates a new ics.eventlist.EventList.

Parameters:arg (iterable) – same argument as list() and pass it to list().
Raises:ValueError – if arg`contains elements which are not :class:`ics.event.Event
__setitem__(key, val)[source]

Set an item or a slice. Verifies that all items are instance of ics.event.Event

__setslice__(i, j, val)[source]

Compatibility for python2

append(elem)[source]

Append a element to self and verifies that it’s an ics.event.Event.

Parameters:elem (Event) – element to be appended
Raises:ValueError – if elem is not a ics.event.Event
at(instant)[source]
Parameters:(Arrow-convertible) (instant) –
Returns:list<Event>: all events that are occuring during instant.
clone()[source]
Returns:Copy of self containing copies of underlying Event
concurrent(event)[source]
Parameters:(Event) (event) –
Returns:list<Event>: all events that are overlapping event
now()[source]
Returns:list<Event>: all events that occurs now
on(day, strict=False)[source]
Parameters:
  • (Arrow-convertible) (day) –
  • strict (bool) – if True events will be returned only if they are strictly included in day.
Returns:

list<Event>: all events that occurs on day

today(strict=False)[source]
Parameters:strict (bool) – if True events will be returned only if they are strictly included in day.
Returns:list<Event>: all events that occurs today
__weakref__

list of weak references to the object (if defined)

ics.py is an elegant and simple iCalendar library for Python, built for human beings.

About

Ics.py is made by C4 and others and is under the Apache 2 licence.
Contributions are welcome !

About page

Useful Links