pyRFC3339 parses and generates RFC 3339-compliant timestamps using Python datetime.datetime objects. It aims to simplify timestamp parsing and generation, leveraging improvements in native Python capabilities. The current stable version is 2.1.0, released on August 23, 2025. It appears to be actively maintained with recent releases and GitHub activity.
pip install pyrfc3339Verified import paths — ran on the pinned version, not inferred.
Demonstrates how to generate RFC 3339 timestamps from timezone-aware `datetime` objects and parse RFC 3339 strings back into `datetime` objects, including handling of naive datetimes for generation.
Upgrade Python to 3.9+ or pin `pyrfc3339<2.0.0`.
Ensure `datetime` objects are timezone-aware (e.g., `datetime.now(timezone.utc)`), or explicitly pass `accept_naive=True` to treat naive datetimes as UTC.
Carefully manage `produce_naive` based on whether downstream code expects timezone-aware or naive datetimes. Prefer `utc=True` for consistent UTC output when a timezone is present in the string, or ensure `tzinfo` is handled if `produce_naive=True`.
Be aware that not all parsed timestamps might be strictly RFC 3339 compliant, even if `pyrfc3339` successfully parses them. If strict validation is required, additional checks might be necessary.
Install the library using pip: `pip install pyrfc3339`
Provide a timezone-aware datetime object, typically by localizing it to UTC or another timezone using `pytz` or `zoneinfo` (e.g., `dt_aware = dt_naive.replace(tzinfo=timezone.utc)` or `pytz.utc.localize(dt_naive)`).
Ensure the input string is a valid RFC 3339 timestamp (e.g., '2014-01-01T12:00:00Z' or '2014-01-01T12:00:00+01:00').
Remove the zero-value fractional seconds from the input string (e.g., change '2018-09-06T09:30:00.000000Z' to '2018-09-06T09:30:00Z').
No dependency data recorded yet.