Skip to main content

Tree-based date filtering utilities

Project description

DateTree

DateTree is a high-level Python utility for managing, filtering, and querying collections of dates stored in a Red Black Tree (RBTree).

It provides a clean, expressive API for adding date ranges, filtering by calendar fields, and performing efficient date queries, while guaranteeing predictable performance and sorted traversal.


Why DateTree?

DateTree is useful when you need to:

  • Store large collections of dates efficiently
  • Perform frequent date-based queries (year, month, day)
  • Filter dates deterministically and in sorted order
  • Enforce constraints like allowed days of the week
  • Avoid ad-hoc list filtering or repeated date generation

Dates are stored as keys in an RBTree, giving strong performance guarantees and deterministic behavior.


Features

  • Store dates in a balanced Red Black Tree
  • Add single dates or inclusive date ranges
  • Delete individual dates or ranges of dates
  • Filter dates by:
    • year
    • month
    • day
    • combinations of the above
  • Include or exclude specific days of the week
  • Efficient range queries
  • Sorted traversal
  • Explicit, exception-driven error handling

Basic Usage

This example demonstrates the most common workflow:
include days of the week, add a date range, and filter results.

from datetime import date
from bintrees import RBTree
from date_tree.date_tree import DateTree

tree = RBTree()
builder = DateTree(tree, date_obj="example")

# Include all days of the week
builder.include_days_of_week(include_all=True)

# Add an inclusive date range
builder.add_dates(date(2025, 1, 1), date(2025, 1, 31))

# Filter dates in January 2025
filtered = builder.filter_dates(month=1, year=2025)

Installation

Install from PyPI:

pip install date-tree

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

date_tree-1.0.2.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

date_tree-1.0.2-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file date_tree-1.0.2.tar.gz.

File metadata

  • Download URL: date_tree-1.0.2.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for date_tree-1.0.2.tar.gz
Algorithm Hash digest
SHA256 25c376d335b4beae1212719096a930362084c5c555149400974920836386b0ec
MD5 9e38126d954aae3175e1cb23cbfccd34
BLAKE2b-256 5a10b5fda29bf95d4910be57aa7e40f2ee26fc260f887d91e8a4a5709e8dbf08

See more details on using hashes here.

File details

Details for the file date_tree-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: date_tree-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for date_tree-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2956c3d14087d22b80de1b632d0e96d313b172d1ac26417832aa1362fbf7b011
MD5 6cf0f1f0f658a95093fa1ef81e04cadc
BLAKE2b-256 4443a7b0d6c515a03a9405127e47edcb0b1fedfd397289615c46569e4150977d

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