DateTimeRange
DateTimeRange is a Python library to handle a time range. e.g. check whether a time is within the time range, get the intersection of time ranges, truncate a time range, iterate through a time range, and so forth.
What it is and what it does
DateTimeRange is a Python library for creating and working with time intervals. It wraps datetime objects into range containers that support standard operations—checking whether a specific time falls within a range, finding overlaps between ranges, computing their union or intersection, and iterating through a range at regular intervals. The library handles timezone-aware datetimes and daylight saving time transitions.
You use it when you need to reason about time spans rather than individual moments: scheduling systems that check availability windows, log analysis that filters events within time bounds, or data pipelines that need to split time series into regular chunks. It depends on python-dateutil for relative date arithmetic and typepy for type validation.
Use it for:
- Check if a specific timestamp falls within a scheduled maintenance window or business hours range.
- Find overlapping time slots when merging calendar events or meeting availability.
- Iterate through a date range in monthly or quarterly steps for reporting or data aggregation.
- Truncate or split time ranges to align with reporting periods or data collection windows.
- Compute the intersection of multiple time ranges to find common availability across resources.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
DateTimeRange creates and manipulates time range objects, supporting operations like containment checks, intersections, unions, truncation, and iteration over intervals.
Yes. DateTimeRange is actively maintained, has no known vulnerabilities, minimal dependencies, and solves a concrete problem in datetime handling that the standard library handles awkwardly. Install it if your code frequently reasons about time intervals, overlaps, or iteration across date ranges.
Install
datetimerange on PyPI
pip
pip install datetimerangeuv
uv add datetimerangepoetry
poetry add datetimerangeInstalling DateTimeRange
Before you install
Low install friction with just two runtime dependencies (python-dateutil and typepy). Actively maintained with a recent commit on 2026-07-20 and stable production status.
License in practice
MIT License permits commercial and private use with minimal restrictions, making it suitable for most projects without licensing concerns.
Quickstart
pip install DateTimeRange
from datetimerange import DateTimeRange
time_range = DateTimeRange("2015-03-22T10:00:00+0900", "2015-03-22T10:10:00+0900")
print("2015-03-22T10:05:00+0900" in time_range)
Requires Python 3.9 or later.
Package facts
| License | MIT License (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — python-dateutil, typepy |
| Maintenance | actively maintained — 273 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 331,852/month — #7,511 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: datetimerange-2.3.2-py3-none-any.whl
Keywords: datetimerange, datetime, time range
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
aniso8601Parses ISO 8601 date, time, datetime, duration,…
permissive · top 5,000 on PyPI
types-DateTimeRangeProvides type stubs for the DateTimeRange…
permissive · top 15,000 on PyPI
dateformatParses strings into datetime objects and…
permissive · top 15,000 on PyPI
pendulumPendulum provides an enhanced datetime API for…
permissive · top 1,000 on PyPI
wheneverWhenever provides type-safe, DST-aware datetime…
permissive · top 5,000 on PyPI
pytzpytz brings the Olson timezone database into…
permissive · top 100 on PyPI
schedulerAn in-process job scheduler for Python that…
copyleft · top 15,000 on PyPI
DateTimeProvides a DateTime data type for working with…
unclear · top 5,000 on PyPI
cronitercroniter iterates over datetime objects using…
permissive · top 1,000 on PyPI