Skip to main content

Crate urlparse_rs

Crate urlparse_rs 

Source
Expand description

A Rust port of Python’s urllib.parse.

Port target: the standard library urllib/parse.py (CPython 3.13). Behaviour is verified against the reference module itself across a large corpus via differential testing.

Surface: the percent-encoding layer (quote, quote_plus, quote_from_bytes, unquote, unquote_plus, unquote_to_bytes) and the URL splitting/joining layer (urlsplit, urlunsplit, urlparse, urlunparse, urljoin, urldefrag, parse_qs/parse_qsl, urlencode), including the SplitResult/ParseResult netloc accessors and urlsplit’s full authority validation — bracketed IPv6/IPvFuture hosts plus the NFKC homograph check on non-ASCII authorities (_checknetloc). That NFKC pass is the crate’s one dependency (unicode-normalization, as used by url/idna), since Rust std has no Unicode normalization. See STATUS.md.

Like urllib.parse, percent-encoding works on bytes: a str is first encoded as UTF-8, every byte that is not “always safe” (A-Z a-z 0-9 _ . - ~) or in the caller’s safe set becomes %XX (uppercase hex), and decoding reverses it (UTF-8, replacing invalid sequences).

Structs§

DefragResult
A URL split into its defragmented part and its fragment, as returned by urldefrag. Port of DefragResult.
ParseResult
The six components of a URL, as returned by urlparse. Port of ParseResult (like SplitResult but with a ;params field split out of the path).
SplitResult
The five components of a URL, as returned by urlsplit. Port of SplitResult.
UrlError
Error raised by the parsing functions, mirroring the ValueErrors in urllib.parse.

Functions§

parse_qs
Parse a query string into a list of (name, values) entries (insertion order, values grouped per name). Port of parse_qs (which returns a dict). See parse_qsl for the arguments.
parse_qsl
Parse a query string into a list of (name, value) pairs. Port of parse_qsl.
quote
Percent-encode a string. Letters, digits and _.-~ are never quoted; everything else outside safe becomes %XX. The string is encoded as UTF-8 first. Port of quote (str input).
quote_from_bytes
Like quote, but takes a byte slice directly and does no string-to-bytes encoding. Always returns an ASCII string. Port of quote_from_bytes.
quote_plus
Like quote, but also encodes ' ' as '+', as required for HTML form values. Port of quote_plus (Python defaults safe to "").
unquote
Replace %xx escapes by their character equivalent, decoding as UTF-8 with invalid sequences replaced by U+FFFD (Python’s errors='replace'). Port of unquote.
unquote_plus
Like unquote, but also replaces '+' with ' ', as required for HTML form values. Port of unquote_plus.
unquote_to_bytes
Replace %xx escapes by the bytes they encode. Port of unquote_to_bytes (the input string is encoded as UTF-8 first).
urldefrag
Remove the fragment from a URL, returning the defragmented URL and the fragment. Port of urldefrag.
urlencode
Encode a sequence of (key, value) pairs into a key=value&... query string, with each part run through quote_plus. Port of urlencode (with doseq=False, the default quote_plus).
urlencode_doseq
Like urlencode, but each key maps to a sequence of values, emitting one key=value pair per element. Port of urlencode with doseq=True.
urljoin
Join a base URL and a possibly-relative URL into an absolute one. Port of urljoin.
urlparse
Parse a URL into 6 components: scheme://netloc/path;params?query#fragment. Port of urlparse. Like urlsplit, but also splits ;params off the path for schemes in uses_params.
urlsplit
Parse a URL into 5 components: scheme://netloc/path?query#fragment. Port of urlsplit.
urlunparse
Combine 6 URL components into a string. Port of urlunparse.
urlunsplit
Combine 5 URL components into a string. Port of urlunsplit.