On this page
calendar.HTMLCalendar
Prev: calendar.firstweekday | Up: calendar | Next: calendar.IllegalMonthError
Rel: calendar.calendar, calendar.Calendar, calendar.Day, calendar.firstweekday
Ref: docs.python.org — calendar.HTMLCalendar
Tags: #public #python3 #stdlib #calendar
Import
import calendar
from calendar import HTMLCalendar
Signature & Overview
calendar.HTMLCalendar(firstweekday=0)
This calendar returns complete HTML pages.
Methods & Attributes
HTMLCalendar.firstweekday(...)—HTMLCalendar.firstweekdaymethod/property.HTMLCalendar.formatday(self, day, weekday)— Return a day as a table cell.HTMLCalendar.formatmonth(self, theyear, themonth, withyear=True)— Return a formatted month as a table.HTMLCalendar.formatmonthname(self, theyear, themonth, withyear=True)— Return a month name as a table row.HTMLCalendar.formatweek(self, theweek)— Return a complete week as a table row.HTMLCalendar.formatweekday(self, day)— Return a weekday name as a table header.HTMLCalendar.formatweekheader(self)— Return a header for a week as a table row.HTMLCalendar.formatyear(self, theyear, width=3)— Return a formatted year as a table of tables.HTMLCalendar.formatyearpage(self, theyear, width=3, css='calendar.css', encoding=None)— Return a formatted year as a complete HTML page.HTMLCalendar.getfirstweekday(self)—HTMLCalendar.getfirstweekdaymethod/property.HTMLCalendar.itermonthdates(self, year, month)— Return an iterator for one month. The iterator will yield datetime.date values and will always iterate through complete weeks, so it will yield dates outside the specified month.HTMLCalendar.itermonthdays(self, year, month)— Like itermonthdates(), but will yield day numbers. For days outside the specified month the day number is 0.HTMLCalendar.itermonthdays2(self, year, month)— Like itermonthdates(), but will yield (day number, weekday number) tuples. For days outside the specified month the day number is 0.HTMLCalendar.itermonthdays3(self, year, month)— Like itermonthdates(), but will yield (year, month, day) tuples. Can be used for dates outside of datetime.date range.HTMLCalendar.itermonthdays4(self, year, month)— Like itermonthdates(), but will yield (year, month, day, day_of_week) tuples.HTMLCalendar.iterweekdays(self)— Return an iterator for one week of weekday numbers starting with the configured first one.HTMLCalendar.monthdatescalendar(self, year, month)— Return a matrix (list of lists) representing a month's calendar.HTMLCalendar.monthdays2calendar(self, year, month)— Return a matrix representing a month's calendar.HTMLCalendar.monthdayscalendar(self, year, month)— Return a matrix representing a month's calendar.HTMLCalendar.setfirstweekday(self, firstweekday)—HTMLCalendar.setfirstweekdaymethod/property.HTMLCalendar.yeardatescalendar(self, year, width=3)— Return the data for the specified year ready for formatting. The return value is a list of month rows. Each month row contains up to width months.HTMLCalendar.yeardays2calendar(self, year, width=3)— Return the data for the specified year ready for formatting (similar to yeardatescalendar()). Entries in the week lists are (day number, weekday number) tuples. Day numbers outside this month areHTMLCalendar.yeardayscalendar(self, year, width=3)— Return the data for the specified year ready for formatting (similar to yeardatescalendar()). Entries in the week lists are day numbers.
Usage
import calendar
html = calendar.HTMLCalendar().formatmonth(2026, 12)
assert "<table" in html and "December 2026" in html
Gotchas
- Returns an HTML
<table>snippet with CSS classes (mon,tue,noday) ready for styling.
REPL Inspect
from calendar import HTMLCalendar
help(HTMLCalendar)
Linked from
Related notes
- tuts/python3/stdlib_module/calendar/calendar Linked here; links to this page; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/Calendar_class Linked here; links to this page; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/Day Linked here; links to this page; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/firstweekday Linked here; links to this page; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/IllegalMonthError Linked here; links to this page; shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/calendar/IllegalWeekdayError shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/isleap shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/leapdays shared tags: #calendar, #stdlib
- tuts/python3/stdlib_module/calendar/LocaleHTMLCalendar shared tags: #calendar, #stdlib