ics: iCalendar (RFC 5545) Parser

0.7.2 · active · verified Wed Apr 15

ics is a Python library for parsing, creating, and manipulating iCalendar files (RFC 5545). It provides an object-oriented API to work with Calendars, Events, Todos, Alarms, and other iCalendar components. The current version is 0.7.2, and releases occur periodically for bug fixes, minor enhancements, and major version upgrades that introduce breaking changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a new iCalendar object, add events with basic properties like name, start time, and duration, and then output the calendar as an iCalendar string. You can also save it to a .ics file.

from ics import Calendar, Event
from datetime import datetime

# Create a new Calendar
c = Calendar()

# Create a new Event
e = Event()
e.name = "My cool event"
e.begin = datetime(2024, 1, 1, 10, 0, 0)
e.duration = {'hours': 1}
e.description = "This is a description for my event."

# Add the event to the calendar
c.events.add(e)

# Add another event
e2 = Event(name="Another event", begin='2024-01-02 14:30:00')
c.events.add(e2)

# Print the iCalendar string
print(str(c))

# To save to a file (example):
# with open('my_calendar.ics', 'w') as f:
#     f.writelines(c)

view raw JSON →