rfc3986-validator

A pure Python regex-based validator for RFC3986 URIs and URI references

Library
PyPI
v0.1.1
4stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
18/100Needs Attention
Development Activity0
Maintenance0
Community12
Maturity60
Momentum0

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
54/100Fair
Architecture40
Code Quality58
Innovation32
Learning Curve85

rfc3986-validator is a small Python package that checks whether a string is a syntactically valid URI (or URI-reference) per RFC3986, the IETF grammar underlying most modern URI/URL formats. It implements the RFC’s ABNF grammar directly as compiled regular expressions — covering scheme, authority (including IPv4 and IPv6 host literals), path, query, and fragment components — and exposes a single validate_rfc3986() function.

Like its sibling rfc3339-validator, it’s widely used transitively as the default uri/uri-reference format checker inside the jsonschema ecosystem, giving it outsized reach relative to its tiny codebase.

What You Get

  • A single validate_rfc3986(uri, rule=...) function returning a boolean
  • Full RFC3986 ABNF grammar coverage: scheme, authority, userinfo, IPv4/IPv6 host literals, path, query, fragment
  • Support for both absolute URI and relative URI_reference validation via the rule parameter
  • Zero runtime dependencies — pure Python regex, no external parsing library

Common Use Cases

  • Implementing the uri/uri-reference format checker for JSON Schema validation (used internally by jsonschema)
  • Validating URL/URI fields in API request payloads before storing or dereferencing them
  • Rejecting malformed URIs (e.g. unencoded spaces) in user-submitted links
  • Distinguishing absolute URIs from relative references in link-processing pipelines

Under The Hood

Architecture — the module builds up RFC3986’s grammar compositionally: an IPv6_RE regex feeds into AUTHORITY_RE (host/userinfo/port), which feeds into URI_RE and a second URI_REFERENCE_RE for relative references, each pre-compiled once at import time; validate_rfc3986() simply picks the right compiled pattern based on the rule argument and calls .match().

Tech Stack — pure Python standard library only (re), no third-party runtime dependencies, packaged with plain setuptools.

Code Quality — the test suite exercises both URI and URI_reference rules against valid and invalid examples (encoded/unencoded characters, IPv6 authorities, missing schemes); the regex-heavy implementation trades some readability for direct fidelity to the RFC’s ABNF, with comments mapping each regex fragment back to its grammar rule.

API Design — a single function with a string argument and an optional rule keyword covers both use cases (strict absolute URI vs. permissive URI-reference) without needing separate functions or classes, keeping the surface area minimal for library consumers like jsonschema.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search