Beautiful Date

raw JSON →
2.3.0 verified Fri May 01 auth: no python

A Python library providing a simple and beautiful way to create date and datetime objects using natural language-like expressions. Current version 2.3.0, requires Python >=3.5. Release cadence is low, with occasional updates. Maintained by kuzmoyev.

pip install beautiful-date
error AttributeError: module 'beautiful_date' has no attribute 'beautiful_date'
cause Importing the module incorrectly. The function is inside the module but imported as a symbol.
fix
Use: from beautiful_date import beautiful_date
error AttributeError: module 'beautiful_date' has no attribute 'January'
cause Trying to use month names directly after importing the module without importing the function.
fix
Correct import: from beautiful_date import beautiful_date as bd; then use bd.January(...)
error ValueError: day is out of range for month
cause Passing invalid day number for given month, e.g., February 30.
fix
Check the day number is valid for the month. For February, days 1-28 (or 29 in leap year).
gotcha beautiful_date returns datetime.date objects, not custom types. Do not expect additional methods beyond standard date methods.
fix Use standard date methods or cast to datetime if needed.
gotcha Month names are English only. Locale or non-English month names will raise AttributeError.
fix Always use English month names (January, February, etc.).
deprecated beautiful_time and beautiful_datetime are deprecated in favor of using beautiful_date with datetime.time objects.
fix Use beautiful_date for dates; for times, construct datetime.time manually.

Creates date objects using month names. bd.January(1, 2023) returns a datetime.date(2023,1,1).

from beautiful_date import beautiful_date as bd
print(bd.January(1, 2023))
print(bd.today())
print(bd.now())