icalendar.param module#

Parameter access for icalendar.

Related:

icalendar.param.boolean_parameter(name, default, doc)[source]#
Return type:

property

icalendar.param.quoted_list_parameter(name, doc)[source]#

Return a parameter that contains a quoted list.

Return type:

property

icalendar.param.string_parameter(name, doc, default=<function _default_return_none>, convert=None, convert_to=None)[source]#

Create a property for a string parameter with optional conversion.

This helper function is used to define properties that read from and write to self.params while optionally converting values between their stored string representation and a more convenient Python type.

Parameters:
  • name (str) – Name of the parameter in the params dictionary.

  • doc (str) – Documentation for the property.

  • default (Callable) – Function that returns a default value if the parameter is not found.

  • convert (Callable[[str], TypeVar(T)] | None) – Function that converts the stored string value to the desired type.

  • convert_to (Callable[[TypeVar(T)], str] | None) – Function to convert a value back to a string for storage.

Return type:

property

Returns:

A property object with a getter, setter, and deleter for the parameter.

Example

Define a parameter that is stored as a string but used as an integer:

>>> from icalendar.param import string_parameter
>>> class Dummy:
...     def __init__(self):
...         self.params = {}
...
>>> Dummy.priority = string_parameter(
...     "PRIORITY",
...     "Priority of the component",
...     default=lambda: 0,
...     convert=int,
...     convert_to=str,
... )
>>> obj = Dummy()

Accessing the property converts the stored string value to the type specified by the convert parameter, in this case, an int.

>>> obj.priority = "5"
>>> obj.priority
5

Setting the property stores the new value.

>>> obj.priority = 10
>>> obj.priority
10