Dateparser is a Python library (v1.4.0) designed to parse dates from various formats, including natural language and localized strings, often found on web pages. It aims to simplify datetime string conversion, timezone handling, and ambiguous date resolution. The library has an active development cycle with minor versions released every few months, frequently adding new language support and parsing features.
pip install dateparserVerified import paths — ran on the pinned version, not inferred.
The most common way to parse dates is using the `dateparser.parse()` function. It automatically detects formats and languages, and can be configured with settings for more control, such as handling relative dates or specific timezones.
Upgrade to Python >=3.10.
Review any custom logic that interacted with locale metadata or expected specific deserialization behavior. Adapt to stricter parsing rules.
Update code expecting a dictionary from `get_date_data()` to handle a `DateData` object. Validate settings passed to avoid `SettingValidationError`.
Pass `settings={'TIMEZONE': 'UTC', 'RETURN_AS_TIMEZONE_AWARE': True}` (or your desired timezone) to `dateparser.parse()` for consistent timezone-aware results.Use `settings={'DATE_ORDER': 'DMY'}` (or 'MDY', 'YMD' as appropriate) or `languages=['en-US']` to guide the parser.Configure settings like `settings={'PREFER_DATES_FROM': 'past'}` or `{'PREFER_MONTH_OF_YEAR': 'last'}` to control how missing date parts are inferred.Install the package using pip: `pip install dateparser`
Import the 'parse' function directly: `from dateparser import parse`
Always check if the result of `dateparser.parse()` is `None` before attempting further operations. For strings with extra text, consider using `dateparser.search.search_dates()` instead.
Ensure that the language codes are valid ISO 639-1 codes (e.g., `['en']`) and that the `languages` argument is always provided as a list.