Registry / serialization / rfc3339

rfc3339

JSON →
library6.2pypypi✓ verified 25d ago

The `rfc3339` library for Python provides utilities to format `datetime` objects into RFC 3339 compliant strings and to parse such strings back into `datetime` objects. It closely adheres to the RFC 3339 standard, including providing its own UTC `tzinfo` implementation. While the PyPI package `6.2` was last released in 2019, the primary GitHub repository shows recent maintenance activity, indicating it's still actively maintained, albeit with a slow release cadence.

pip install rfc3339
INSTALL
IMPORT
SIG · RFC3339
R
rfc3339
serializationpythonv6.2
Install
1.5s avg
Import
131ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v6.2 · 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.103.95 runs
installs and imports cleanly · install 0.0s · import 0.142s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.120s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

rfc3339
import rfc3339
The library itself is imported as `rfc3339`.

This quickstart demonstrates how to format a `datetime` object into an RFC 3339 compliant string and parse such a string back into a `datetime` object using the `rfc3339` library. It also includes an example of parsing a string with a specific timezone offset.

from datetime import datetime, timezone import rfc3339 # Get current UTC time now_utc = datetime.now(timezone.utc) # Format a datetime object to RFC 3339 string rfc3339_string = rfc3339.rfc3339(now_utc) print(f"Formatted: {rfc3339_string}") # Parse an RFC 3339 string back to a datetime object parsed_datetime = rfc3339.parse_rfc3339(rfc3339_string) print(f"Parsed: {parsed_datetime}") # Example with a specific date and offset date_with_offset_str = "2023-10-27T10:00:00-05:00" parsed_with_offset = rfc3339.parse_rfc3339(date_with_offset_str) print(f"Parsed with offset: {parsed_with_offset}")
Debug
Known issues
gotchaThe `rfc3339` library, like Python's standard `datetime` module, does not support or account for leap seconds in its parsing or generation. While RFC 3339 specifies them, this library (and Python's native `datetime`) treats all minutes as 60 seconds long.
fix
Applications requiring precise handling of leap seconds must implement custom logic or use specialized libraries that provide this functionality, as it's not handled by standard Python `datetime` or this library.
affects: All versions
gotchaThe library explicitly states it does not implement RFC 3339 Section 4.3, "Unknown Local Offset Convention." This means it might not correctly handle or generate timestamps where the local offset is truly unknown and represented by '-00:00' semantically distinct from '+00:00' or 'Z'.
fix
When dealing with timestamps that might originate from systems using the 'Unknown Local Offset Convention', verify how the specific string format is handled. For strict adherence, consider manual parsing or pre-processing if '-00:00' must carry this specific semantic meaning.
affects: All versions
gotchaThe parsing routines in `rfc3339` primarily focus on Section 5.6, "Internet Date/Time Format." While this is a common and strict profile of RFC 3339 (and ISO 8601), more lenient or alternative RFC 3339 compliant variations might not be parsed correctly. For broader ISO 8601 parsing, other libraries like `python-dateutil` might be more suitable.
fix
Ensure input strings strictly adhere to the 'Internet Date/Time Format' profile (e.g., 'T' separator, explicit offset like 'Z' or '+HH:MM'). If you encounter parsing failures for valid RFC 3339 strings, inspect their exact format against Section 5.6 of the RFC.
affects: All versions
gotchaPython's `datetime` module itself has complexities with timezones, especially when dealing with naive datetimes or converting between different timezone representations (local vs. UTC, DST transitions). While `rfc3339` provides its own UTC `tzinfo`, inconsistencies can arise if not carefully managed with the underlying `datetime` objects.
fix
Always ensure your `datetime` objects are timezone-aware (e.g., created with `timezone.utc` or `pytz` timezones) before passing them to `rfc3339` functions for consistent results. Avoid mixing timezone-aware and naive `datetime` objects.
affects: All versions
Upgrade
Version history
6.2latest on PyPI · released Sep 24, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Resources
rfc3339 — pip install rfc3339 · libregistry