URL Encoder/Decoder — Developer Code Samples

URL encoding (percent-encoding) replaces unsafe characters with a % followed by two hex digits. Python's urllib.parse, JavaScript's encodeURIComponent, and curl handle URL encoding natively with no external packages needed.

Try the interactive version online: Open URL Encode/Decode Tool →

Parameters

Parameter Type Required Description
text str Yes String to URL-encode or URL-decode
safe str No Characters to leave unencoded (default: empty string)
encoding str No Character encoding (default: utf-8)

Returns: Percent-encoded URL string, or decoded original string

Code Examples

from urllib.parse import quote, unquote, quote_plus, unquote_plus, urlencode, urlparse

# Encode a URL component (query parameter value)
text = "hello world & more=stuff"
encoded = quote(text)
print(encoded)
# Output: hello%20world%20%26%20more%3Dstuff

# Use quote_plus for form data (spaces become +)
form_encoded = quote_plus(text)
print(form_encoded)
# Output: hello+world+%26+more%3Dstuff

# Decode percent-encoded string
decoded = unquote("hello%20world%20%26%20more%3Dstuff")
print(decoded)
# Output: hello world & more=stuff

# Build a URL with encoded query parameters
params = {"name": "Alice Smith", "city": "New York", "age": 30}
query_string = urlencode(params)
print(f"https://example.com/search?{query_string}")
# Output: https://example.com/search?name=Alice+Smith&city=New+York&age=30

# Parse a URL into components
url = "https://example.com/path?key=val&other=test#anchor"
parsed = urlparse(url)
print(parsed.scheme, parsed.netloc, parsed.path, parsed.query)