Datefinder is a Python library designed to extract datetime objects from natural language text. It supports various date and time formats, including relative and absolute expressions. The current version is 1.0.0, and it follows an active release cadence, with a recent major update shifting its default parsing engine.
pip install datefinderVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `find_dates` to extract datetime objects from a string. It iterates through the returned `DateMatch` objects, printing both the original substring found and the parsed `datetime` object. It also shows how to explicitly specify the 'legacy' engine for pre-1.0.0 behavior.
If you need the pre-1.0.0 behavior, either use `find_dates(..., engine='legacy')` or import and use `find_dates_legacy` directly.
Always iterate over the results and access the `.datetime` attribute, e.g., `for match in find_dates(text): date_obj = match.datetime`.
Upgrade your Python environment to Python 3.9 or newer to use datefinder 1.0.0 and above.
Explicitly include timezone information in your input text for `datefinder` to parse it, or apply a default timezone to the resulting naive `datetime` objects using `pytz` or `zoneinfo` (Python 3.9+).
Understand that `strict=True` aims for higher precision (fewer false positives) at the cost of recall (more false negatives). Test your inputs thoroughly with `strict=True` to ensure it meets your requirements.
Install the package using pip: `pip install datefinder` or `!pip install datefinder` in a Jupyter Notebook cell.
Wrap the iteration over the `find_dates` generator in a `try-except IllegalMonthError` block to gracefully handle and skip problematic date strings.
Iterate through the list (or generator) of `datetime` objects and apply `.strftime()` to each individual `datetime` object.
Update both `datefinder` and its dependencies (especially `regex`) to their latest versions using `pip install --upgrade datefinder regex`. If the problem persists, consider reinstalling them in a fresh virtual environment.