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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file date_tree-1.0.1.tar.gz.
File metadata
- Download URL: date_tree-1.0.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0daa205ed0e3badfd249fabf998bfa2230c3a3d5ffa1570bee448db5ead36bbf
|
|
| MD5 |
bf832e6e87104e479e92b781946aab8a
|
|
| BLAKE2b-256 |
fd63f193d510dbdaef2cbfd38f9ce71e114640c8a0d79bdf26387d3bbfa60ef0
|
File details
Details for the file date_tree-1.0.1-py3-none-any.whl.
File metadata
- Download URL: date_tree-1.0.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7f59ac59e570fac1d1b9e2ded5c894fc652db2aa33637dda18ceb6a55e05e0c
|
|
| MD5 |
89225f0d52c89d6ecafa873454e49d34
|
|
| BLAKE2b-256 |
9b79bb134dceba0650eaa1ef6f1aa34d0fed3a6cafc559f99896c2bfeb3ff04c
|