Set algebra for calendars. Compose lazily and query efficiently.
pip install calgebra # Or with Google Calendar support pip install calgebra[google-calendar] # Or with iCalendar (.ics) file support pip install calgebra[ical]
from calgebra import day_of_week, time_of_day, at_tz, pprint, hours, HOUR from itertools import islice tz = "US/Pacific" at = at_tz(tz) # Team calendars alice, bob, charlie = ... # Timeline objects (Google Calendar, .ics files, etc.) # Define when work happens weekend = day_of_week(["saturday", "sunday"], tz=tz) weekdays = ~weekend workhours = time_of_day(start=9*HOUR, duration=8*HOUR, tz=tz) business_hours = weekdays & workhours # When is anyone busy? team_busy = alice | bob | charlie # Free slots: business hours minus busy, at least 2 hours free_slots = (business_hours - team_busy) & (hours >= 2) # Query January 2025 pprint(islice(free_slots[at("2025-01-01"):at("2025-02-01")], 5), tz=tz) # 2025εΉ΄01ζ06ζ₯ 14:00:00 -> 2025εΉ΄01ζ06ζ₯ 17:00:00 # 2025εΉ΄01ζ08ζ₯ 09:00:00 -> 2025εΉ΄01ζ08ζ₯ 12:00:00 # ...
Core Features:
- Set operations:
|(union),&(intersection),-(difference),~(complement) - Lazy composition: Build complex queries, execute with slicing
- Recurring patterns:
day_of_week(),time_of_day(),recurring()(RFC 5545) - Interval filtering:
hours >= 2,summary == "standup", custom properties - Google Calendar: Read/write via
calgebra.gcsa - iCalendar (.ics): Load/save standard RFC 5545 files
β Quick-start | Tutorial | API Reference | Google Calendar | Demo Video
MIT License - see LICENSE file for details.