iCalendar Searcher

1.0.5 · active · verified Thu Apr 16

icalendar-searcher is a Python library designed for powerful searching, filtering, and sorting of iCalendar components using a SQL-like Domain Specific Language (DSL). It simplifies interaction with `.ics` data, offering functionalities like expanding recurring events and complex property queries. The current stable version is 1.0.5, with an active development pace characterized by frequent patch and minor releases.

Common errors

Warnings

Install

Imports

Quickstart

Initialize an `IcalendarSearcher` with iCalendar data and use `QueryBuilder` to construct SQL-like filters for searching. The `search()` method returns an iterator of `icalendar.cal.Component` objects.

from icalendar_searcher import IcalendarSearcher, QueryBuilder

ics_data = """
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Example Corp//NONSGML Event Generator//EN
BEGIN:VEVENT
UID:19970610T172345Z-AF23B2@example.com
DTSTAMP:19970610T172345Z
DTSTART:19970714T170000Z
DTEND:19970715T035959Z
SUMMARY:Bastille Day Party
DESCRIPTION:Party to celebrate Bastille Day.
LOCATION:Paris, France
END:VEVENT
BEGIN:VEVENT
UID:19980610T172345Z-AF23C3@example.com
DTSTAMP:19980610T172345Z
DTSTART:19980720T100000Z
DTEND:19980720T110000Z
SUMMARY:Meeting with client
END:VEVENT
END:VCALENDAR
"""

searcher = IcalendarSearcher(ics_data)

# Example 1: Find events starting after a specific date
query_future = QueryBuilder().filter("DTSTART >= 1997-07-15T00:00:00Z").build()
results_future = searcher.search(query_future)
print("\nEvents starting after July 15, 1997:")
for component in results_future:
    print(f"- {component.get('SUMMARY')}")

# Example 2: Filter by property value (case-insensitive summary containing 'party')
query_party = QueryBuilder().filter("SUMMARY ~ 'party'").build()
results_party = searcher.search(query_party)
print("\nEvents with 'party' in summary:")
for component in results_party:
    print(f"- {component.get('SUMMARY')}")

# Example 3: Get all components
all_results = searcher.search()
print("\nAll events:")
for component in all_results:
    print(f"- {component.get('SUMMARY')}")

view raw JSON →