Recognizers-Text
raw JSON → 1.0.2a2 verified Fri May 01 auth: no python
Recognizers-Text is a Microsoft-maintained NLP library for recognizing and normalizing numbers, units, date/time, phone numbers, emails, and URLs from unstructured text. It supports multiple languages (English, Spanish, French, Chinese, Japanese, and more) via separate per-culture packages. The Python package is at version 1.0.2a2 (alpha) and lags behind the .NET and JavaScript releases (v1.8.x). Releases are irregular.
pip install recognizers-text Common errors
error ModuleNotFoundError: No module named 'recognizers_number' ↓
cause Attempting to import from sub-packages that do not exist as standalone modules.
fix
Use 'from recognizers_text import recognize_number' instead.
error AttributeError: type object 'Culture' has no attribute 'en-us' ↓
cause Passing a string like 'en-us' instead of the Culture class attribute.
fix
Use Culture.English or Culture.EnglishUs (if available). Check Culture.__dict__ for valid options.
error KeyError: 'values' ↓
cause Accessing result.resolution['values'] when resolution is None or not a dict (e.g., when no match or different type).
fix
Check that result.resolution is a dict and contains 'values' key. Use result.resolution.get('values', []) or handle empty cases.
error ImportError: cannot import name 'recognize_datetime' from 'recognizers_text' ↓
cause Older versions of the package may not have the function or the package is installed incorrectly.
fix
Upgrade to the latest version: pip install --upgrade recognizers-text
Warnings
gotcha The Python package (1.0.2a2) is an alpha release and significantly outdated compared to the .NET/JS versions (v1.8.x). Many languages and features (e.g., phone numbers, URLs) are missing. ↓
fix If you need the latest recognizers, use the .NET or JavaScript libraries instead.
gotcha All recognizer functions are in the same 'recognizers_text' top-level module. Do not import from sub-packages like 'recognizers_number' or 'recognizers_datetime' — they are not directly importable. ↓
fix Use 'from recognizers_text import recognize_number, recognize_datetime, ...'.
gotcha Culture is a class, not an enum or string. You must use Culture.English, Culture.Spanish, etc. Passing a string like 'en-us' will raise an AttributeError. ↓
fix Always use Culture attributes. Example: Culture.English.
deprecated The 'recognizers_text' package does not include the optional 'datatypes-timex-expression' dependency by default. Without it, accessing 'result.resolution' as a Timex object will fail. ↓
fix Install with extra: pip install recognizers-text[datatypes-timex-expression]
gotcha Recognition results may return empty lists for unrecognized text; they do not raise exceptions. Always check the result length. ↓
fix if not results: # handle no match
gotcha The 'recognizers_text' package name is slightly different from the GitHub repo name 'Recognizers-Text' (capitalized with hyphen). Import uses underscores. ↓
fix Use 'import recognizers_text' (all lowercase, underscore).
Install
pip install recognizers-text[datatypes-timex-expression] Imports
- Culture wrong
from recognizers_text.culture import Culturecorrectfrom recognizers_text import Culture - recognize_number wrong
from recognizers_number import recognize_numbercorrectfrom recognizers_text import recognize_number - recognize_datetime
from recognizers_text import recognize_datetime - ModelResult wrong
from recognizers_text.model import ModelResultcorrectfrom recognizers_text import ModelResult
Quickstart
from recognizers_text import Culture, recognize_datetime
# Recognize dates in English text
results = recognize_datetime("I'll be there on 2025-06-15", Culture.English)
for result in results:
print(f"Text: {result.text}, Type: {result.type_name}, Resolution: {result.resolution}")
# Example output:
# Text: 2025-06-15, Type: datetimeV2.date, Resolution: {'values': [{'timex': '2025-06-15', 'type': 'date', 'value': '2025-06-15'}]}