Skip to main content
File added late

1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.

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

[![Build Status](https://secure.travis-ci.org/aventurella/pyquerystring.png?branch=master)](http://travis-ci.org/aventurella/pyquerystring)

## The Problem

Python's default:

```python
from urlparse import parse_qsl
from urlparse import parse_qs
```

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

&dog=lucy&dog=tucker&dog=radar&id=11

*parse_qs* will return something like this:

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

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

&dog[0]=lucy&dog[1]=tucker&dog[2]=radar&id=11

*parse_qs* will give you back something like:

```json
{"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:

```python
from querystring import QueryStringParser

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

if __name__ == "__main__":
main()
```

In other words, you get this:

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

&id=foo&dog[0][0]=lucy&dog[0][1]=radar&dog[1][0]=tucker&dog[1][1]=dexter

even 3 dimensional arrays:

&id=foo&dog[0][0][0]=lucy&dog[0][0][1]=radar&dog[0][0][2]=tucker

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

&id=foo&dog[2]=dexter&dog[1]=tucker&dog[0]=lucy&cat=ollie&pets[1].name=pogo&pets[1].type=catz&pets[0].name=kiki&pets[0].type=cat&fish.name=robofish&fish.type=fishz&person.name[0]=adam&person.name[1]=adamz&plants.name[0][1]=flower&plants.name[0][0]=tree&plants.name[1][0]=willow&plants.name[1][1]=fern

You can also do some primitive array pushing:

&id=foo&dog[]=radar&dog[]=lucy&dog[]=tucker

Or push into an object:

&id=foo&dog.name[]=radar&dog.name[]=tucker&dog.name[]=lucy

And you would get:

```json
{"id":"foo",
"dog":{"name":["radar", "tucker", "lucy"]}
}
```
Anyway, I think you get the idea. Crack open tests/test_parser.py 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.

Metadata

Release files for pyquerystring 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

File added late

1 file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release files before installing.

Source distribution (sdist)

Source distribution for pyquerystring 0.1
File Size Uploaded
pyquerystring-0.1.tar.gz 3.7 kB Details

Release files / pyquerystring-0.1.tar.gz

File added late

This file was uploaded more than 14 days after the first file in this release.

While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.

We recommend inspecting the release file before installing.

Download URL pyquerystring-0.1.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
288d42ee81347c22a983586a855ccd800978b7e2a3cfef365129cc76f27952c7
BLAKE2b-256 checksum
How to use checksums
ce70caa4c5600d02b6a7a3b345b21da16f521402766d634bcc600278bd081bb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.1

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.2

1 release file

0.1.1

1 release file

This release

0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page