Networking and Internet Modules

urllib.parse

Splits, joins and quotes URL components and encodes query parameters. urlsplit does not validate whether a URL is safe to fetch. urljoin can replace the original host when given an absolute URL, so validate untrusted destinations separately.

Formal Syntax & Structure

python syntaxpython
import urllib.parse

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from urllib.parse import urlsplit, parse_qsparts = urlsplit("https://example.invalid/search?q=tea")print(parts.hostname, parse_qs(parts.query)["q"][0])
Python Reference