RFC 3987 Syntax Validation

1.1.0 · active · verified Sat Mar 28

rfc3987-syntax is a Python library (current version 1.1.0) that provides helper functions to syntactically validate strings according to the ABNF grammar defined in RFC 3987, which specifies Internationalized Resource Identifiers (IRIs). It is lightweight, permissively licensed (MIT), and leverages the Lark parsing library. The project strictly focuses on ABNF syntax validation, explicitly stating that additional semantic rules (like Unicode normalization or BiDi constraints) must be handled separately. With a relatively active release cadence, its latest major update (v1.1.0) introduced support for IRI-reference and absolute-IRI.

Warnings

Install

Imports

Quickstart

Demonstrates how to list supported validation terms and use the `is_valid_syntax` function to check if a string conforms to a specific RFC 3987 syntax rule, such as 'iri'.

from rfc3987_syntax import is_valid_syntax, RFC3987_SYNTAX_TERMS

# List all supported validation terms
print(f"Supported terms: {RFC3987_SYNTAX_TERMS}\n")

# Validate a string against a specific term
if is_valid_syntax(term='iri', value='http://example.com/path/to/resource?query=param#fragment'):
    print("✓ 'http://example.com/path/to/resource?query=param#fragment' is a valid IRI syntax")
else:
    print("✗ Invalid IRI syntax")

# Example of invalid syntax
if not is_valid_syntax(term='iri', value='not-an-iri-with- space'):
    print("✗ 'not-an-iri-with- space' is invalid IRI syntax as expected")

view raw JSON →