Parsing Dates in 200+ Locales? This Python Library Does the Heavy Lifting
If you've ever tried to parse dates from a user input field or scraped text, you know the pain. One person writes "March 3rd, 2024", another writes "03/03/24", and someone else writes "3 mars 2024" (if they're in France). Python's built-in datetime and dateutil handle the common formats, but add relative dates like "2 days ago" or "next Thursday" and things get messy fast.
There's a library that handles exactly this — and it's been around quietly doing excellent work. Let me introduce you to dateparser.
What It Does
dateparser is a Python library for parsing dates from strings. The headline feature: it supports over 200 locales and also handles relative dates. You feed it a string, it returns a Python datetime object. That's it.
Under the hood, it uses a combination of language detection, locale-specific tokenization, and fuzzy matching to figure out what "last martes" or "il y a 3 jours" means and convert it to a concrete date.
Why It's Cool
1. 200+ locales out of the box
This is the killer feature. You don't need to install separate locale packages or write custom parsers for each language. Just pass the string and optionally set the language hint. Chinese, Arabic, Hindi, Swedish — it's all covered.
2. Relative dates with zero effort
Strings like "2 weeks ago", "tomorrow", "next Friday", "yesterday at 3pm" — they all parse correctly without any configuration. This is incredibly useful for scraping, chatbots, or processing user input in apps.
3. Handles ambiguous dates gracefully
It can deal with "03/04/2024" and correctly interpret it based on the locale (US: March 4, EU: April 3). You can also set a DATE_ORDER preference when ambiguity matters.
4. Built for speed and reliability
The library has been around for years (since ~2015) with relatively stable APIs. It's used by scrapinghub (the company behind Scrapy) in production for millions of date strings. It's mature and well-tested.
5. Simple API
You just call parse() with a string. Optionally pass languages, locales, or settings for fine control.
import dateparser dateparser.parse("2 days ago")
# returns datetime object for 2 days ago dateparser.parse("3 mars 2024", languages=['fr'])
# datetime(2024, 3, 3)
How to Try It
Insta