PyDocs

Internet Protocols and Support

urllib.parse

Parse (absolute and relative) URLs.

urllib.parse module is based upon the following RFC specifications.

RFC 3986 (STD66): "Uniform Resource Identifiers" by T. Berners-Lee, R. Fielding
and L.  Masinter, January 2005.

RFC 2732 : "Format for Literal IPv6 Addresses in URL's by R.Hinden, B.Carpenter
and L.Masinter, December 1999.

RFC 2396:  "Uniform Resource Identifiers (URI)": Generic Syntax by T.
Berners-Lee, R. Fielding, and L. Masinter, August 1998.

RFC 2368: "The mailto URL scheme", by P.Hoffman , L Masinter, J. Zawinski, July 1998.

RFC 1808: "Relative Uniform Resource Locators", by R. Fielding, UC Irvine, June
1995.

RFC 1738: "Uniform Resource Locators (URL)" by T. Berners-Lee, L. Masinter, M.
McCahill, December 1994

RFC 3986 is considered the current standard and any future changes to
urllib.parse module should conform with it.  The urllib.parse module is
currently not entirely compliant with this RFC due to defacto
scenarios for parsing, and for backward compatibility purposes, some
parsing quirks from older RFCs are retained. The testcases in
test_urlparse.py provides a good indicator of parsing behavior.

The WHATWG URL Parser spec should also be considered.  We are not compliant with
it either due to existing user code API behavior expectations (Hyrum's Law).
It serves as a useful guide when making changes.
Symbols in urllib.parse

d

DefragResult
Concrete class for urldefrag() results containing str data.
DefragResultBytes
Concrete class for urldefrag() results containing bytes data.

p

parse_qs
Parse a query given as a string argument.
parse_qsl
Parse a query given as a string argument.
ParseResult
Concrete class for urlparse() results containing str data.
ParseResultBytes
Concrete class for urlparse() results containing bytes data.

q

quote
Each part of a URL, e.g.
quote_from_bytes
Like quote(), but accepts a bytes object rather than a str, and does not perform string-to-bytes encoding.
quote_plus
Like quote(), but also replace ' ' with '+', as required for quoting HTML form values.

s

SplitResult
Concrete class for urlsplit() results containing str data.
SplitResultBytes
Concrete class for urlsplit() results containing bytes data.

u

unquote
Replace %xx escapes by their single-character equivalent.
unquote_plus
Like unquote(), but also replace plus signs by spaces, as required for unquoting HTML form values.
unquote_to_bytes
unquote_to_bytes('abc%20def') -> b'abc def'.
unwrap
Transform a string like '<URL:scheme://host/path>' into 'scheme://host/path'.
urldefrag
Removes any existing fragment from URL.
urlencode
Encode a dict or sequence of two-element tuples into a URL query string.
urljoin
Join a base URL and a possibly relative URL to form an absolute interpretation of the latter.
urllib.parse.SplitResult.geturl
Return the re-combined version of the original URL as a string.
urlparse
Parse a URL into 6 components: <scheme>://<netloc>/<path>;<params>?<query>#<fragment>
urlsplit
Parse a URL into 5 components: <scheme>://<netloc>/<path>?<query>#<fragment>
urlunparse
Put a parsed URL back together again.
urlunsplit
Combine the elements of a tuple as returned by urlsplit() into a complete URL as a string.