rfc3339-validator
A pure Python regex-based validator for RFC3339 datetime strings
Repository Health
Technical Analysis
rfc3339-validator is a tiny, dependency-light Python package that checks whether a string is a valid RFC3339 datetime, the timestamp format used throughout JSON Schema’s date-time format keyword. It exposes a single validate_rfc3339() function that returns True/False, using a compiled regular expression plus a calendar-aware day-of-month check to reject dates like February 30th.
Despite its tiny surface area, it is widely depended upon transitively — most notably by the jsonschema and openapi-schema-validator ecosystems — as the default date-time format checker, which is why it sees very high download volume relative to its size.
What You Get
- A single
validate_rfc3339(date_string)function returning a boolean - Regex-based format matching for the full RFC3339 date-time grammar, including fractional seconds and UTC/offset timezone suffixes
- Calendar-aware day validation (rejects invalid dates like April 31st) via
calendar.monthrange() - Zero heavyweight dependencies beyond the
sixcompatibility shim
Common Use Cases
- Implementing the
date-timeformat checker for JSON Schema validation (used internally byjsonschema) - Validating timestamp fields in API request/response payloads before further processing
- Sanity-checking timestamp strings pulled from logs, config files, or third-party APIs
- Lightweight form/input validation where a full datetime-parsing library would be overkill
Under The Hood
Architecture — the entire implementation is a single module (rfc3339_validator.py) containing one compiled regex (RFC3339_REGEX) and one function (validate_rfc3339); the regex handles structural matching (year/month/day/time/timezone), and the function layers a calendar.monthrange() check on top to catch dates the regex alone would wrongly accept (e.g. February 30th).
Tech Stack — pure Python with a single runtime dependency on six for Python 2/3 compatibility flags; no compiled extensions, no async code, packaged via plain setuptools.
Code Quality — tests/test_rfc3339_validator.py exercises the validator against a table of valid and invalid date strings covering leap years, invalid months/days, and malformed timezone offsets; the codebase is small enough (under 50 lines) that the test-to-code ratio is high relative to complexity.
API Design — the API is a single function with a single string argument and boolean return, which is about as low-friction as an API can be; there’s no configuration, no exceptions to catch, and no state, making it trivial to drop into a validation pipeline or JSON Schema format-checker registry.