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
from itertools import islice

# 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 (forward)
at = at_tz("US/Pacific")
meeting_options = list(long_slots[at("2025-01-01"):at("2025-02-01")])

# Query in reverse (last 5 events)
last_5 = list(islice(calendar[at("2024-01-01"):at("2025-01-01"):-1], 5))

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)
  • Reverse iteration: timeline[end:start:-1] for reverse chronological order
  • 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

**→ Quick-start | Tutorial | API Reference | Google Calendar

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.8.3.tar.gz (87.9 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.8.3-py3-none-any.whl (68.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for calgebra-0.8.3.tar.gz
Algorithm Hash digest
SHA256 0fa370bd462b5e027390d8adbcdbe65f286f04f203b56ad4a148f9654b6de13e
MD5 0e6ca6c37280d9e99b221868fad18b36
BLAKE2b-256 070722e484795de15f57c45edb437de8f317359654d046fad6fc421e6796a92d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: calgebra-0.8.3-py3-none-any.whl
  • Upload date:
  • Size: 68.9 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.8.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d63cb2834212c3b5b42319de9c9d30b8a59e6e2cf8ea634a7d14f8811de92036
MD5 ff51fddf0a6da07434b11a10fea0b5d8
BLAKE2b-256 bc27f28bbcc96ba933a773fffca213a807c904265420547a76f4c99d7a3f2c06

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