Skip to main content

Fancy query string parsing & application/x-www-form-urlencoded parsing

Project description

# Fancy Query String or application/x-www-form-urlencoded parsing

[![Build Status](](

## The Problem

Python's default:

from urlparse import parse_qsl
from urlparse import parse_qs

does not understand the concept of data structures. When given a query string of:


*parse_qs* will return something like this:

{"dog":["lucy", "tucer", "radar"], "id":[11]}

This is perfect for simple things. If you wanted to communicate a more complex data structure:


*parse_qs* will give you back something like:

{"dog[0]":["lucy"], "dog[1]":["tucker"], "dog[2]":["radar"], "id":[11]}

Not exactly what was described by the query string. But that's ok, if you need fancier query strings or application/x-www-form-urlencoded parsing this library to the rescue.

## How it works

Lets try some code:

from querystring import parse

def __main__():
qs = "&id=foo&dog[0].name=lucy&dog[1].name=radar"
result = parse(qs)
print(result["dog"][0]["name"]) #lucy
print(result["dog"][1]["name"]) #radar

if __name__ == "__main__":

In other words, you get this:

"dog":[{"name":"lucy"}, {"name":"radar"}]
You can get pretty crazy with it as well. It will handle multidimensional arrays:


even 3 dimensional arrays:


Or you can go totally nuts and just throw some mixed madness at it:


You can also do some primitive array pushing:


Or push into an object:


And you would get:

"dog":{"name":["radar", "tucker", "lucy"]}
Anyway, I think you get the idea. Crack open tests/ if you would like to see some additional examples.

P.S. You could apply this to multipart parsing as well, you would just need to extract the parts that are not files, and hand them to this query string parser.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyquerystring-0.4.0.tar.gz (4.6 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page