datasette-ics by simonw

98 downloads this week        Star

Screenshot of simonw/datasette-ics

README source code


PyPI Changelog Tests License

Datasette plugin that adds support for generating iCalendar .ics files with the results of a SQL query.


Install this plugin in the same environment as Datasette to enable the .ics output extension.

$ pip install datasette-ics


To create an iCalendar file you need to define a custom SQL query that returns a required set of columns:

  • event_name - the short name for the event
  • event_dtstart - when the event starts

The following columns are optional:

  • event_dtend - when the event ends
  • event_duration - the duration of the event (use instead of dtend)
  • event_description - a longer description of the event
  • event_uid - a globally unique identifier for this event
  • event_tzid - the timezone for the event, e.g. America/Chicago

A query that returns these columns can then be returned as an ics feed by adding the .ics extension.


This SQL query calculates the lowest tide per day at Pillar Point in Half Moon Bay, California.

Since the query returns event_name, event_dtstart and event_tzid columns it produces this ICS feed. If you subscribe to that in a calendar application such as Apple Calendar you get something that looks like this:

Apple Calendar showing low tides at Pillar Point during a week

Using a canned query

Datasette's canned query mechanism can be used to configure calendars. If a canned query definition has a title that will be used as the title of the calendar.

Here's an example, defined using a metadata.yaml file:

        title: My Calendar
        sql: |-
            title as event_name,
            start as event_dtstart,
            description as event_description
          order by

This will result in a calendar feed at http://localhost:8001/mydatabase/calendar.ics