Skip to main content

iCalendar parser/generator

Project description

The icalendar package is a RFC 5545 compatible parser/generator for iCalendar files.


Homepage:

https://icalendar.readthedocs.io

Code:

https://github.com/collective/icalendar

Mailing list:

https://github.com/collective/icalendar/issues

Dependencies:

python-dateutil and pytz.

License:

BSD


Python Package Version on PyPI PyPI - Python Version Downloads from PyPI GitHub Actions build status for main Documentation Status Test Coverage

Quick start guide

icalendar enables you to create, inspect and modify calendaring information with Python.

To install the package, run:

pip install icalendar

Inspect Files

You can open an .ics file and see all the events:

>>> import icalendar
>>> from pathlib import Path
>>> ics_path = Path("src/icalendar/tests/calendars/example.ics")
>>> with ics_path.open() as f:
...     calendar = icalendar.Calendar.from_ical(f.read())
>>> for event in calendar.walk('VEVENT'):
...     print(event.get("SUMMARY"))
New Year's Day
Orthodox Christmas
International Women's Day

Modify Content

Such a calendar can then be edited and saved again.

>>> calendar["X-WR-CALNAME"] = "My Modified Calendar"  # modify
>>> print(calendar.to_ical()[:129])  # save modification
BEGIN:VCALENDAR
VERSION:2.0
PRODID:collective/icalendar
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:My Modified Calendar

Create Events, TODOs, Journals, Alarms, …

icalendar supports the creation and parsing of all kinds of objects in the iCalendar (RFC 5545) standard.

>>> icalendar.Event()  # events
VEVENT({})
>>> icalendar.FreeBusy()  # free/busy times
VFREEBUSY({})
>>> icalendar.Todo()  # Todo list entries
VTODO({})
>>> icalendar.Alarm()  # Alarms e.g. for events
VALARM({})
>>> icalendar.Journal()   # Journal entries
VJOURNAL({})

Have a look at more examples.

Use timezones of your choice

With icalendar, you can localize your events to take place in different timezones. zoneinfo, dateutil.tz and pytz are compatible with icalendar. This example creates an event that uses all of the timezone implementations with the same result:

>>> import pytz, zoneinfo, dateutil.tz  # timezone libraries
>>> import datetime, icalendar
>>> e = icalendar.Event()
>>> tz = dateutil.tz.tzstr("Europe/London")
>>> e["X-DT-DATEUTIL"] = icalendar.vDatetime(datetime.datetime(2024, 6, 19, 10, 1, tzinfo=tz))
>>> tz = pytz.timezone("Europe/London")
>>> e["X-DT-USE-PYTZ"] = icalendar.vDatetime(datetime.datetime(2024, 6, 19, 10, 1, tzinfo=tz))
>>> tz = zoneinfo.ZoneInfo("Europe/London")
>>> e["X-DT-ZONEINFO"] = icalendar.vDatetime(datetime.datetime(2024, 6, 19, 10, 1, tzinfo=tz))
>>> print(e.to_ical())  # the libraries yield the same result
BEGIN:VEVENT
X-DT-DATEUTIL;TZID=Europe/London:20240619T100100
X-DT-USE-PYTZ;TZID=Europe/London:20240619T100100
X-DT-ZONEINFO;TZID=Europe/London:20240619T100100
END:VEVENT

Version 6 with zoneinfo

Version 6 of icalendar switches the timezone implementation to zoneinfo. This only affects you if you parse icalendar objects with from_ical(). The functionality is extended and is tested since 6.0.0 with both timezone implementations pytz and zoneinfo.

By default and since 6.0.0, zoneinfo timezones are created.

>>> dt = icalendar.Calendar.example("timezoned").walk("VEVENT")[0]["DTSTART"].dt
>>> dt.tzinfo
ZoneInfo(key='Europe/Vienna')

If you would like to continue to receive pytz timezones in parse results, you can receive all the latest updates, and switch back to earlier behavior:

>>> icalendar.use_pytz()
>>> dt = icalendar.Calendar.example("timezoned").walk("VEVENT")[0]["DTSTART"].dt
>>> dt.tzinfo
<DstTzInfo 'Europe/Vienna' CET+1:00:00 STD>

Version 6 is on branch main. It is compatible with Python versions 3.8 - 3.12, and PyPy3. We expect the main branch with versions 6+ to receive the latest updates and features.

Further Reading

You can find out more about this project:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

icalendar-6.0.1.tar.gz (98.4 kB view details)

Uploaded Source

Built Distribution

icalendar-6.0.1-py3-none-any.whl (131.3 kB view details)

Uploaded Python 3

File details

Details for the file icalendar-6.0.1.tar.gz.

File metadata

  • Download URL: icalendar-6.0.1.tar.gz
  • Upload date:
  • Size: 98.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for icalendar-6.0.1.tar.gz
Algorithm Hash digest
SHA256 1ff44825d7b41c3f77eac9e09cc67a770dd3c2377430c23b0eb7d91603088892
MD5 086a957b9b36d4443ab5e242d594be55
BLAKE2b-256 2fc8517de527ddd5acf8dfb4da1b0faf27ceba30526f481680f56e7c5b91dd83

See more details on using hashes here.

File details

Details for the file icalendar-6.0.1-py3-none-any.whl.

File metadata

  • Download URL: icalendar-6.0.1-py3-none-any.whl
  • Upload date:
  • Size: 131.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for icalendar-6.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9bf3d69203bd0366a9a29a8b0e220574580b86d7918afcb628fc6920287922f3
MD5 27324c3b6db6f462a5a5276d8c394981
BLAKE2b-256 76c5d10fc932f7fcc770180b4bf3c63df79d518086a51548422101f4a7c8fdfa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page