icalendar.cal.lazy module#
Components for lazy parsing of components.
- class icalendar.cal.lazy.InitialSubcomponentsStrategy[source]#
Bases:
objectInitial strategy for the calendar.
No subcomponents.
- class icalendar.cal.lazy.LazyCalendar(*args, **kwargs)[source]#
Bases:
CalendarA 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
eventsof the calendar, onlyEventandTimezoneare 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
subcomponentsof 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:
- 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:
- Returns:
Trueif subcomponents are deferred and not yet parsed.Falseif all subcomponents have been parsed.
- class icalendar.cal.lazy.LazySubcomponentsStrategy[source]#
Bases:
objectParse subcomponents only when accessed.
- property as_parsed: ParsedSubcomponentsStrategy#
Return the parsed components.
- get_all_components()[source]#
Get the subcomponents of the calendar.
Parse all subcomponents.
- Return type:
- initial_components_to_parse: tuple[str, ...] = ('VTIMEZONE',)#
Parse these subcomponents before any others.
- 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:
- class icalendar.cal.lazy.ParsedSubcomponentsStrategy[source]#
Bases:
objectAll the subcomponents are parsed and available as a list.
- is_lazy()[source]#
Returns
Falsebecause subcomponents are not lazily parsed.- Return type:
Literal[False]