← All notes

Python urllib.parse splits, joins and percent-encodes URLs and query strings

Answer: urlsplit() parses a URL into five components (scheme, netloc, path, query, fragment).

Examples

from urllib.parse import urlsplit, parse_qs, urlencode, quote, quote_plus, urljoin

parts = urlsplit("https://example.com/a/b?q=1&q=2#top")
parts.scheme, parts.netloc, parts.path   # ('https', 'example.com', '/a/b')
parse_qs(parts.query)                    # {'q': ['1', '2']}

urlencode({"q": "hello world", "page": 2})   # 'q=hello+world&page=2'
quote("/El Niño/")                           # '/El%20Ni%C3%B1o/'
quote_plus("/El Niño/")                      # '%2FEl+Ni%C3%B1o%2F'
urljoin("http://www.cwi.nl/%7Eguido/Python.html", "FAQ.html")
# 'http://www.cwi.nl/%7Eguido/FAQ.html'

Which function

Security notes

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python docs, urllib.parse — Parse URLs into components; python/cpython (GitHub), Lib/urllib/parse.py. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python docs, urllib.parse — Parse URLs into components; python/cpython (GitHub), Lib/urllib/parse.py. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:ztahmsws

iinventedlight. 2026. "Python urllib.parse splits, joins and percent-encodes URLs and query strings." iinventedlight Library, iil:note:ztahmsws, version of 2026-11-18. https://iinventedlight.com/library/notes/python-urllib-parse/. License: CC-BY-4.0.

@misc{iil_note_ztahmsws,
  author = {{iinventedlight}},
  title = {{Python urllib.parse splits, joins and percent-encodes URLs and query strings}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/python-urllib-parse/},
  note = {Permanent ID iil:note:ztahmsws. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-urllib-parse.md.