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.
pip install rfc3987-syntaxVerified import paths — ran on the pinned version, not inferred.
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'.
Implement additional logic for semantic validation as required by your application.
Confirm the correct package name during installation: `pip install rfc3987-syntax`.
Review validation logic and expected outcomes when upgrading from versions prior to 1.1.0, especially for inputs involving IRI-references, absolute-IRIs, or single quotes within delimited components.
Install the library using `pip install rfc3987-syntax` and ensure your import statement is `import rfc3987_syntax`.
Use `rfc3987_syntax.parse_iri()` (or other `parse_` functions) within a `try-except lark.exceptions.UnexpectedInput` block to handle invalid input.
```python
import rfc3987_syntax
from lark.exceptions import UnexpectedInput
try:
rfc3987_syntax.parse_iri("http://example.com/path?query")
print("IRI is valid")
except UnexpectedInput:
print("IRI is invalid")
```Review the input string to ensure it adheres precisely to RFC 3987 syntax rules, paying attention to valid characters, structure, and component delimiters for the specific `parse_` function used.
Upgrade the `rfc3987-syntax` library to version 1.1.0 or newer using the command `pip install --upgrade rfc3987-syntax`.