Python URL Encode & Decode
Encode and decode URLs online — with Python urllib.parse examples, gotchas, and tips.
🔒 100% private — runs entirely in your browserEncode and decode URLs online — with Python urllib.parse examples, gotchas, and tips.
🔒 100% private — runs entirely in your browserPython's urllib.parse module provides functions for percent-encoding URLs and query parameters. It converts unsafe characters to %XX hex sequences so they can be safely included in URLs.
%20.application/x-www-form-urlencoded). Spaces become +.requests library handles URL encoding automatically via the params argument.from urllib.parse import quote text = "hello world & more"
encoded = quote(text)
print(encoded) # hello%20world%20%26%20morefrom urllib.parse import quote_plus query = "search term with spaces"
encoded = quote_plus(query)
print(encoded) # search+term+with+spacesfrom urllib.parse import urlencode params = { "q": "python url encode", "page": 1, "lang": "en"
}
query_string = urlencode(params)
print(query_string) # q=python+url+encode&page=1&lang=enimport requests # requests handles URL encoding automatically
response = requests.get( "https://api.example.com/search", params={"q": "hello world", "lang": "en"}
)
print(response.url)
# https://api.example.com/search?q=hello+world&lang=enfrom urllib.parse import unquote, unquote_plus encoded = "hello%20world%20%26%20more"
print(unquote(encoded)) # hello world & more form_encoded = "search+term+with+spaces"
print(unquote_plus(form_encoded)) # search term with spacesquote() encodes spaces as %20 (correct for URL paths). quote_plus() encodes spaces as + (correct for form data / query parameters). Using the wrong one causes subtle bugs.
By default, quote() does not encode /. To encode everything, use quote(string, safe=''). The safe parameter specifies characters that should NOT be encoded.
Encoding an already-encoded string creates double-encoding: %20 becomes %2520. Always check if input is already encoded before calling quote(). Use unquote() first if unsure.
In Python 2, URL encoding functions were in urllib (urllib.quote, urllib.urlencode). In Python 3, they moved to urllib.parse. If you see ImportError, check your Python version.
Use urllib.parse.quote(string) for path components or urllib.parse.quote_plus(string) for query parameters. quote() encodes spaces as %20, while quote_plus() encodes spaces as +.
quote() encodes spaces as %20 and is suitable for URL path segments. quote_plus() encodes spaces as + and is designed for application/x-www-form-urlencoded query parameters.
Use urllib.parse.unquote(string) to decode percent-encoded characters, or urllib.parse.unquote_plus(string) to also convert + back to spaces.
Use urllib.parse.urlencode(dict) to convert a dictionary to a query string like key1=value1&key2=value2. For the requests library, just pass a params dict to requests.get().
Yes. All encoding and decoding happens entirely in your browser using client-side JavaScript. Your data is never sent to any server.