RFC3339 Validator
rfc3339-validator is a lightweight, pure Python library designed for strictly validating date-time strings against the RFC 3339 Internet Date/Time Format specification. Currently at version 0.1.4, its last release was in May 2021, indicating a mature, low-cadence project that provides a focused utility for ensuring RFC 3339 compliance in applications requiring precise time formatting, such as web APIs and data serialization.
Warnings
- gotcha RFC 3339 is a strict profile of ISO 8601. This validator enforces strict compliance, meaning common deviations like using a space instead of 'T' between date and time, or omitting timezone information (offset or 'Z'), will result in validation failure.
- gotcha The library does not support validation or handling of leap seconds. As standard timestamps do not generally account for leap seconds, RFC 3339 validators typically do not either. This is a characteristic of the standard itself.
- gotcha While Python's `datetime` objects can be used for RFC 3339 representation, improper handling of timezones (e.g., naive datetimes or incorrectly applied local timezones) can lead to invalid RFC 3339 strings, as RFC 3339 strictly requires an explicit UTC offset or 'Z'.
Install
-
pip install rfc3339-validator
Imports
- validate_rfc3339
from rfc3339_validator import validate_rfc3339
Quickstart
from rfc3339_validator import validate_rfc3339
# Valid RFC3339 datetime
print(validate_rfc3339('2001-10-23T15:32:12.9023368Z'))
# Invalid RFC3339 datetime
print(validate_rfc3339('1424-45-93T15:32:12.9023368Z'))
# Another valid example with offset
print(validate_rfc3339('2023-09-24T15:30:00+09:00'))
# Invalid: missing timezone/offset, RFC3339 requires it
print(validate_rfc3339('2023-09-24T15:30:00'))