Skip to main content

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

Project description

calgebra 🗓️

A tiny DSL for merging and searching over calendar-like intervals.

Installation

pip install calgebra

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

Quick Start

from calgebra import day_of_week, time_of_day, hours, at_tz, HOUR

# Compose time windows
weekdays = day_of_week(["monday", "tuesday", "wednesday", "thursday", "friday"])
work_hours = time_of_day(start=9*HOUR, duration=8*HOUR, tz="US/Pacific")
business_hours = weekdays & work_hours

# Find free time
busy = monday_meetings | friday_focus
free = business_hours - busy
long_slots = free & (hours >= 2)

# Query results
at = at_tz("US/Pacific")
meeting_options = list(long_slots[at("2025-01-01"):at("2025-02-01")])

Intervals use exclusive end bounds ([start, end)), matching Python slicing. Interval(start=10, end=13) represents 3 seconds. Intervals are automatically clipped to query bounds.

Core Features:

  • Set operations: | (union), & (intersection), - (difference), ~ (complement)
  • Recurring patterns: recurring(), day_of_week(), time_of_day() (RFC 5545 via python-dateutil)
  • Aggregations: total_duration, max_duration, min_duration, count_intervals, coverage_ratio
  • Transformations: buffer() (add time around intervals), merge_within() (coalesce nearby intervals)
  • Google Calendar: calgebra.gcsa.calendars() for read/write operations

Tutorial | API Reference | Google Calendar Guide

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.7.0.tar.gz (72.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.7.0-py3-none-any.whl (60.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: calgebra-0.7.0.tar.gz
  • Upload date:
  • Size: 72.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.7.0.tar.gz
Algorithm Hash digest
SHA256 6bb6c722cdcacfe19c0b62054cb61c9bc834d728f5db8ccbf2f05f1a0a0d2a01
MD5 c34f2c7f83008df149c150970a3667b6
BLAKE2b-256 c6ed188bd14ac2c34141430ff2af82c8be67e2633a4008f9731ab8be47b58b2b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: calgebra-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 60.6 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.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de92310b740a733c8205e5b1e5a8dbe74f8a0e768775fa988f17c1a03d17d7d1
MD5 be1ee5e0f058df20dcb1aabdc4c2f941
BLAKE2b-256 d5777d5952b6c8b2548ed16753e2dcf0c82586315b2e6e65489b10cb35fc51d4

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