Flashdate - a drop-in for Python's dateparser, 100x faster
dateparser reads dates the way people write them: "March 5, 2024", "le 5 mars 2024", "3 days ago". It is downloaded about 45 million times a month, and it is slow.
One ISO date takes it about 670 microseconds. A scraper that reads ten million dates spends about two hours on it.
flashdate is a modified copy of dateparser with the same API and the same results. It reads common date formats 100 to 250 times faster, and it is still pure Python.
Making it fast was the easier half. The harder half was knowing that it still gives the same answer for every string. This article covers both.
Why dateparser is slow
dateparser does not know the language of a string in advance. For every string it works out which of its 205 languages could apply, translates the words to English, splits the result into tokens, and tries several parsers in turn.
An ISO date like 2024-03-05 goes through all of these steps, although nothing in it needs translating.
What flashdate does differently
Three changes give most of the speed.
- Direct routes for common shapes. ISO dates, numeric dates like
03/05/2024, and dates with month names in English and six other languages are recognised by their shape and read straight away. Anything else goes through the full steps, as before. On dateparser's own evaluation set of 300,000 article dates, 80% take a direct route. - Languages are skipped early. A language is skipped when the string contains a letter or a word that the language cannot have.
- Work is done once. The list of languages is built once, not for every date. Time zones are searched once per string. Known words are matched with a prefix tree.
Figure 1. The route one ISO date takes through each library.
Figure 2. Time to read one date, on a standard GitHub Actions runner.
The numbers behind the chart
Microseconds per date string:
| Date string | dateparser | flashdate | Speedup |
|---|---|---|---|
| 2024-03-05 | 672 | 4.8 | 141x |
| 2024-03-05T13:45:00Z | 1,388 | 5.4 | 259x |
| 03/05/2024 | 679 | 5.3 | 129x |
| March 5, 2024 | 691 | 5.3 | 131x |
| le 5 mars 2024 | 935 | 6.0 | 156x |
| 3 days ago | 391 | 41.7 | 9x |
| Text that is not a date | 7,443 | 432 | 17x |
These numbers come from a public run. Anyone can open it or start it again in a fork. The times change with the machine. The speedup changes much less: across three runners, the common formats were 103 to 259 times faster.
How I know it is the same
I never decided what the right answer for a string is. The untouched dateparser is the judge. The only question is whether both libraries give the same answer.
Figure 3. How every change was checked.
- 112 million strings, in 127 groups, were parsed by both. That includes every valid ISO date from year 1 to 9999 and every valid numeric date in both day and month orders. There were 0 differences.
- 31 combinations of settings, called in mixed order, gave 836,052 results. Mixed order matters: it catches a cache that leaks from one call into the next.
- 17 clock and time zone setups, because "3 days ago" depends on what time it is now.
- Errors too. Where dateparser raises an exception, flashdate raises the same one.
- dateparser's own tests, more than 25,000 of them, pass against the built package on Python 3.10 to 3.14.
A check is only worth something if it can fail, and this one did. An early version had a faulty cache, and the comparison caught it.
It also caught a case where flashdate was arguably more correct. On a machine set to German or Japanese, it read "1:45 PM" where dateparser does not. I changed flashdate to match, because code that switches to it should not start behaving differently.
What it costs
Memory, in one case. Usually flashdate uses as much memory as dateparser, to within 1 MB, or less. When dates in all 205 languages go through one process, it keeps 68 MB where dateparser keeps 55 MB. The difference is fixed and does not grow.
The table is in the README, and reducing it is planned for the next release.
Figure 4. Memory kept after parsing.
How it was built
Most of the code was written with Claude Code, an AI coding tool, and the commits say so. I chose the target, set the rules and made the decisions. The agent wrote, measured and checked.
One rule made this workable: nothing is believed, everything is measured. That applied to the agent's claims, to the reviewer's claims, and to mine.
Figure 5. What was said, and what was measured.
- A change stays only if dateparser agrees. Every change was run against the untouched dateparser, on every string, before it was kept.
- A test must be seen failing. Each new test was checked by undoing the fix it covers and watching the test fail. A test that cannot fail proves nothing.
- The code was reviewed, and the review was measured too. Before the release, a separate AI session reviewed the whole change without knowing how it was written. It reported 8 issues, none of which gave a wrong date. Seven were fixed. The eighth was a claim about speed that did not hold when measured, so nothing was changed.
- Published numbers were measured again in public. The first benchmark ran on my laptop. Moving it to a public GitHub run showed that two claims were slightly high, and I corrected them: "10 times" became "8 to 10 times", and "19 times" became "17 times".
- Costs were measured, not argued. When I asked whether the speed was bought with memory, the answer came from a benchmark. It found one case that costs 13 MB more, and that case is now in the README.
Agentic coding makes writing code cheap. It does not make the code right. What makes it right is a check that does not depend on anyone's word, including the agent's.
What I would repeat
- Keep the old system as the judge. It removes every argument about what is correct.
- Make sure the check can fail. Break something on purpose and watch the check catch it.
- Publish numbers that others can run again. A benchmark on a laptop cannot be checked. A public run can.
Try it
pip install flashdate
import flashdate
flashdate.parse("le 5 mars 2024") # datetime.datetime(2024, 3, 5, 0, 0)
Moving an existing codebase
It takes one changed line per file. Change the import and leave the rest of the code alone:
# before
import dateparser
# after
import flashdate as dateparser
Every call below that line stays as it is: dateparser.parse(...), the settings, the languages, DateDataParser.
Where you import from a submodule, only the package name changes:
from flashdate.search import search_dates
from flashdate.date import DateDataParser
You do not have to take my word for the results. Check them on your own data first:
- Install flashdate. It does not replace dateparser, so nothing changes yet.
- Run both on a sample of your own dates and compare.
- Switch the import. To go back, change that one line back.
import dateparser
import flashdate
for text in my_dates:
assert flashdate.parse(text) == dateparser.parse(text), text
Relative dates such as "3 days ago" depend on the current time. To compare those, pass the same RELATIVE_BASE setting to both.
It installs next to dateparser under its own name, so you can run both and compare. If you find a string where they differ, that is a bug: please open an issue.
The design, the language data and the tests are the work of dateparser's maintainers. flashdate keeps their licence and only changes how fast the answers come.
Code, benchmarks and the comparison scripts: shrinish123 / flashdate
Comments
No comments yet. Start the discussion.