icalendar.cal.lazy module#

Components for lazy parsing of components.

class icalendar.cal.lazy.InitialSubcomponentsStrategy[source]#

Bases: object

Initial strategy for the calendar.

No subcomponents.

set_components(components)[source]#
Return type:

LazySubcomponentsStrategy

class icalendar.cal.lazy.LazyCalendar(*args, **kwargs)[source]#

Bases: Calendar

A calendar that can handle big files.

Subcomponents of this calendar are evaluated lazily, meaning that they are not parsed until they are accessed. This allows the calendar to handle large files without consuming too much memory or time.

All properties of the calendar component are parsed immediately. Subcomponents and their properties are parsed lazily.

Examples

By accessing the events of the calendar, only Event and Timezone are immediately parsed.

>>> from icalendar import LazyCalendar
>>> calendar = LazyCalendar.example("issue_1050_all_components")
>>> len(calendar.events) == 1
True

The calendar's subcomponents were not parsed because they were not accessed. The calendar is still lazy.

>>> calendar.is_lazy()
True

When you access all subcomponents of the calendar, for example by getting their count, the entire calendar is parsed and becomes not lazy.

>>> len(calendar.subcomponents)
5
>>> calendar.is_lazy()
False

Initialize the calendar.

add_component(component)[source]#

Add a component to the calendar.

Use this instead of appending to subcomponents, as the latter does not parse the whole calendar.

Return type:

None

is_lazy()[source]#

Whether the subcomponents will be parsed lazily.

Note

If you believe that the calendar parses more than it should, please open an issue.

Return type:

bool

Returns:

True if subcomponents are deferred and not yet parsed. False if all subcomponents have been parsed.

property subcomponents: list[Component]#

The subcomponents of the calendar.

Parse all subcomponents of the calendar and return them as a list.

You can manipulate this list or set it. It has the same behavior as in Calendar.

with_uid(uid)[source]#

Return a list of components with the given UID.

Parameters:

uid (str) – The UID of the component.

Returns:

List of components with the given UID.

Return type:

list[Component]

class icalendar.cal.lazy.LazySubcomponentsStrategy[source]#

Bases: object

Parse subcomponents only when accessed.

add_component(component)[source]#

Add a component to the calendar.

Return type:

LazySubcomponentsStrategy

property as_parsed: ParsedSubcomponentsStrategy#

Return the parsed components.

get_all_components()[source]#

Get the subcomponents of the calendar.

Parse all subcomponents.

Return type:

tuple[ParsedSubcomponentsStrategy, list[Component]]

initial_components_to_parse: tuple[str, ...] = ('VTIMEZONE',)#

Parse these subcomponents before any others.

is_lazy()[source]#

Return whether the subcomponents may be lazily parsed.

Return type:

bool

parse_initial_components()[source]#

Parse the components that are required by other components.

This mainly concerns the timezone components. They are required by other components that have a TZID parameter.

Return type:

None

set_components(components)[source]#

Set the subcomponents of the calendar.

Return type:

ParsedSubcomponentsStrategy

walk(name)[source]#

Get the subcomponents of the calendar with the given name.

Parse only the minimal number of subcomponents.

Return type:

tuple[LazySubcomponentsStrategy, list[Component]]

with_uid(uid)[source]#

Get the subcomponents of the calendar with the given uid.

Parse only the minimal number of subcomponents.

Return type:

tuple[LazySubcomponentsStrategy, list[Component]]

class icalendar.cal.lazy.ParsedSubcomponentsStrategy[source]#

Bases: object

All the subcomponents are parsed and available as a list.

add_component(component)[source]#

Add a component to the calendar.

Return type:

ParsedSubcomponentsStrategy

get_all_components()[source]#

Get the subcomponents of the calendar.

Return type:

tuple[ParsedSubcomponentsStrategy, list[Component]]

is_lazy()[source]#

Returns False because subcomponents are not lazily parsed.

Return type:

Literal[False]

set_components(components)[source]#

Set the subcomponents of the calendar.

Return type:

ParsedSubcomponentsStrategy

walk(name)[source]#

Get the subcomponents of the calendar with the given name.

Return type:

tuple[ParsedSubcomponentsStrategy, list[Component]]

with_uid(name)[source]#

Get the subcomponents of the calendar with the given uid.

Return type:

tuple[ParsedSubcomponentsStrategy, list[Component]]