Skip to main content

Python iCalendar implementation (rfc 2445)

Project description

This is an iCalendar rfc 5545 implementation in python. The goal of this project is to offer a calendar library that fills gaps in other widely used calendar libraries such as:

  • Relevant and practical features needed for building a calendar application -- namely recurring events.
  • Simple APIs that are straight forward to use
  • High quality code base with high test coverage and regular releases.

ical's main focus is on simplicity. Internally, this library uses other existing data parsing libraries making it easy to support as much as possible of rfc5545. It is not a goal to support everything exhaustively (e.g. enterprise features), however, the simplicity of the implementation makes it easy to do so. The package has high coverage, and high test coverage, and is easy to extend with new rfc5545 properties.

This packages uses semantic versioning, and releases often, and works on recent python versions.

See documentation for full quickstart and API reference.

Quickstart

The example below creates a Calendar, then adds an all day event to the calendar, then iterates over all events on the calendar.

from datetime import date

from ical.calendar import Calendar
from ical.event import Event

calendar = Calendar()
calendar.events.append(
    Event(summary="Event summary", start=date(2022, 7, 3), end=date(2022, 7, 4)),
)
for event in calendar.timeline:
    print(event.summary)

Reading ics files

This example parses an .ics file from disk and creates a ical.calendar.Calendar object, then prints out the events in order:

from pathlib import Path
from ical.calendar_stream import IcsCalendarStream
from ical.exceptions import CalendarParseError

filename = Path("example/calendar.ics")
with filename.open() as ics_file:
    try:
        calendar = IcsCalendarStream.calendar_from_ics(ics_file.read())
    except CalendarParseError as err:
        print(f"Failed to parse ics file '{str(filename)}': {err}")
    else:
        print([event.summary for event in calendar.timeline])

Writing ics files

This example writes a calendar object to an ics output file:

from pathlib import Path
from ical.calendar_stream import IcsCalendarStream

filename = Path("example/output.ics")
with filename.open() as ics_file:
    ics_file.write(IcsCalendarStream.calendar_to_ics(calendar))

Application-level APIs

The above APIs are used for lower level interaction with calendar components, however applications require a higher level interface to manage some of the underlying complexity. The ical.store library is used to manage state at a higher level (e.g. ensuring timezones are created properly) or handling edits to recurring events.

Recurring events

A calendar event may be recurring (e.g. weekly, monthly, etc). Recurring events are represented in a ical.calendar.Calendar with a single ical.event.Event object, however when observed through a ical.timeline.Timeline will be expanded based on the recurrence rule. See the rrule, rdate, and exdate fields on the ical.event.Event for more details.

Related Work

There are other python rfc5545 implementations that are more mature, and having been around for many years, are still active, and served as reference implementations for this project:

You may prefer these projects if you want something that changes less often or if you require a non-modern version of python and if you don't mind patching recurring events on top yourself e.g. using python-recurring-ical-events.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

ical-13.2.5.tar.gz (131.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ical-13.2.5-py3-none-any.whl (128.4 kB view details)

Uploaded Python 3

File details

Details for the file ical-13.2.5.tar.gz.

File metadata

  • Download URL: ical-13.2.5.tar.gz
  • Upload date:
  • Size: 131.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ical-13.2.5.tar.gz
Algorithm Hash digest
SHA256 1cc3116e6f522eeeaa694b3e20b58dbfbe4b281954a8d3d28892cfb61f03fd40
MD5 32d629da08079ac1fc05054d4f1167f4
BLAKE2b-256 f51cdc7378c5ba63e8b0f2987bd827a1e40bd27196d37a7082be0593551e8ed8

See more details on using hashes here.

Provenance

The following attestation bundles were made for ical-13.2.5.tar.gz:

Publisher: publish.yaml on allenporter/ical

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ical-13.2.5-py3-none-any.whl.

File metadata

  • Download URL: ical-13.2.5-py3-none-any.whl
  • Upload date:
  • Size: 128.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ical-13.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 410c195c59244c59bd6d1ffd6b27fb96ab29cf063b7359b531ee5de055f32486
MD5 2a62d27c7adc62b75a109f6b8a869988
BLAKE2b-256 6908b377a57bcaaf7f63c53137e59655bf33957b49df90394a2e0d0d554a049f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ical-13.2.5-py3-none-any.whl:

Publisher: publish.yaml on allenporter/ical

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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