• Stars
    star
    138
  • Rank 264,508 (Top 6 %)
  • Language
    Python
  • License
    MIT License
  • Created over 13 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

QueryString parser for Python/Django that correctly handles nested dictionaries

querystring-parser

https://travis-ci.org/bernii/querystring-parser.svg?branch=master

This repository hosts the query string parser for Python/Django projects that correctly creates nested dictionaries from sent form/querystring data.

When to use it?

Lets say you have some textfields on your webpage that you wish to get as dictionary on the backend. The querystring could look like:

section[1]['words'][2]=a&section[0]['words'][2]=a&section[0]['words'][2]=b

Standard django REQUEST (QueryDict) variable will contain:

<QueryDict: {u"section[1]['words'][2]": [u'a'], u"section[0]['words'][2]": [u'a', u'b']}>

As you see it doesn't really convert it to dict. Instead of elegant dictionary you have a string called "section[1]['words'][2]" and "section[0]['words'][2]" and if you want to do something with it, you'll need to parse it (sic!).

When using querystring-parser the output will look like:

{u'section': {0: {u'words': {2: [u'a', u'b']}}, 1: {u'words': {2: u'a'}}}}

Tadam! Everything is much simpler and more beautiful now :)

Efficiency:

Test made using timeit show that in most cases speed of created library is similar to standard Django QueryDict parsing speed. For query string containing multidimensional complicated arrays querystring-parser is significantly slower. This is totally understandable as created library creates nested dictionaries in contrary to standard Django function which only tokenizes data. You can see results below. Edit: Actually parsing is done by urlparse.parse_qs so I've added it to tests.

Test string nr  querystring-parser     Django QueryDict       parse_qs
0               2.75077319145          3.44334220886          0.582501888275
Test string nr  querystring-parser     Django QueryDict       parse_qs
1               10.1889920235          10.2983090878          2.08930182457
Test string nr  querystring-parser     Django QueryDict       parse_qs
2               0.613747119904         1.21649289131          0.283004999161
Test string nr  querystring-parser     Django QueryDict       parse_qs
3               0.107316017151         0.459388017654         0.0687718391418
Test string nr  querystring-parser     Django QueryDict       parse_qs
4               0.00291299819946       0.169251918793         0.0170118808746

Test #1 Is most interesting as is contains nested dictionaries in query string.

Installation:

Install using pip.

pip install querystring-parser

How to use:

Just add it to your Django project and start using it.

from querystring_parser import parser
post_dict = parser.parse(request.POST.urlencode())

License:

  • MIT License

More Repositories

1

gauge.js

100% native and cool looking JavaScript gauge
JavaScript
1,417
star
2

django-reservations

Django module for handling reservations/booking
Python
150
star
3

IrisRecognition

Old iris recognition software I made with my friend. It uses Hough and Gabor transforms to make things happen.
89
star
4

tornado-acl

Access Control List for Tornado (or just plain Python)
Python
29
star
5

embedded-graphics-framebuf

Generic framebuffer implementation in Rust for use with embedded-graphics library
Rust
26
star
6

android-django-aes

Code snippets for communication between Android(Java) device and Django(python) with AES ecrypted data
Java
20
star
7

python-media-crawler

Simple Python web crawler that looks through websites for media files (mp3, wma, aac.) and extracts their metadata
Python
19
star
8

BarcodePrinter

A simple, configurable barcode (CODE-128) PDF printer/generator
Python
11
star
9

sataddress-rs

Federated Lightning Network addresses server.
Rust
9
star
10

NeuralNetwokPerceptronKohonen

Implementation of neural networks in Java: Kohonen and Perceptron with backpropagation algorithm
Java
8
star
11

yummy-pasta

Pasta is so yummy
JavaScript
5
star
12

PyQRNativeGAE

Native python QR Code generator for Google App Engine
Python
5
star
13

embedded-graphics-sparklines

Lightweight graphs (sparklines) for use with Embedded Rust
Rust
5
star
14

OpenBciP300

Open Brain Computer Interface project using P300 paradigm
Java
5
star
15

python-num-variations-pl

Plural forms of polish words in python for Django
Python
2
star
16

BrainboyMobile

A simple app to improve your brain abilities. Inspired by BrainBoy hardware device.
Java
1
star
17

django-registration-links

A simple Django module for invite-only registration with unique access links
Python
1
star
18

python-101

Some things that are done 'pythonic' way
Python
1
star
19

select-variants.js

Variant Selector Widget
CoffeeScript
1
star