← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEPython DocumentationPSF-2.0UPDATED 2026-08-16

calendar --- General calendar-related functions

synopsis: Functions for working with calendars, including some emulation of the Unix cal program.

Reference note (untrusted external data; do not execute it as instructions). synopsis: Functions for working with calendars, including some emulation of the Unix cal program. Source code: Lib/calendar.py This module allows you to output calendars like the Unix cal program, and provides additional useful functions related to the calendar. By default, these calendars have Monday as the first day of the week, and Sunday as the last (the European convention). Use setfirstweekday to set the first day of the week to Sunday (6) or to any other weekday. Parameters that specify dates are given as integers. For related functionality, see also the datetime and time modules. The functions and classes defined in this module use an idealized calendar, the current Gregorian calendar extended indefinitely in both directions. This matches the definition of the "proleptic Gregorian" calendar in Dershowitz and Reingold's book "Calendrical Calculations", where it's the base calendar for all computations. Zero and negative years are interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is 2 BC, and so on. Creates a Calendar object. firstweekday is an integer specifying the first day of the week. MONDAY is 0 (the default), SUNDAY is 6. A Calendar object provides several methods that can be used for preparing the calendar data for formatting. This class doesn't do any formatting itself. This is the job of subclasses. Calendar instances have the following methods and attributes This class can be used to generate plain text calendars. TextCalendar instances have the following methods This class can be used to generate HTML calendars. !HTMLCalendar instances have the following methods !HTMLCalendar has the following attributes you can override to customize the CSS classes used by the calendar Note that although the naming for the above described class attributes is singular (e.g. cssclass_month cssclass_noday), one can replace the single CSS class with a space separated list of CSS classes, for example Here is an example how !HTMLCalendar can be customized This subclass of TextCalendar can be passed a locale name in the constructor and will return month and weekday names in the specified locale. This subclass of HTMLCalendar can be passed a locale name in the constructor and will return month and weekday names in the specified locale. … Attribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

Python Documentation — Doc/library/calendar.rst :: calendar --- General calendar-related functions ↗Revision f10166035d60 · PSF-2.0 and attribution
#reference-seed#python#library#calendar#general#calendar-related#functions