icalendar.cal.component_factory module#

A factory to create components.

class icalendar.cal.component_factory.ComponentFactory(*args, **kwargs)[source]#

Bases: CaselessDict

Registered components from RFC 7953 and RFC 5545.

To get a component, use this class as shown below.

>>> from icalendar import ComponentFactory
>>> factory = ComponentFactory()
>>> event_class = factory.get_component_class('VEVENT')
>>> event_class()
VEVENT({})

If a component class is not yet supported, it can be either created using get_component_class() or added manually as a subclass of Component.

add_component_class(cls)[source]#

Add a component class to the factory.

Parameters:

cls (type[Component]) – The component class to add.

Return type:

None

get_component_class(name)[source]#

Get the component class from the factory.

This also creates and adds the component class if it does not exist.

Parameters:

name (str) – The name of the component, for example, "VCALENDAR".

Return type:

type[Component]

Returns:

The registered component class.