Registry / serialization / prefixdate

prefixdate

JSON →
library0.6.1pypypi✓ verified 25d ago

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 prefixdate
INSTALL
IMPORT
SIG · PREFIXDATE
P
prefixdate
serializationpythonv0.6.1
Install
1.5s avg
Import
36ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.038s · 17.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.034s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
✓ from prefixdate import parse
normalize_date
✓ from prefixdate import normalize_date
Precision
✓ from prefixdate import Precision
parse_parts
✓ from prefixdate import parse_parts

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.

from prefixdate import parse, normalize_date, Precision, parse_parts from datetime import datetime # Parse returns a `DatePrefix` object: date_obj_month = parse('2001-3') assert date_obj_month.text == '2001-03' assert date_obj_month.precision == Precision.MONTH date_obj_year = parse(2001) assert date_obj_year.text == '2001' assert date_obj_year.precision == Precision.YEAR # Handle invalid input which results in an empty DatePrefix date_obj_invalid = parse('Not-a-date') assert date_obj_invalid.text is None assert date_obj_invalid.precision == Precision.EMPTY # Normalize to a standard string: assert normalize_date('2001-1') == '2001-01' assert normalize_date('2001-00-00') == '2001' # Normalize a datetime object with specific precision: now_utc_iso = datetime.utcnow().isoformat() minute_precision_date = normalize_date(now_utc_iso, precision=Precision.MINUTE) # Example output for minute_precision_date: 'YYYY-MM-DDTHH:MM' # Using parse_parts for structured input: date_from_parts = parse_parts(2001, '3', None) assert date_from_parts.precision == Precision.MONTH assert date_from_parts.text == '2001-03'
Debug
Known issues
gotchaAll `datetime` objects are converted to UTC and made naive (timezone information is stripped). Be aware of potential timezone issues if your application requires preserving original timezone data.
fix
Manually handle timezone conversion before or after using `prefixdate` if aware datetimes are critical.
affects: All versions
gotchaThe library explicitly does not support the full complexities of ISO 8601 and RFC 3339 standards, including date ranges and calendar-week/day-of-year notations.
fix
For full ISO 8601/RFC 3339 compliance, consider alternative libraries or custom parsing solutions.
affects: All versions
gotchaInvalid date strings (e.g., 'Boo!') or `None` passed to `parse()` will result in a `DatePrefix` object with `text` as `None` and `precision` as `Precision.EMPTY`.
fix
Always check the `text` and `precision` attributes of the returned `DatePrefix` object for `None` or `Precision.EMPTY` to handle invalid inputs gracefully.
affects: All versions
gotchaThe library does not currently process milliseconds in date strings.
fix
Trim milliseconds from input strings if they are not relevant, or use other parsing methods for inputs requiring millisecond precision.
affects: All versions
gotchaThe library does not validate for calendrically invalid dates (e.g., 'February 31st'). It focuses on string format parsing rather than date validity checks.
fix
Implement separate validation logic using Python's `datetime` module or other date validation libraries if strict calendrical validity is required.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'prefixdate'
The 'prefixdate' library is not installed in the Python environment or the import statement contains a typo.
fix
Install the library using pip: `pip install prefixdate`
ValueError: Invalid date string format
The input string provided to a prefixdate parsing function (e.g., `prefixdate.parse()`) does not match any of the supported partial date formats (e.g., 'YYYY', 'YYYY-M', 'YYYY-MM-DD').
fix
Ensure the input string adheres to one of the valid partial date formats that prefixdate is designed to parse.
TypeError: argument of type 'int' is not iterable
A function within the prefixdate library, such as `prefixdate.parse()`, was called with an argument of an incorrect type (e.g., an integer) when a string was expected.
fix
Provide a string argument to the prefixdate function, for example, `prefixdate.parse("2001")` instead of `prefixdate.parse(2001)`.
Upgrade
Version history
0.6.1latest on PyPI · released Aug 8, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources