ctparse - Parse natural language time expressions
raw JSON → 0.3.6 verified Mon Apr 27 auth: no python
Ctparse is a Python library for parsing natural language time expressions (like 'next Tuesday at 3pm', 'in two weeks', '3rd of March'). Version 0.3.6 is the latest release, with no recent updates. The project appears to be in maintenance mode.
pip install ctparse Common errors
error ImportError: cannot import name 'parse' from 'ctparse' ↓
cause Old import path from early examples or documentation.
fix
Use 'from ctparse import ctparse'.
error ctparse('next week') returns an empty list ↓
cause Missing reference timestamp or ambiguous expression not handled by grammar.
fix
Pass reference_ts=datetime.now() or try a more specific expression like 'next Monday'.
error TypeError: ctparse() missing 1 required positional argument: 'reference_ts' ↓
cause reference_ts is required in newer versions.
fix
Always provide reference_ts parameter as a datetime object.
Warnings
gotcha ctparse returns a list of results (or empty list), not a single object. Always check the list. ↓
fix Check if result list is non-empty before accessing result[0].
gotcha The function ctparse() requires a 'reference_ts' parameter (a datetime object) to resolve relative times. Without it, parsing 'today' or 'tomorrow' may be ambiguous. ↓
fix Always pass reference_ts=datetime.now() or similar.
deprecated The old import 'from ctparse import ctparse' is correct, but some older examples use 'from ctparse import parse'. That function no longer exists. ↓
fix Use 'from ctparse import ctparse'.
breaking In version 0.3, the internal rule engine was rewritten. Some expressions that worked in 0.2 may no longer parse. ↓
fix Review patterns; if something fails, file an issue on GitHub.
Imports
- ctparse
from ctparse import ctparse - parse_time_expression wrong
from ctparse import parse_time_expressioncorrectInternal server error