The data is UTF-8 encoded bytes escaped with URL quoting, so you want to decode, with urllib.parse.unquote(), which handles decoding from percent-encoded data to UTF-8 bytes and then to text, transparently:

from urllib.parse import unquote

url = unquote(url)

Demo:

>>> from urllib.parse import unquote
>>> url = 'example.com?title=%D0%BF%D1%80%D0%B0%D0%B2%D0%BE%D0%B2%D0%B0%D1%8F+%D0%B7%D0%B0%D1%89%D0%B8%D1%82%D0%B0'
>>> unquote(url)
'example.com?title=правовая+защита'

The Python 2 equivalent is urllib.unquote(), but this returns a bytestring, so you'd have to decode manually:

from urllib import unquote

url = unquote(url).decode('utf8')
Answer from Martijn Pieters on Stack Overflow
🌐
Python
docs.python.org › 3 › library › urllib.parse.html
urllib.parse — Parse URLs into components
Source code: Lib/urllib/parse.py This module defines a standard interface to break Uniform Resource Locator (URL) strings up in components (addressing scheme, network location, path etc.), to combi...
🌐
URLDecoder
urldecoder.io › python
URL Decoding query strings or form parameters in Python | URLDecoder
In this article, you'll learn how to decode/parse URL query strings or Form parameters in Python 3.x and Python 2.x.
🌐
GitHub
gist.github.com › nkentaro › 37f25b802e825da7ab3b7f27c0303047
url encode and decode in python3 · GitHub
The quote() function encodes space to . Python also has a quote_plus() function that encodes space to plus sign (+). I've written about URL Encoding in python on my website.
🌐
DEV Community
dev.to › k4ml › python-urldecode-on-command-line-2ek9
Python urldecode on command line - DEV Community
December 2, 2018 - #python #bash · I have some logs that contain url with encoded characters and I need to extract some data out of the urls. Searching around lead me to this stackexchange's answer:- alias urldecode='python3 -c "import sys, urllib.parse as ul;print(ul.unquote_plus(sys.argv[1]))"' Then you can use it as:- urldecode '"status":"SUCCESS"' "status":"SUCCESS" Now that's perfect.
🌐
URL Decode
urldecoder.org › dec › python
URL Decoding of "python" - Online
Decode python from URL-encoded format with various advanced options. Our site has an easy to use online tool to convert your data.
Find elsewhere
🌐
FusionAuth
fusionauth.io › docs › dev-tools › url-encoder-decoder
URL Encoder/Decoder | FusionAuth Docs
Python: urllib.parse.unquote() Java: java.net.URLDecoder and java.net.URLEncoder · It's important to use URL decoding when processing received data that may have been URL-encoded. This ensures that the data is correctly interpreted. However, it's also crucial to consider potential security risks, as decoding URLs can potentially lead to injection attacks if not handled carefully.
🌐
Waylon Walker
waylonwalker.com › thought-26
💭 URL Decoding query strings or form parameters in Python | URLD... | Waylon Walker
July 28, 2023 - !https://www.urldecoder.io/python/ ... in Python | URLDecoder · URL Decode online. URLDecoder is a simple and easy to use online tool for decoding URL components....
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.sql › api › pyspark.sql.functions.url_decode.html
pyspark.sql.functions.url_decode — PySpark 4.1.2 documentation
URL function: Decodes a URL-encoded string in ‘application/x-www-form-urlencoded’ format to its original format · New in version 3.5.0
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-urlencode-a-querystring-in-python
How to Urlencode a Querystring in Python? - GeeksforGeeks
July 23, 2025 - import urllib.parse data = { "site": "GeeksforGeeks", "topic": "Python URL encoding", "level": "Intermediate" } encoded_data = '&'.join([f"{urllib.parse.quote_plus(key)}={urllib.parse.quote_plus(value)}" for key, value in data.items()]) print(encoded_data)
🌐
Urldecoder
urldecoder.net › python-urldecode
Python unqoute() - URL Decode
We cannot provide a description for this page right now
🌐
Python
docs.python.org › 3 › library › urllib.request.html
urllib.request — Extensible library for opening URLs
Source code: Lib/urllib/request.py The urllib.request module defines functions and classes which help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirection...
🌐
Testmuai
testmuai.com › testmu ai › blog › how to use python url decode() method in selenium | testmu ai
How to Use Python URL Decode() Method In Selenium | TestMu AI (Formerly LambdaTest)
Learn how to use the Python URL decode() method to manage the URLs to maintain security and improve the web development and testing process.
Published   December 26, 2025
🌐
PyPI
pypi.org › project › urldecode
urldecode · PyPI
URLDecode is to decode an encoded url
      » pip install urldecode
    
