Pure Python RFC 3986 Validator

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

rfc3986-validator is a pure Python library designed for validating Uniform Resource Identifiers (URIs) according to RFC 3986. It offers a single validation function. The library is currently at version 0.1.1, released in October 2019, and is designated as '2 - Pre-Alpha' development status, indicating a very inactive release cadence and experimental nature.

pip install rfc3986-validator
error ModuleNotFoundError: No module named 'rfc3986_validator'
cause The rfc3986-validator library is not installed in the current Python environment or the module name is misspelled.
fix
pip install rfc3986-validator
error ImportError: cannot import name 'validate' from 'rfc3986_validator'
cause The function name 'validate' does not exist in the 'rfc3986_validator' module; the correct function name is 'validate_uri'.
fix
from rfc3986_validator import validate_uri
error AttributeError: module 'rfc3986_validator' has no attribute 'validate'
cause After importing the 'rfc3986_validator' module, an attempt was made to call a non-existent attribute 'validate' instead of the correct function 'validate_uri'.
fix
import rfc3986_validator rfc3986_validator.validate_uri("http://example.com")
error TypeError: expected string or bytes-like object
cause The 'validate_uri' function received a non-string argument, but it expects a string or bytes-like object for URI validation.
fix
validate_uri("http://example.com") # Ensure the input is a string
gotcha This library is classified as '2 - Pre-Alpha' and has not seen updates since October 2019. Its long-term maintenance and compatibility with newer Python versions (beyond 3.8) are uncertain.
fix For actively maintained and feature-rich RFC 3986 validation, parsing, and building capabilities, consider using the `rfc3986` library (without the '-validator' suffix) which is at version 2.0.0 and actively developed.
gotcha The `rfc3986-validator` library provides a single `validate_rfc3986` function for basic URI validation. It does not offer granular control over URI components (like scheme, host, path, query) or methods for constructing URIs.
fix If your application requires more advanced URI handling, such as parsing components, building URIs, or custom validation rules (e.g., allowing only specific schemes or hosts), the `rfc3986` library offers `uri_reference`, `urlparse`, `validators.Validator` classes, and `URIBuilder` for these purposes.
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.04s 17.8M
3.10 alpine (musl) - - 0.05s 17.8M
3.10 slim (glibc) wheel 1.5s 0.02s 18M
3.10 slim (glibc) - - 0.03s 18M
3.11 alpine (musl) wheel - 0.10s 19.6M
3.11 alpine (musl) - - 0.12s 19.6M
3.11 slim (glibc) wheel 1.6s 0.09s 20M
3.11 slim (glibc) - - 0.10s 20M
3.12 alpine (musl) wheel - 0.06s 11.5M
3.12 alpine (musl) - - 0.07s 11.5M
3.12 slim (glibc) wheel 1.4s 0.08s 12M
3.12 slim (glibc) - - 0.08s 12M
3.13 alpine (musl) wheel - 0.06s 11.2M
3.13 alpine (musl) - - 0.07s 11.1M
3.13 slim (glibc) wheel 1.4s 0.06s 12M
3.13 slim (glibc) - - 0.07s 12M
3.9 alpine (musl) wheel - 0.03s 17.3M
3.9 alpine (musl) - - 0.04s 17.3M
3.9 slim (glibc) wheel 1.7s 0.03s 18M
3.9 slim (glibc) - - 0.03s 18M

The `validate_rfc3986` function checks if a given string conforms to the RFC 3986 URI syntax. It can also validate against specific rules like 'URI_reference'.

from rfc3986_validator import validate_rfc3986

# Validate a full URI
print(validate_rfc3986('http://example.com/path?query=val#fragment')) # Expected: True

# Validate a URI reference (e.g., relative path)
print(validate_rfc3986('//example.com/path', rule='URI_reference')) # Expected: True

# Example of an invalid URI
print(validate_rfc3986('http://foo.bar?q=Spaces should be encoded')) # Expected: False