Prefixdate (version 0.5.0) is a Python library for parsing and processing date strings with varied levels of precision, such as '2001', '2001-4', or '2001-04-02'. It converts these partial dates into a structured format, enabling validation and re-formatting (e.g., normalizing '2001-4' to '2001-04'). The library is designed for handling ambiguous date prefixes and does not aim for full compliance with ISO 8601 or RFC 3339 standards, specifically excluding date ranges or calendar-week/day-of-year notations. It requires Python >=3.9. The latest version was released on August 4, 2025.
pip install prefixdateVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse various date strings and integers into `DatePrefix` objects, normalize them to standard formats, and use `parse_parts` for structured date input. It also shows how to handle invalid date inputs and specify output precision.
Manually handle timezone conversion before or after using `prefixdate` if aware datetimes are critical.
For full ISO 8601/RFC 3339 compliance, consider alternative libraries or custom parsing solutions.
Always check the `text` and `precision` attributes of the returned `DatePrefix` object for `None` or `Precision.EMPTY` to handle invalid inputs gracefully.
Trim milliseconds from input strings if they are not relevant, or use other parsing methods for inputs requiring millisecond precision.
Implement separate validation logic using Python's `datetime` module or other date validation libraries if strict calendrical validity is required.
Install the library using pip: `pip install prefixdate`
Ensure the input string adheres to one of the valid partial date formats that prefixdate is designed to parse.
Provide a string argument to the prefixdate function, for example, `prefixdate.parse("2001")` instead of `prefixdate.parse(2001)`.No dependency data recorded yet.