Skip to content

ics ​

The ics module arrives in Basthon's Python kernel: it writes and reads calendars in the iCalendar format, the .ics files that every calendar understands (the phone's, the school's digital workspace, Thunderbird, Google Calendar…). A way to generate the schedule of a project or of a course, then import it into your calendar in a single click.

python
import basthon
from ics import Calendar, Event

lessons = [
    ("2026-11-02", "Recursion"),
    ("2026-11-09", "Binary trees"),
    ("2026-11-16", "Graphs"),
]

calendar = Calendar()
for day, topic in lessons:
    calendar.events.add(Event(
        name=f"CS: {topic}",
        begin=f"{day}T08:00:00+01:00",
        duration={"hours": 2},
        location="Room B12",
    ))

with open("cs.ics", "w") as file:
    file.write(calendar.serialize())
basthon.download("cs.ics")

# and the other way round: reading a calendar back
with open("cs.ics") as file:
    read = Calendar(file.read())
for lesson in sorted(read.events):
    print(lesson.begin.to("Europe/Paris").format("DD/MM at HH:mm"), lesson.name)

basthon.download offers to save the file on the computer, ready to be imported. The reverse works too: drop the calendar exported from a diary into Basthon, then count the teaching hours or look for the next free slot.

Play with it!