RFC3339 Validator

raw JSON →
0.1.4 verified Tue May 12 auth: no python install: verified quickstart: verified

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.

pip install rfc3339-validator
error ModuleNotFoundError: No module named 'rfc3339_validator'
cause The rfc3339-validator library has not been installed, or the Python environment where the code is run does not have access to it.
fix
Run pip install rfc3339-validator to install the library.
error ImportError: cannot import name 'validate' from 'rfc3339_validator'
cause The user is attempting to import a function named `validate` from the module, but the correct function name for validation is `validate_rfc3339`.
fix
Use the correct function name: from rfc3339_validator import validate_rfc3339
error AttributeError: module 'rfc3339_validator' has no attribute 'validate'
cause After importing the `rfc3339_validator` module, the user is attempting to call a method named `validate` which does not exist; the correct function name is `validate_rfc3339`.
fix
Call the correct validation function: rfc3339_validator.validate_rfc3339(date_string)
error TypeError: expected string, got <type>
cause The `validate_rfc3339` function expects a string as its argument, but it received a different data type (e.g., int, float, or None).
fix
Ensure that the argument passed to validate_rfc3339 is always a string. Convert non-string inputs to strings before validation, for example: validate_rfc3339(str(value)).
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.
fix Ensure all date-time strings conform precisely to RFC 3339, including the 'T' separator and a mandatory timezone offset (e.g., '+00:00', '-05:00', or 'Z' for UTC).
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.
fix For applications requiring leap second awareness, additional, specialized logic or libraries would be necessary beyond standard RFC 3339 validation.
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'.
fix Always use timezone-aware `datetime` objects, preferably `timezone.utc` or `datetime.now(timezone.utc)`, and ensure output formatting includes the correct offset or 'Z' when constructing RFC 3339 strings to be validated.
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.02s 17.9M
3.10 alpine (musl) - - 0.02s 17.9M
3.10 slim (glibc) wheel 1.5s 0.01s 18M
3.10 slim (glibc) - - 0.01s 18M
3.11 alpine (musl) wheel - 0.03s 19.7M
3.11 alpine (musl) - - 0.04s 19.7M
3.11 slim (glibc) wheel 1.6s 0.03s 20M
3.11 slim (glibc) - - 0.03s 20M
3.12 alpine (musl) wheel - 0.02s 11.6M
3.12 alpine (musl) - - 0.02s 11.6M
3.12 slim (glibc) wheel 1.5s 0.02s 12M
3.12 slim (glibc) - - 0.02s 12M
3.13 alpine (musl) wheel - 0.02s 11.3M
3.13 alpine (musl) - - 0.02s 11.2M
3.13 slim (glibc) wheel 1.5s 0.02s 12M
3.13 slim (glibc) - - 0.02s 12M
3.9 alpine (musl) wheel - 0.02s 17.4M
3.9 alpine (musl) - - 0.02s 17.4M
3.9 slim (glibc) wheel 1.8s 0.02s 18M
3.9 slim (glibc) - - 0.02s 18M

The library provides a single, straightforward function, `validate_rfc3339`, which takes a string and returns `True` if it conforms to the RFC 3339 specification, and `False` otherwise. RFC 3339 strictly requires a timezone offset (e.g., '+09:00', '-05:00') or 'Z' for UTC.

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'))