API Reference#
This is the public API for this library.
Core functionality#
This is the core of the functionality of the library.
The first step is to customize which components to query with recurring_ical_events.of().
- recurring_ical_events.of(a_calendar, keep_recurrence_attributes=False, components=('VEVENT',), skip_bad_series=False, calendar_query=CalendarQuery)[source]#
Create a query for recurring components in a_calendar.
If the argument is a calendar, this will also correct times according to
X-WR-TIMEZONE.- Parameters:
a_calendar (icalendar.cal.Component) – an
icalendar.cal.calendar.Calendarcomponent likeicalendar.cal.calendar.Calendar.keep_recurrence_attributes – Whether to keep attributes that are only used to calculate the recurrence (
RDATE,EXDATE,RRULE).components (recurring_ical_events.query.T_COMPONENTS) – A list of component type names of which the recurrences should be returned. This can also be instances of
SelectComponents. Examples:("VEVENT", "VTODO", "VJOURNAL", "VALARM")skip_bad_series (
bool) – Whether to skip series of components that contain errors. You can useCalendarQuery.suppressed_errorsto specify which errors to skip.calendar_query (
type[CalendarQuery]) – TheCalendarQueryclass to use.
- Return type:
Query#
of() returns a recurring_ical_events.CalendarQuery object, which can be used to query the calendar.
For the most common cases, you do not need to look any further.
- class recurring_ical_events.CalendarQuery(calendar, keep_recurrence_attributes=False, components=('VEVENT',), skip_bad_series=False)[source]#
Query a calendar for occurrences.
Functions like
at(),between()andmafter()can be used to query the selected components. If any malformed icalendar information is found, anInvalidCalendarexception is raised. For other bad arguments, you should expect aValueError.- suppressed_errors#
a list of errors to suppress when skip_bad_series is True
- after(earliest_end)[source]#
Iterate over components happening during or after earliest_end.
- Parameters:
earliest_end (recurring_ical_events.types.DateArgument) – A date specification. See
to_datetime(). Anything happening during or after earliest_end is returned in the order of start time.- Return type:
- all()[source]#
Generate all Components.
The Components are sorted from the first to the last Occurrence. Calendars can contain millions of Occurrences. This iterates safely across all of them.
- at(date)[source]#
Return all events within the next 24 hours of starting at the given day.
- Parameters:
date (recurring_ical_events.types.DateArgument) – A date specification, see
to_datetime().
This is translated to
between()in the following way:- A year returns all occurrences within that year.
Example:
(2019,),2019
- A month returns all occurrences within that month.
Example:
(2019, 1)
- A day returns all occurrences within that day.
Examples:
(2019, 1, 19)datetime.date(2019, 1, 19)"20190101"
- An hour returns all occurrences within that hour.
Example:
(2019, 1, 19, 1)
- A minute returns all occurrences within that minute.
Example:
(2019, 1, 19, 13, 30 )
- A second returns all occurrences at that exact second.
Examples:
(2019, 1, 19, 13, 30, 59)datetime.datetime(2019, 1, 19, 13, 30, 59)datetime.datetime(2019, 1, 19, tzinfo=datetime.timezone.utc),datetime.datetime(2019, 1, 19, 13, 30, 59, tzinfo=ZoneInfo('Europe/London'))"20190119T133059Z"
- between(start, stop)[source]#
Return events at a time between start (inclusive) and end (inclusive)
- Parameters:
start – A date specification. See
to_datetime().stop – A date specification or a
datetime.timedeltarelative to start.
Warning
If you pass a
datetime.datetimeto bothstartandstop, make sure thedatetime.datetime.tzinfois the same.
- count()[source]#
Return the amount of recurring components in this calendar.
Warning
Do not use this in production as it generates all occurrences.
- Return type:
- property first: icalendar.cal.Component#
Return the first recurring component in this calendar.
- Returns:
The first recurring component in this calendar.
- Raises:
IndexError – if the calendar is empty
- paginate(page_size, earliest_end=None, latest_start=None, next_page_id='')[source]#
Return pages for pagination.
- Parameters:
page_size (
int) – the number of components per pageearliest_end (
Optional[recurring_ical_events.types.DateArgument]) – the start of the first page All components occur after this date. Seeto_datetime()for possible values.latest_start (
Optional[recurring_ical_events.types.DateArgument]) – the end of the last page All components occur before this date. Seeto_datetime()for possible values.next_page_id (
str) – The id of the next page. This is optional for the first page. These are safe to pass outside of the application and back in.
- Return type:
- static to_datetime(date)[source]#
Convert date inputs of various sorts into a datetime object.
- Parameters:
date (recurring_ical_events.types.DateArgument) – A date specification.
Date Specification:
a year like
(2019,)or2019(int)a month like
(2019, 1)for January of 2019a day like
(2019, 1, 19)for the first of January 2019a day with hours,
(2019, 1, 19, 1)a day with minutes,
(2019, 1, 19, 13, 30 )a day with seconds,
(2019, 1, 19, 13, 30, 59)a
strin the formatyyyymmdda
strin the formatyyyymmddThhmmssZ
list from at() and between()#
The result of both recurring_ical_events.CalendarQuery.between() and
recurring_ical_events.CalendarQuery.at() is a list of icalendar.cal.component.Component
objects like icalendar.cal.event.Event.
By default, all attributes of the event with repetitions are copied, like UID and SUMMARY.
However, these attributes may differ from the source event:
DTSTARTwhich is the start of the event instance. (always present)DTENDwhich is the end of the event instance. (always present)RDATE,EXDATE,RRULEare the rules to create event repetitions. They are not included in repeated events, see Issue 23. To change this, useof(calendar, keep_recurrence_attributes=True).
Generator from after() and all()#
If the resulting components are ordered when recurring_ical_events.CalendarQuery.after() or
recurring_ical_events.CalendarQuery.all() is used.
The result is an iterator that returns the events in order.
for event in recurring_ical_events.of(an_icalendar_object).after(datetime.datetime.now()):
print(event["DTSTART"]) # The start is ordered
Timezones and floating time#
This library makes a distinction between floating time and times with timezones.
Examples:
Event 1 happes at 12:00 in Singapore and event 2 on the same day at 12:00 in New York.
If you query that day without timezone, you will get both events.
If you query 12:00 - 13:00 without timezone, you will get both events.
If you query 12:00 - 13:00 in
Asia/Singapore, you will only get event 1.If you query 12:00 - 13:00 in
America/New_York, you will only get event 2.
If an event happens at night in floating time (without timezone) and you query that day it will appear regardless of the timezone of the query. Which is at different times in different timezones.
icalendar.cal.alarm.Alarmhas aTRIGGERwhich is in UTC. The timezone to compute that for alarms relative to floating events will be taken from the start and stop arguments.
Pagination#
For ease of use, pagination has been introduced. These are the pages returned by the query.
Pagination for recurring ical events.
See niccokunzmann/python-recurring-ical-events#211
- class recurring_ical_events.pages.Page(components, next_page_id='')[source]#
One page in a series of pages.
Examples
Check if the page has components.
if page: print(f"We have {len(page)} components.")
Go though the components:
for component in page: print(component)
- property components: list[TypeAliasForwardRef('icalendar.cal.Component')]#
All the components of this page.
- class recurring_ical_events.pages.Pages(occurrence_iterator, size, stop=None, keep_recurrence_attributes=False)[source]#
A pagination configuration to iterate over pages.
This is an
Iteratorthat returnsPageobjects.- generate_next_page()[source]#
Generate the next page.
In contrast to
next(pages), this does not raiseStopIteration. But it works the same: the next page is generated and returned. The last page is empty.- Return type:
Complete API#
Calculate repetitions of icalendar components.
- class recurring_ical_events.AbsoluteAlarmAdapter(alarm, parent)[source]#
Bases:
ComponentAdapterAdapter for absolute alarms.
- class recurring_ical_events.AbsoluteAlarmSeries[source]#
Bases:
objectA series of absolute alarms.
- between(span_start, span_stop)[source]#
Components between the start (inclusive) and end (exclusive).
The result does not need to be ordered.
- Return type:
- class recurring_ical_events.AlarmOccurrence(trigger, alarm, parent)[source]#
Bases:
OccurrenceAdapter for absolute alarms.
- as_component(keep_recurrence_attributes)[source]#
Return the alarm’s parent as a modified component.
- property id: recurring_ical_events.occurrence.OccurrenceID#
The id of the component.
- class recurring_ical_events.AlarmSeriesRelativeToEnd(alarm, series)[source]#
Bases:
AlarmSeriesRelativeToStartA series of alarms relative to the start of a component.
- between(span_start, span_stop)[source]#
Components between the start (inclusive) and end (exclusive).
The result does not need to be ordered.
- class recurring_ical_events.AlarmSeriesRelativeToStart(alarm, series)[source]#
Bases:
objectA series of alarms relative to the start of a component.
- between(span_start, span_stop)[source]#
Components between the start (inclusive) and end (exclusive).
The result does not need to be ordered.
- Return type:
- class recurring_ical_events.Alarms(parents=(EventAdapter, TodoAdapter))[source]#
Bases:
SelectComponentsSelect alarms and find their times.
By default, alarms from TODOs and events are collected. You can use this to change which alarms are collected:
Alarms((EventAdapter,)) Alarms((TodoAdapter,))
- collect_parent_series_from(source, suppress_errors)[source]#
Collect the parent components of alarms.
- class recurring_ical_events.AllKnownComponents(series=Series, occurrence=Occurrence, collector=ComponentsWithName)[source]#
Bases:
SelectComponentsGroup all known components into series.
- exception recurring_ical_events.BadRuleStringFormat(message, rule)[source]#
Bases:
InvalidCalendarAn iCal rule string is badly formatted.
- class recurring_ical_events.ComponentAdapter(component)[source]#
Bases:
ABCA unified interface to work with icalendar components.
- as_component(start=None, stop=None, keep_recurrence_attributes=True)[source]#
Create a shallow copy of the source event and modify some attributes.
- classmethod collect_series_from(source, suppress_errors)[source]#
Collect all components for this adapter.
This is a shortcut.
- property duration: datetime.timedelta#
The duration of the component.
- property end: recurring_ical_events.types.Time#
The end time.
- property extend_query_span_by: tuple[datetime.timedelta, datetime.timedelta]#
Calculate how much we extend the query span.
If an event is long, we need to extend the query span by the event’s duration. If an event has moved, we need to make sure that that is included, too.
This is so that the RECURRENCE-ID falls within the modified span. Imagine if the span is exactly a second. How much would we need to query forward and backward to capture the recurrence id?
Returns two positive spans: (subtract_from_start, add_to_stop)
- is_in_span(span_start, span_stop)[source]#
Return whether the component is in the span.
- Return type:
- property move_recurrences_by: datetime.timedelta#
Occurrences of this component should be moved by this amount.
Usually, the occurrence starts at the new start time. However, if we have a RANGE=THISANDFUTURE, we need to move the occurrence.
RFC 5545:
When the given recurrence instance is rescheduled, all subsequent instances are also rescheduled by the same time difference. For instance, if the given recurrence instance is rescheduled to start 2 hours later, then all subsequent instances are also rescheduled 2 hours later. Similarly, if the duration of the given recurrence instance is modified, then all subsequence instances are also modified to have this same duration.
- abstract property raw_end#
Return the start property of the component.
- abstract property raw_start#
Return the start property of the component.
- property rdates: list[TypeAliasForwardRef('recurring_ical_events.types.Time'), tuple[TypeAliasForwardRef('recurring_ical_events.types.Time'), TypeAliasForwardRef('recurring_ical_events.types.Time')]]#
A list of rdates, possibly a period.
- property recurrence_ids: recurring_ical_events.types.RecurrenceIDs#
The recurrence ids of the component that might be used to identify it.
- property sequence: int#
The sequence in the history of modification.
The sequence is negative if none was found.
- property span#
Return (start, end).
- property start: recurring_ical_events.types.Time#
The start time.
- property uid: recurring_ical_events.types.UID#
The UID of a component.
UID is required by RFC5545. If the UID is absent, we use the Python ID.
- class recurring_ical_events.ComponentsWithName(name, adapter=None, series=Series, occurrence=Occurrence)[source]#
Bases:
SelectComponentsThis is a component collecttion strategy.
Components can be collected in different ways. This class allows extension of the functionality by - subclassing to filter the resulting components - composition to combine collection behavior (see AllKnownComponents)
- class recurring_ical_events.EventAdapter(component)[source]#
Bases:
ComponentAdapterAn icalendar event adapter.
- property raw_end: recurring_ical_events.types.Time#
Yield DTEND or calculate the end of the event based on DTSTART and DURATION.
- property raw_start: recurring_ical_events.types.Time#
Return DTSTART
- exception recurring_ical_events.InvalidCalendar(message)[source]#
Bases:
ValueErrorException thrown for bad icalendar content.
- class recurring_ical_events.JournalAdapter(component)[source]#
Bases:
ComponentAdapterApdater for journal entries.
- class recurring_ical_events.Occurrence(adapter, start=None, end=None, sequence=-1)[source]#
Bases:
objectA repetition of an event.
- as_component(keep_recurrence_attributes)[source]#
Create a shallow copy of the source component and modify some attributes.
- Return type:
icalendar.cal.Component
- property id: recurring_ical_events.occurrence.OccurrenceID#
The id of the component.
- is_in_span(span_start, span_stop)[source]#
Return whether the component is in the span.
- Return type:
- property recurrence_ids: recurring_ical_events.types.RecurrenceIDs#
The recurrence ids.
- exception recurring_ical_events.PeriodEndBeforeStart(message, start, end)[source]#
Bases:
InvalidCalendarAn event or component starts before it ends.
- class recurring_ical_events.SelectComponents[source]#
Bases:
ABCAbstract class to select components from a calendar.
- class recurring_ical_events.Series(components)[source]#
Bases:
objectBase class for components that result in a series of occurrences.
- class RecurrenceRules(core)[source]#
Bases:
objectA strategy if we have an actual core with recurrences.
- as_occurrence(start, stop, occurrence, core)[source]#
Return this as an occurrence at a specific time.
- Return type:
- property components: list[ComponentAdapter]#
The components in this recurrence calculation.
- convert_to_original_type(date)[source]#
Convert a date back if this is possible.
Dates may get converted to datetimes to make calculations possible. This reverts the process where possible so that Repetitions end up with the type (date/datetime) that was specified in the icalendar component.
- create_rule_with_start(rule_string)[source]#
Helper to create an rrule from a rule_string
The rrule is starting at the start of the component. Since the creation is a bit more complex, this function handles special cases.
- Return type:
- property extend_query_span_by: tuple[datetime.timedelta, datetime.timedelta]#
The extension of the time span we need for this component’s core.
- make_all_dates_comparable()[source]#
Make sure we can use all dates with eachother.
Dates may be mixed and we have many of them. - date - datetime without timezone - datetime with timezone These three are not comparable but can be converted.
- between(span_start, span_stop)[source]#
Components between the start (inclusive) and end (exclusive).
The result does not need to be ordered.
- Return type:
- property components: list[ComponentAdapter]#
All the components in this sequence.
Components with the same UID might not occur if the SEQUENCE number suggests that they are obsolete.
- compute_span_extension()[source]#
Compute how much to extend the span for the rrule to cover all events.
- get_component_for_recurrence_id(recurrence_id)[source]#
Get the component which contains all information for the recurrence id.
This concerns this modifications that have RANGE=THISANDFUTURE set.
- Return type:
- has_recurrence_id_in_rrule(modification)[source]#
Wether this occurrence ID is part of the RRULE.
- Return type:
- rrule_between(span_start, span_stop)[source]#
Modify the rrule generation span and yield recurrences.
- skip_core_modification(modification)[source]#
Wether to skip this occurrence.
See Issues: - niccokunzmann/python-recurring-ical-events#253 - niccokunzmann/python-recurring-ical-events#148 - niccokunzmann/python-recurring-ical-events#164
- Return type:
- property this_and_future_components: Generator[ComponentAdapter, None, None]#
All components that influence future events.
- property uid#
The UID that identifies this series.
- class recurring_ical_events.TodoAdapter(component)[source]#
Bases:
ComponentAdapterUnified access to TODOs.
- recurring_ical_events.example_calendar(name='')[source]#
Return an example calendar.
- Parameters:
name (str) – The name of the example file.
- Returns:
The parsed calendar example.
- Return type:
icalendar.cal.Calendar
Type annotations.
- class recurring_ical_events.OccurrenceID(name: str, uid: UID, recurrence_id: Time | None, start: Time)[source]#
The ID of a component’s occurrence to identify it clearly.
- name#
The name of the component, e.g. “VEVENT”
- uid#
The UID of the component.
- recurrence_id#
The Recurrence-ID of the component in UTC but without tzinfo.
- start#
The start of the component
- classmethod from_string(string_id)[source]#
Parse a string and return the component id.
- Return type:
recurring_ical_events.occurrence.OccurrenceID