icalendar is an RFC 5545 compatible parser and generator of iCalendar files. It facilitates the creation, modification, and parsing of calendar data (events, todos, journals) in Python. The library is actively maintained with frequent patch releases within major versions, and new major versions are released occasionally to introduce breaking changes and new features.
pip install icalendarVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create an iCalendar object with an event and a recurrence rule, serialize it to an iCalendar string, and then parse that string back into a Python object to extract event details.
If you were reading from a file, explicitly read the content into a string or bytes first: `ical_data = file.read(); cal = Calendar.from_ical(ical_data)`.
Always use timezone-aware `datetime` objects, preferably `datetime.timezone.utc`, when adding event times to avoid ambiguity and ensure correct RFC 5545 compliance.
Explicitly provide `tzinfo` for all `datetime` objects, e.g., using `datetime.datetime.now(datetime.timezone.utc)` or `datetime.datetime(..., tzinfo=zoneinfo.ZoneInfo('America/New_York'))` (Python >=3.9). For older Python, `pytz` is commonly used.Update calls from `vDDDTypes(value)` to `vDDDTypes.from_str(value)` or directly use `component.add('property', value)` for common cases where `icalendar` handles the type conversion automatically.Ensure that datetime properties are assigned with a proper Python datetime object. If you have a string, parse it into a datetime object first, or use `icalendar.vDatetime` if you need specific iCalendar value handling.
Validate the input iCalendar data for correctness (e.g., using an online validator like icalendar.org/validator). Common issues include incorrect line endings, missing required components (BEGIN/END:VCALENDAR, VEVENT), or improperly formatted properties/parameters.
Review your code to ensure that you are adding only one 'METHOD' property (e.g., 'METHOD:PUBLISH') to your `icalendar.Calendar` instance. If different methods are needed, they should be in separate VCALENDAR components.
No dependency data recorded yet.