iCalEvents

0.3.1 · active · verified Tue Apr 14

iCalEvents is a simple Python 3 library designed to download, parse, and query iCalendar (iCal) sources. It provides functionalities for extracting event data, especially within specified time ranges, and handles recurring events. Maintained by Jazzband, its latest version (0.3.1) was released on September 26, 2025.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to fetch and display iCalendar events from a given URL within a specific date range. It includes a placeholder for an iCal URL, emphasizing the need for a valid source. The `fix_apple=True` parameter is included as a common best practice when dealing with Apple iCal sources.

import os
from datetime import datetime, timedelta
from icalevents.icalevents import events

# Replace with your actual iCal URL, e.g., from Google Calendar or iCloud
ICAL_URL = os.environ.get('ICAL_SOURCE_URL', 'https://example.com/path/to/your/calendar.ics')

if not ICAL_URL or ICAL_URL == 'https://example.com/path/to/your/calendar.ics':
    print("Please set the ICAL_SOURCE_URL environment variable or replace the placeholder in the code.")
else:
    # Define a time range for events (e.g., next 7 days)
    start_date = datetime.now()
    end_date = start_date + timedelta(days=7)

    # Fetch events
    try:
        calendar_events = events(ICAL_URL, start=start_date, end=end_date, fix_apple=True)

        if calendar_events:
            print(f"Found {len(calendar_events)} events between {start_date.date()} and {end_date.date()}:")
            for event in calendar_events:
                print(f"- {event.summary} (Start: {event.start}, End: {event.end})")
        else:
            print("No events found in the specified range.")
    except Exception as e:
        print(f"Error fetching events: {e}")
        print("Ensure the ICAL_SOURCE_URL is correct and accessible.")

view raw JSON →