Published   Apr 01, 2012
Version   0.1
🌐
URLDecoder
urldecoder.io
URL Decode Online | URLDecoder
URL Decode online. URLDecoder is a simple and easy to use online tool for decoding URL components. Get started by typing or pasting a URL encoded string in the input text area, the tool will automatically decode your URL in real time.
🌐
Python.org
discuss.python.org › ideas
Speed up urllib.parse - Ideas - Discussions on Python.org
December 8, 2023 - Hello. Are there any plans to speed up urlib.parse? I mean, it’s used a lot in web apps and I feel it’s CPython’s weak side on the web for decades. There are some efforts out there trying to rewrite it with C. But I t…
Top answer
1 of 16
184

Found these Python one liners that do what you want:

Python2

$ alias urldecode='python -c "import sys, urllib as ul; \
    print ul.unquote_plus(sys.argv[1])"'

$ alias urlencode='python -c "import sys, urllib as ul; \
    print ul.quote_plus(sys.argv[1])"'

Python3

$ alias urldecode='python3 -c "import sys, urllib.parse as ul; \
    print(ul.unquote_plus(sys.argv[1]))"'

$ alias urlencode='python3 -c "import sys, urllib.parse as ul; \
    print (ul.quote_plus(sys.argv[1]))"'

Example

$ urldecode 'q+werty%3D%2F%3B'
q werty=/;

$ urlencode 'q werty=/;'
q+werty%3D%2F%3B

References

  • Urlencode and urldecode from a command line
2 of 16
89

sed

Try the following command line:

$ sed 's@+@ @g;s@%@\\x@g' file | xargs -0 printf "%b"

or the following alternative using echo -e:

$ sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' file | xargs echo -e

Note: The above syntax may not convert + to spaces, and can eat all the newlines.


You may define it as alias and add it to your shell rc files:

$ alias urldecode='sed "s@+@ @g;s@%@\\\\x@g" | xargs -0 printf "%b"'

Then every time when you need it, simply go with:

$ echo "http%3A%2F%2Fwww" | urldecode
http://www

Bash

When scripting, you can use the following syntax:

input="http%3A%2F%2Fwww"
decoded=$(printf '%b' "${input//%/\\x}")

However above syntax won't handle pluses (+) correctly, so you've to replace them with spaces via sed or as suggested by @isaac, use the following syntax:

decoded=$(input=${input//+/ }; printf "${input//%/\\x}")

You can also use the following urlencode() and urldecode() functions:

urlencode() {
    # urlencode <string>
    local length="${#1}"
    for (( i = 0; i < length; i++ )); do
        local c="${1:i:1}"
        case $c in
            [a-zA-Z0-9.~_-]) printf "$c" ;;
            *) printf '%%%02X' "'$c" ;;
        esac
    done
}
 
urldecode() {
    # urldecode <string>
 
    local url_encoded="${1//+/ }"
    printf '%b' "${url_encoded//%/\\x}"
}

Note that above urldecode() assumes the data contains no backslash.

Here is similar Joel's version found at: https://github.com/sixarm/urldecode.sh


bash + xxd

Bash function with xxd tool:

urlencode() {
  local length="${#1}"
  for (( i = 0; i < length; i++ )); do
    local c="${1:i:1}"
    case $c in
      [a-zA-Z0-9.~_-]) printf "$c" ;;
    *) printf "$c" | xxd -p -c1 | while read x;do printf "%%%s" "$x";done
  esac
done
}

Found in cdown's gist file, also at stackoverflow.


PHP

Using PHP you can try the following command:

$ echo oil+and+gas | php -r 'echo urldecode(fgets(STDIN));' // Or: php://stdin
oil and gas

or just:

php -r 'echo urldecode("oil+and+gas");'

Use -R for multiple line input.


Perl

In Perl you can use URI::Escape.

decoded_url=$(perl -MURI::Escape -e 'print uri_unescape($ARGV[0])' "$encoded_url")

Or to process a file:

perl -i -MURI::Escape -e 'print uri_unescape($ARGV[0])' file

awk

Try anon solution:

awk -niord '{printf RT?$0chr("0x"substr(RT,2)):$0}' RS=%..

Note: Parameter -n is specific to GNU awk.

Try Stéphane Chazelas urlencode solution:

awk -v RS='&#[0-9]+;' -v ORS= '1;RT{printf("%%%02X", substr(RT,3))}'

See: Using awk printf to urldecode text.

decoding file names

If you need to remove url encoding from the file names, use deurlname tool from renameutils (e.g. deurlname *.*).

See also:

  • Can wget decode uri file names when downloading in batch?
  • How to remove URI encoding from file names?

Related:

  • How to decode URL-encoded string in shell? at SO
  • How can I encode and decode percent-encoded strings on the command line? at Ask Ubuntu