Recurring iCal Events

3.8.1 · active · verified Sat Apr 11

This library calculates recurrence times of events, todos, alarms, and journals based on the iCalendar RFC5545 specification. It provides a convenient way to expand recurring events within a given time range from an iCalendar object. The current version is 3.8.1, with a regular release cadence as evidenced by frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to parse an iCalendar string, extract a recurring event, and then expand its occurrences within a specified date range using the `recurring_ical_events` library. It uses `icalendar` for parsing the base calendar and `datetime` for defining the period.

import recurring_ical_events
import icalendar
import datetime

# An iCalendar string with a daily recurring event
calendar_string = """BEGIN:VCALENDAR\nPRODID:-//Example Corp.//iCalGen 1.0//EN\nVERSION:2.0\nBEGIN:VEVENT\nDTSTART;TZID=America/New_York:20231201T090000\nDTEND;TZID=America/New_York:20231201T100000\nRRULE:FREQ=DAILY;COUNT=3\nSUMMARY:Daily Meeting\nEND:VEVENT\nEND:VCALENDAR"""

# Parse the iCalendar string
calendar = icalendar.Calendar.from_ical(calendar_string)

# Define the period for which to get events
start_date = datetime.datetime(2023, 11, 20, tzinfo=datetime.timezone.utc)
end_date = datetime.datetime(2023, 12, 31, tzinfo=datetime.timezone.utc)

# Get recurring events within the specified period
events = recurring_ical_events.of(calendar).between(start_date, end_date)

print(f"Found {len(events)} events:")
for event in events:
    print(f"- {event['SUMMARY']} on {event['DTSTART'].dt.isoformat()}")

view raw JSON →