import urllib.parse
qsdata = 'test=test&test2=test2&test2=test3'
qs = dict((k, v if len(v) > 1 else v[0]) for k, v in urllib.parse.parse_qs(
    qsdata).items())
print(qs)
How to stop Python parse_qs from parsing single values into lists?