date-ranges
A DateRange type and related utility functions.
Quickstart
Install from pip:
pip install date-ranges
Import and create an instance:
from datetime import date
from date_ranges import DateRange
my_date_range = DateRange(start=date(2023, 5, 10), end=date(2023, 11, 3))
Usage
from datetime import date
from date_ranges import DateRange, MAX_DATE
# end date defaults to MAX_DATE
dr = DateRange(date(2023, 11, 1))
date(2023, 11, 22) in dr
# True
# An empty date (0 days in range):
empty = DateRange.empty()
bool(empty)
# False
# Iteration
for d in DateRange(date(2023, 1, 1), date(2023, 1, 3)):
print(d)
# 2023-01-01
# 2023-01-02
# 2023-01-03
# Create from strings
dr = DateRange.from_string('20230101-20230103')
repr(dr)
# 'DateRange(start=datetime.date(2023, 1, 1), end=datetime.date(2023, 1, 3))'
# Create range for a single date
dr = DateRange.from_string('20231031')
repr(dr)
# 'DateRange(start=datetime.date(2023, 10, 31), end=datetime.date(2023, 10, 31))'
# Create range for given year-month
dr = DateRange.from_string('202305')
repr(dr)
# 'DateRange(start=datetime.date(2023, 5, 1), end=datetime.date(2023, 5, 31))'
# Create range for multiple full months
dr = DateRange.from_string('202305-202311')
repr(dr)
# 'DateRange(start=datetime.date(2023, 5, 1), end=datetime.date(2023, 11, 30))'
# Formatted print
dr = DateRange(date(2023, 1, 1), date(2023, 1, 3))
dr
# 20230101-20230103
print(f'{dr:H}') # H for human
# 2023-01-01 to 2023-01-03
# Full months rendered appropriately
dr = DateRange.from_string('202305')
f'{dr:H}' # H for "human-readable"
# 'May 2023'
f'{dr:C}' # C for compact
# '202305'
dr
# '202305'
Development
For those developing or maintaining the date-ranges package itself,
be sure to install it with the [dev] option to pull in packages
used when developing.
pip install --editable .[dev]
When developing, this package uses pre-commit. After the initial
clone of the repository, you will need to set up pre-commit with:
# in the top level of the checked-out repository:
pre-commit install
Changelog
0.1.1 released 2025-06-27
- Fixed explicit exports
0.1.0 released 2025-06-26
- Add utility functions
- weekday_after, weekday_before, first_weekday_of_month, last_weekday_of_month
0.0.2 released 2023-11-10
- Fixed typo
0.0.1 released 2023-11-03
- Initial Version
Metadata
Release files for date-ranges 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| date_ranges-0.1.1.tar.gz | 9.5 kB | Without provenance | Details for date_ranges-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| date_ranges-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for date_ranges-0.1.1-py3-none-any.whl |
Total release size: 16.1 kB
Release files / date_ranges-0.1.1.tar.gz
| Download URL | date_ranges-0.1.1.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6d0fc5f7ffb12e8e5124fa340ca05e29f0bb06e93375b0c5a8f161795055fe00
|
|
BLAKE2b-256 checksum How to use checksums |
4f5224a3966748e38098cc6a5e5a950a956fcd7acea9c23c0bc19ad655ce79d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / date_ranges-0.1.1-py3-none-any.whl
| Download URL | date_ranges-0.1.1-py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b93cac1d11606cd73a831ff510eb6de815c4835e33cd810ee6fb66de0875875e
|
|
BLAKE2b-256 checksum How to use checksums |
4b321a3bb31b329bad381cc99a7bd594b65ea2a79b2f420565232896255f1293
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Security for date-ranges 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.