Skip to main content

A tiny DSL for calendar interval algebra - compose, filter, and query time ranges using set operations.

Project description

calgebra 🗓️

Set algebra for calendars. Compose lazily and query efficiently.

Installation

pip install calgebra

# Or with Google Calendar support
pip install calgebra[google-calendar]

# Or with iCalendar (.ics) file support
pip install calgebra[ical]

Quick Start

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

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

calgebra-0.10.7.tar.gz (113.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

calgebra-0.10.7-py3-none-any.whl (83.0 kB view details)

Uploaded Python 3

File details

Details for the file calgebra-0.10.7.tar.gz.

File metadata

  • Download URL: calgebra-0.10.7.tar.gz
  • Upload date:
  • Size: 113.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for calgebra-0.10.7.tar.gz
Algorithm Hash digest
SHA256 8453010ee27f7f6443d8b789b32e547746f3e2d1551766972669f130ed1f887a
MD5 0d1acfe93b01b0153f5027f63d61882e
BLAKE2b-256 2edadc2757a6f80b059f10ae8baa15254ba4258c08c3b416e071f1a196ca4c5a

See more details on using hashes here.

File details

Details for the file calgebra-0.10.7-py3-none-any.whl.

File metadata

  • Download URL: calgebra-0.10.7-py3-none-any.whl
  • Upload date:
  • Size: 83.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for calgebra-0.10.7-py3-none-any.whl
Algorithm Hash digest
SHA256 90d0bd3736eef658464ee06d64d80aed7d4b2c96cdcf7f70fd4c2b414d3efd53
MD5 874cda6a74676f18c7e4320a188b1e24
BLAKE2b-256 b57ecad287f22cf8ae2179c80abc8baf4faa9cb8f3bc400c52e18e0ad0a3793e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page