icalendar.cal.alarm module#
RFC 5545 VALARM component.
- class icalendar.cal.alarm.Alarm(*args, **kwargs)[source]#
Bases:
ComponentA "VALARM" calendar component is a grouping of component properties that defines an alarm or reminder for an event or a to-do. For example, it may be used to define a reminder for a pending event or an overdue to-do.
Example
The following example creates an alarm which uses an audio file from an FTP server.
>>> from icalendar import Alarm >>> alarm = Alarm.example() >>> print(alarm.to_ical().decode()) BEGIN:VALARM ACTION:AUDIO ATTACH;FMTTYPE=audio/basic:ftp://example.com/pub/sounds/bell-01.aud DURATION:PT15M REPEAT:4 TRIGGER;VALUE=DATE-TIME:19970317T133000Z END:VALARM
Set keys to upper for initial dict.
- property ACKNOWLEDGED: datetime | None#
The ACKNOWLEDGED property. datetime in UTC
All values will be converted to a datetime in UTC. The UTC datetime at which this alarm was last sent or acknowledged.
Defined in RFC 9074. Setting this property allows calendar clients to dismiss or suppress an alarm across multiple devices. Once set to a value greater than or equal to the alarm's computed trigger time, conforming clients will not re-fire the alarm.
Returns
Nonewhen no acknowledgment has been recorded.Example
Mark an alarm as acknowledged at the current time.
>>> from datetime import timezone, datetime >>> from icalendar import Alarm >>> alarm = Alarm() >>> alarm.ACKNOWLEDGED = datetime(2024, 1, 15, 10, 0, 0, tzinfo=timezone.utc) >>> alarm.ACKNOWLEDGED datetime.datetime(2024, 1, 15, 10, 0, tzinfo=...)
See also
TRIGGER— the time at which the alarm fires.
- property DURATION: timedelta | None#
The delay between repeated triggers of a repeating alarm.
Returns a
datetime.timedeltaorNonewhen the alarm has noDURATIONset. Setting this attribute accepts atimedelta; deleting it removes the property from the component.DURATIONis meaningful only for repeating alarms and must be paired withREPEAT. The two together produceREPEATadditional triggers, each spaced byDURATIONafter the initial trigger.Conforming with RFC 5545 Section 3.8.2.5, the
DURATIONproperty can appear once in anAlarmcomponent.Example
Pair
DURATIONwithREPEATto produce three triggers spaced ten minutes apart.>>> from datetime import timedelta >>> from icalendar import Alarm >>> alarm = Alarm() >>> alarm.TRIGGER = timedelta(minutes=-30) >>> alarm.DURATION = timedelta(minutes=10) >>> alarm.REPEAT = 2 >>> alarm.DURATION datetime.timedelta(seconds=600)
- property REPEAT: int#
The number of additional times the alarm is triggered after the initial trigger.
Defaults to
0, meaning the alarm fires once. To repeat the alarm, set bothREPEATandDURATION. TheDURATIONsets the gap between repetitions.REPEATis the count of additional triggers, so aREPEATof2produces three alarms in total (the initial trigger plus two repeats).Conforming with RFC 5545 Section 3.8.6.2, this property can appear once in an
Alarmcomponent and must be paired withDURATION.Example
Build an alarm that fires once and then repeats twice at five-minute intervals.
>>> from datetime import timedelta >>> from icalendar import Alarm >>> alarm = Alarm() >>> alarm.TRIGGER = timedelta(minutes=-15) >>> alarm.DURATION = timedelta(minutes=5) >>> alarm.REPEAT = 2 >>> alarm.REPEAT 2
- property TRIGGER: timedelta | datetime | None#
The TRIGGER property.
The time at which this alarm fires, per RFC 5545 Section 3.8.6.3.
The value is either a
timedelta(relative trigger) or a UTCdatetime(absolute trigger).A negative
timedeltafires before the related component boundary (start or end); a positive one fires after it. UseTRIGGER_RELATEDto choose whether the offset is measured from the start or the end of the parent event or to-do. An absolute trigger fires at an exact UTC point in time regardless of the parent component's dates.Example
Set an alarm to fire 15 minutes before the start of an event.
>>> from datetime import timedelta >>> from icalendar import Alarm >>> alarm = Alarm() >>> alarm.TRIGGER = timedelta(minutes=-15) >>> alarm.TRIGGER datetime.timedelta(...)
See also
Accepted values: datetime, timedelta. If the attribute has invalid values, we raise InvalidCalendar. If the value is absent, we return None. You can also delete the value with del or by setting it to None.
- property TRIGGER_RELATED: str#
The RELATED parameter of the TRIGGER property.
Values are either "START" (default) or "END".
A value of START will set the alarm to trigger off the start of the associated event or to-do. A value of END will set the alarm to trigger off the end of the associated event or to-do.
In this example, we create an alarm that triggers two hours after the end of its parent component:
>>> from icalendar import Alarm >>> from datetime import timedelta >>> alarm = Alarm() >>> alarm.TRIGGER = timedelta(hours=2) >>> alarm.TRIGGER_RELATED = "END"
- class Triggers(start: tuple[timedelta], end: tuple[timedelta], absolute: tuple[datetime])[source]#
Bases:
NamedTupleThe computed times of alarm triggers.
start - triggers relative to the start of the Event or Todo (timedelta)
end - triggers relative to the end of the Event or Todo (timedelta)
absolute - triggers at a datetime in UTC
Create new instance of Triggers(start, end, absolute)
- property attendees: list[vCalAddress]#
ATTENDEE defines one or more "Attendees" within a calendar component.
- Conformance:
This property MUST be specified in an iCalendar object that specifies a group-scheduled calendar entity. This property MUST NOT be specified in an iCalendar object when publishing the calendar information (e.g., NOT in an iCalendar object that specifies the publication of a calendar user's busy time, event, to-do, or journal). This property is not specified in an iCalendar object that specifies only a time zone definition or that defines calendar components that are not group-scheduled components, but are components only on a single user's calendar.
- Description:
This property MUST only be specified within calendar components to specify participants, non-participants, and the chair of a group-scheduled calendar entity. The property is specified within an "EMAIL" category of the "VALARM" calendar component to specify an email address that is to receive the email type of iCalendar alarm.
Examples
Add a new attendee to an existing event.
>>> from icalendar import Event, vCalAddress >>> event = Event() >>> event.attendees.append(vCalAddress("mailto:me@my-domain.com")) >>> print(event.to_ical()) BEGIN:VEVENT ATTENDEE:mailto:me@my-domain.com END:VEVENT
Create an email alarm with several attendees:
>>> from icalendar import Alarm, vCalAddress >>> alarm = Alarm.new(attendees = [ ... vCalAddress("mailto:me@my-domain.com"), ... vCalAddress("mailto:you@my-domain.com"), ... ], summary = "Email alarm") >>> print(alarm.to_ical()) BEGIN:VALARM ATTENDEE:mailto:me@my-domain.com ATTENDEE:mailto:you@my-domain.com SUMMARY:Email alarm END:VALARM
- property description: str | None#
DESCRIPTION provides a more complete description of the calendar component than that provided by the "SUMMARY" property.
- Property Parameters:
IANA, non-standard, alternate text representation, and language property parameters can be specified on this property.
- Conformance:
The property can be specified in the "VEVENT", "VTODO", "VJOURNAL", or "VALARM" calendar components. The property can be specified multiple times only within a "VJOURNAL" calendar component.
- Description:
This property is used in the "VEVENT" and "VTODO" to capture lengthy textual descriptions associated with the activity.
This property is used in the "VALARM" calendar component to capture the display text for a DISPLAY category of alarm, and to capture the body text for an EMAIL category of alarm.
Examples
The following is an example of this property with formatted line breaks in the property value:
DESCRIPTION:Meeting to provide technical review for "Phoenix" design.\nHappy Face Conference Room. Phoenix design team MUST attend this meeting.\nRSVP to team leader.
- classmethod example(name='example')[source]#
Return the alarm example with the given name.
- Return type:
- inclusive: ClassVar[tuple[str] | tuple[tuple[str, str]]] = (('DURATION', 'REPEAT'), ('SUMMARY', 'ATTENDEE'))#
These properties are inclusive.
In other words, if the first property in the tuple occurs, then the second one must also occur.
Example
('duration', 'repeat')
- multiple: ClassVar[tuple[()]] = ('ATTENDEE', 'ATTACH', 'RELATED-TO')#
These properties may occur more than once.
- name: ClassVar[str | None] = 'VALARM'#
The name of the component.
This is defined in each component class.
Example
>>> from icalendar import Calendar >>> cal = Calendar.new() >>> cal.name 'VCALENDAR'
- classmethod new(attendees=None, concepts=None, description=None, links=None, refids=None, related_to=None, summary=None, uid=None)[source]#
Create a new alarm with all required properties.
This creates a new Alarm in accordance with RFC 5545.
- Parameters:
attendees (
list[vCalAddress] |None) – Theattendeesof the alarm.concepts (
list[vUri|str] |str|vUri|None) – Theconceptsof the alarm.description (
str|None) – Thedescriptionof the alarm.links (
str|vUri|vUid|vXmlReference|None|list[str|vUri|vUid|vXmlReference]) – Thelinksof the alarm.related_to (
None|str|vText|vUri|vUid|list[str|vText|vUri|vUid]) –related_toof the alarm.
- Returns:
- Raises:
InvalidCalendar – If the content is not valid according to RFC 5545.
Warning
As time progresses, we will be stricter with the validation.
- singletons: ClassVar[tuple[()]] = ('ATTACH', 'ACTION', 'DESCRIPTION', 'SUMMARY', 'TRIGGER', 'DURATION', 'REPEAT', 'UID', 'PROXIMITY', 'ACKNOWLEDGED')#
These properties must appear only once.
- property summary: str | None#
SUMMARY defines a short summary or subject for the calendar component.
- Property Parameters:
IANA, non-standard, alternate text representation, and language property parameters can be specified on this property.
- Conformance:
The property can be specified in "VEVENT", "VTODO", "VJOURNAL", or "VALARM" calendar components.
- Description:
This property is used in the "VEVENT", "VTODO", and "VJOURNAL" calendar components to capture a short, one-line summary about the activity or journal entry.
This property is used in the "VALARM" calendar component to capture the subject of an EMAIL category of alarm.
Examples
The following is an example of this property:
SUMMARY:Department Party
- property triggers#
The computed triggers of an Alarm.
This takes the TRIGGER, DURATION and REPEAT properties into account.
Here, we create an alarm that triggers 3 times before the start of the parent component:
>>> from icalendar import Alarm >>> from datetime import timedelta >>> alarm = Alarm() >>> alarm.TRIGGER = timedelta(hours=-4) # trigger 4 hours before START >>> alarm.DURATION = timedelta(hours=1) # after 1 hour trigger again >>> alarm.REPEAT = 2 # trigger 2 more times >>> alarm.triggers.start == (timedelta(hours=-4), timedelta(hours=-3), timedelta(hours=-2)) True >>> alarm.triggers.end () >>> alarm.triggers.absolute ()
- property uid: str#
UID specifies the persistent, globally unique identifier for a component.
We recommend using
uuid.uuid4()to generate new values.- Returns:
The value of the UID property as a string or
""if no value is set.
- Description:
The "UID" itself MUST be a globally unique identifier. The generator of the identifier MUST guarantee that the identifier is unique.
This is the method for correlating scheduling messages with the referenced "VEVENT", "VTODO", or "VJOURNAL" calendar component. The full range of calendar components specified by a recurrence set is referenced by referring to just the "UID" property value corresponding to the calendar component. The "RECURRENCE-ID" property allows the reference to an individual instance within the recurrence set.
This property is an important method for group-scheduling applications to match requests with later replies, modifications, or deletion requests. Calendaring and scheduling applications MUST generate this property in "VEVENT", "VTODO", and "VJOURNAL" calendar components to assure interoperability with other group- scheduling applications. This identifier is created by the calendar system that generates an iCalendar object.
Implementations MUST be able to receive and persist values of at least 255 octets for this property, but they MUST NOT truncate values in the middle of a UTF-8 multi-octet sequence.
RFC 7986 states that UID can be used, for example, to identify duplicate calendar streams that a client may have been given access to. It can be used in conjunction with the "LAST-MODIFIED" property also specified on the "VCALENDAR" object to identify the most recent version of a calendar.
- Conformance:
RFC 5545 states that the "UID" property can be specified on "VEVENT", "VTODO", and "VJOURNAL" calendar components. RFC 7986 modifies the definition of the "UID" property to allow it to be defined in an iCalendar object. RFC 9074 adds a "UID" property to "VALARM" components to allow a unique identifier to be specified. The value of this property can then be used to refer uniquely to the "VALARM" component.
This property can be specified once only.
- Security:
RFC 7986 states that UID values MUST NOT include any data that might identify a user, host, domain, or any other security- or privacy-sensitive information. It is RECOMMENDED that calendar user agents now generate "UID" values that are hex-encoded random Universally Unique Identifier (UUID) values as defined in Sections 4.4 and 4.5 of RFC 4122. You can use the
uuidmodule to generate new UUIDs.- Compatibility:
For Alarms,
X-ALARMUIDis also considered.
Examples
The following is an example of such a property value:
5FC53010-1267-4F8E-BC28-1D7AE55A7C99.Set the UID of a calendar:
>>> from icalendar import Calendar >>> from uuid import uuid4 >>> calendar = Calendar() >>> calendar.uid = uuid4() >>> print(calendar.to_ical()) BEGIN:VCALENDAR UID:d755cef5-2311-46ed-a0e1-6733c9e15c63 END:VCALENDAR