1
0
Fork 0
mirror of https://github.com/scrapinghub/dateparser.git synced 2026-04-09 15:14:34 +02:00
python parser for human readable dates https://dateparser.readthedocs.org/en/latest/
Find a file
Serhii A b72ed09a7f
Remove fastText support and enable numpy 2.x compatibility (#1315)
* Remove fastText support and enable numpy 2.x compatibility

FastText library has been archived since March 2024 and is no longer
maintained. This dependency was blocking numpy 2.x adoption.

Changes:
- Remove fasttext extra from setup.py dependencies
- Add deprecation warnings to fasttext.py module
- Update documentation to recommend langdetect as primary option
- Update CLI to deprecate --fasttext flag
- Add comprehensive test suite for langdetect integration
- Remove fasttext from tox.ini test configurations

Users should migrate to langdetect:
  pip install dateparser[langdetect]

Closes #1287
Closes #1251

* Update dateparser_cli/cli.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dateparser/custom_language_detection/fasttext.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Simplify fasttext deprecation to always error

The previous approach was confusing:
- If fasttext was installed, it showed a warning but still worked
- If fasttext wasn't installed, it raised an ImportError

This creates inconsistent deprecation - users don't know if the
feature is truly deprecated or not.

Now the module:
- Always shows deprecation warning on import
- Always raises ImportError when detect_languages() is called
- Provides clear migration path to langdetect
- No functional fasttext code remains

This makes the deprecation clear and consistent.

* Remove unused module-level mock in test_language_detect

The module-level 'detect_languages' mock was defined but never used.
The MockLangDetectTest class defines its own mock as a class attribute,
and other test classes use the actual lang_detect_detect_languages function.

This cleanup removes the unused mock to avoid confusion.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-04-09 12:22:23 +05:00
.github/workflows Fix deployment 2026-03-20 10:45:33 +01:00
artwork Make logo more translucent (#1312) 2026-02-10 05:26:26 +03:00
dateparser Remove fastText support and enable numpy 2.x compatibility (#1315) 2026-04-09 12:22:23 +05:00
dateparser_cli Remove fastText support and enable numpy 2.x compatibility (#1315) 2026-04-09 12:22:23 +05:00
dateparser_data Add the en-US locale (#1222) 2026-03-25 09:23:29 +01:00
dateparser_scripts Upgrade Python support and fix CI issues (#1296) 2026-01-08 00:18:26 +01:00
docs Remove fastText support and enable numpy 2.x compatibility (#1315) 2026-04-09 12:22:23 +05:00
fuzzing Fix tests (#1248) 2025-02-03 11:35:21 +01:00
tests Remove fastText support and enable numpy 2.x compatibility (#1315) 2026-04-09 12:22:23 +05:00
.coveragerc Modify nosetests command (#320) 2017-06-02 12:29:28 -04:00
.editorconfig remove makefile (#907) 2021-04-09 12:39:14 +02:00
.git-blame-ignore-revs Apply black (#1158) 2023-04-10 16:48:56 +02:00
.gitignore Add support for negative timestamps (#1060) 2022-06-17 15:27:54 +02:00
.isort.cfg Apply black (#1158) 2023-04-10 16:48:56 +02:00
.pre-commit-config.yaml Fix tests (#1248) 2025-02-03 11:35:21 +01:00
.readthedocs.yml Update Read the Docs config to use ubuntu-24.04 (#1320) 2026-03-31 10:19:47 +02:00
AUTHORS.rst Release 0.7.5 2020-06-10 11:56:17 +02:00
conftest.py Apply black (#1158) 2023-04-10 16:48:56 +02:00
CONTRIBUTING.rst 1.4.0 release notes and fixes (#1319) 2026-03-26 10:26:36 +01:00
HISTORY.rst Bump version: 1.3.0 → 1.4.0 2026-03-26 10:27:21 +01:00
LICENSE preparing package for public release, moved docs to reST 2014-11-24 15:17:18 -02:00
MANIFEST.in 1.4.0 release notes and fixes (#1319) 2026-03-26 10:26:36 +01:00
pyproject.toml Bump version: 1.3.0 → 1.4.0 2026-03-26 10:27:21 +01:00
pytest.ini Homogenize flake8 line length (#957) 2021-08-09 12:00:54 +02:00
README.rst Make logo more translucent (#1312) 2026-02-10 05:26:26 +03:00
SECURITY.md Bump version: 1.3.0 → 1.4.0 2026-03-26 10:27:21 +01:00
setup.py Remove fastText support and enable numpy 2.x compatibility (#1315) 2026-04-09 12:22:23 +05:00
tox.ini Remove fastText support and enable numpy 2.x compatibility (#1315) 2026-04-09 12:22:23 +05:00

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

.. Note that we use raw HTML in the header section because centering images and paragraphs is not supported in Github (https://github.com/github/markup/issues/163)

.. raw:: html

    <h1 align="center">
        <br/>
        <a href="https://github.com/scrapinghub/dateparser">
            <img src="artwork/dateparser-logo.png" alt="Dateparser" width="500">
        </a>
        <br/>
    </h1>

    <h3 align="center">Python parser for human readable dates</h4>

    <p align="center">
        <a href="https://pypi.python.org/pypi/dateparser">
            <img src="https://img.shields.io/pypi/dm/dateparser.svg" alt="PyPI - Downloads">
        </a>
        <a href="https://pypi.python.org/pypi/dateparser">
            <img src="https://img.shields.io/pypi/v/dateparser.svg" alt="PypI - Version">
        </a>
        <a href="https://codecov.io/gh/scrapinghub/dateparser">
            <img src="https://codecov.io/gh/scrapinghub/dateparser/branch/master/graph/badge.svg" alt="Code Coverage">
        </a>
        <a href="https://github.com/scrapinghub/dateparser/actions">
            <img src="https://github.com/scrapinghub/dateparser/workflows/Build/badge.svg" alt="Github - Build">
        </a>
        <a href="https://dateparser.readthedocs.org/en/latest/?badge=latest">
            <img src="https://readthedocs.org/projects/dateparser/badge/?version=latest" alt="Readthedocs - Docs">
        </a>
    </p>

    <p align="center">
        <a href="#key-features">Key Features</a> •
        <a href="#how-to-use">How To Use</a> •
        <a href="#installation">Installation</a> •
        <a href="#common-use-cases">Common use cases</a> •
        <a href="#you-may-also-like">You may also like...</a> •
        <a href="#license">License</a>
    </p>


Key Features
------------

-  Support for almost every existing date format: absolute dates,
   relative dates (``"two weeks ago"`` or ``"tomorrow"``), timestamps,
   etc.
-  Support for more than `200 language
   locales <https://dateparser.readthedocs.io/en/latest/supported_locales.html>`__.
-  Language autodetection
-  Customizable behavior through
   `settings <https://dateparser.readthedocs.io/en/latest/settings.html>`__.
-  Support for `non-Gregorian calendar
   systems <https://dateparser.readthedocs.io/en/latest/introduction.html#supported-calendars>`__.
-  Support for dates with timezones abbreviations or UTC offsets
   (``"August 14, 2015 EST"``, ``"21 July 2013 10:15 pm +0500"``...)
-  `Search
   dates <https://dateparser.readthedocs.io/en/latest/introduction.html#search-for-dates-in-longer-chunks-of-text>`__
   in longer texts.
-  Time span detection for expressions like "past month", "last week".

Online demo
-----------

Do you want to try it out without installing any dependency? Now you can test
it quickly by visiting `this online demo <https://gnyman.github.io/dateparser-demo-app/>`__!



How To Use
----------

The most straightforward way to parse dates with **dateparser** is to
use the ``dateparser.parse()`` function, that wraps around most of the
functionality of the module.

.. code:: python

    >>> import dateparser

    >>> dateparser.parse('Fri, 12 Dec 2014 10:55:50')
    datetime.datetime(2014, 12, 12, 10, 55, 50)

    >>> dateparser.parse('1991-05-17')
    datetime.datetime(1991, 5, 17, 0, 0)

    >>> dateparser.parse('In two months')  # today is 1st Aug 2020
    datetime.datetime(2020, 10, 1, 11, 12, 27, 764201)

    >>> dateparser.parse('1484823450')  # timestamp
    datetime.datetime(2017, 1, 19, 10, 57, 30)

    >>> dateparser.parse('January 12, 2012 10:00 PM EST')
    datetime.datetime(2012, 1, 12, 22, 0, tzinfo=<StaticTzInfo 'EST'>)

As you can see, **dateparser** works with different date formats, but it
can also be used directly with strings in different languages:

.. code:: python

    >>> dateparser.parse('Martes 21 de Octubre de 2014')  # Spanish (Tuesday 21 October 2014)
    datetime.datetime(2014, 10, 21, 0, 0)

    >>> dateparser.parse('Le 11 Décembre 2014 à 09:00')  # French (11 December 2014 at 09:00)
    datetime.datetime(2014, 12, 11, 9, 0)

    >>> dateparser.parse('13 января 2015 г. в 13:34')  # Russian (13 January 2015 at 13:34)
    datetime.datetime(2015, 1, 13, 13, 34)

    >>> dateparser.parse('1 เดือนตุลาคม 2005, 1:00 AM')  # Thai (1 October 2005, 1:00 AM)
    datetime.datetime(2005, 10, 1, 1, 0)

    >>> dateparser.parse('yaklaşık 23 saat önce')  # Turkish (23 hours ago), current time: 12:46
    datetime.datetime(2019, 9, 7, 13, 46)

    >>> dateparser.parse('2小时前')  # Chinese (2 hours ago), current time: 22:30
    datetime.datetime(2018, 5, 31, 20, 30)

You can control multiple behaviors by using the ``settings`` parameter:

.. code:: python

    >>> dateparser.parse('2014-10-12', settings={'DATE_ORDER': 'YMD'})
    datetime.datetime(2014, 10, 12, 0, 0)

    >>> dateparser.parse('2014-10-12', settings={'DATE_ORDER': 'YDM'})
    datetime.datetime(2014, 12, 10, 0, 0)

    >>> dateparser.parse('1 year', settings={'PREFER_DATES_FROM': 'future'})  # Today is 2020-09-23
    datetime.datetime(2021, 9, 23, 0, 0)

    >>> dateparser.parse('tomorrow', settings={'RELATIVE_BASE': datetime.datetime(1992, 1, 1)})
    datetime.datetime(1992, 1, 2, 0, 0)

To see more examples on how to use the ``settings``, check the `settings
section <https://dateparser.readthedocs.io/en/latest/settings.html>`__
in the docs.

False positives
^^^^^^^^^^^^^^^

**dateparser** will do its best to return a date, dealing with multiple formats and different locales.
For that reason it is important that the input is a valid date, otherwise it could return false positives.

To reduce the possibility of receiving false positives, make sure that:

- The input string is a valid date and doesn't contain any other words or numbers.
- If you know the language or languages beforehand, you add them through the ``languages`` or ``locales`` properties.


On the other hand, if you want to exclude any of the default parsers
(``timestamp``, ``relative-time``...) or change the order in which they
are executed, you can do so through the
`settings PARSERS <https://dateparser.readthedocs.io/en/latest/usage.html#handling-incomplete-dates>`_.

Installation
------------

Dateparser supports Python 3.10+. You can install it by doing:

::

    $ pip install dateparser

If you want to use the jalali or hijri calendar, you need to install the
``calendars`` extra:

::

    $ pip install dateparser[calendars]

Common use cases
----------------

**dateparser** can be used for a wide variety of purposes,
but it stands out when it comes to:

Consuming data from different sources:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

-  **Scraping**: extract dates from different places with several
   different formats and languages
-  **IoT**: consuming data coming from different sources with different
   date formats
-  **Tooling**: consuming dates from different logs / sources
-  **Format transformations**: when transforming dates coming from
   different files (PDF, CSV, etc.) to other formats (database, etc).

Offering natural interaction with users:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

-  **Tooling and CLI**: allow users to write “3 days ago” to retrieve
   information.
-  **Search engine**: allow people to search by date in an easy /
   natural format.
-  **Bots**: allow users to interact with a bot easily

You may also like...
--------------------

-  `price-parser <https://github.com/scrapinghub/price-parser/>`__ - A
   small library for extracting price and currency from raw text
   strings.
-  `number-parser <https://github.com/scrapinghub/number-parser/>`__ -
   Library to convert numbers written in the natural language to it's
   equivalent numeric forms.
-  `Scrapy <https://github.com/scrapy/scrapy/>`__ - Web crawling and web
   scraping framework

License
-------

`BSD3-Clause <https://github.com/scrapinghub/dateparser/blob/master/LICENSE>`__