[Python] Read query parameters from a URL

Created on November 30, 2026

Use urlsplit(url).query to extract the query string, then pass it to parse_qs() to get a dictionary of parameters.

from urllib.parse import parse_qs, urlsplit

url = 'https://example.com/search?q=hello+world&tag=python&tag=web&empty='
query = urlsplit(url).query
params = parse_qs(query)

print(params)
print(params['q'][0])
{'q': ['hello world'], 'tag': ['python', 'web']}
hello world

Each value is a list, even when the parameter occurs once. Repeated values appear in their original order, and + becomes a space.

Blank values are omitted by default. Pass keep_blank_values=True to keep a parameter such as empty=.

params = parse_qs(query, keep_blank_values=True)
print(params['empty'])
['']
Python