Typing Stubs for icalendar

6.3.2.20260408 · active · verified Mon Apr 13

The `types-icalendar` package provides type annotations (stubs) for the `icalendar` library, which is an RFC 5545 compliant Python parser and generator for iCalendar files. This package is part of the `typeshed` project and specifically targets `icalendar` versions prior to 7.0.0. From `icalendar` version 7.0.0 onwards, type annotations are included directly within the `icalendar` package, making `types-icalendar` redundant for newer versions. It currently requires Python >=3.10 and is updated regularly based on typeshed contributions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic iCalendar file with an event using the `icalendar` library, for which `types-icalendar` provides type hints. It covers initializing a calendar, adding essential properties, creating and populating an event, and then serializing the calendar to a string. Note the use of `zoneinfo` for timezone-aware datetimes, which is crucial for iCalendar compatibility.

from icalendar import Calendar, Event, vText
from datetime import datetime
import zoneinfo

# Create a new Calendar object
cal = Calendar()
cal.add('prodid', '-//My Company//My Calendar App//EN')
cal.add('version', '2.0')
cal.add('summary', 'My Awesome Calendar')

# Create an Event
event = Event()
event.add('summary', 'Meeting with Client X')
event.add('dtstart', datetime(2026, 4, 15, 10, 0, 0, tzinfo=zoneinfo.ZoneInfo('America/New_York')))
event.add('dtend', datetime(2026, 4, 15, 11, 0, 0, tzinfo=zoneinfo.ZoneInfo('America/New_York')))
event.add('description', 'Discuss Q2 strategy and project roadmap.')
event.add('location', vText('Conference Room A'))
event['uid'] = '20260415T100000-abcd-1234@example.com'

# Add the event to the calendar
cal.add_component(event)

# Serialize the calendar to iCalendar format
ical_string = cal.to_ical().decode('utf-8')
print(ical_string)

# Example of parsing an iCalendar string
# parsed_cal = Calendar.from_ical(ical_string)
# for component in parsed_cal.walk():
#    if component.name == 'VEVENT':
#        print(component.get('summary'))

view raw JSON →