qstring

qstring is a Python library that allows you to create nested objects from a list of querystring parameters.

Installation

Use pip to install from PyPI:

pip install qstring

Contributing

To contribute to qstring create a fork on GitHub. Clone your fork, make some changes, and submit a pull request.

API Documentation

qstring.nest(params)

Create a nested object from a list of query string parameters.

Examples:

>>> nest([('foo[bar]', 'baz')])
{'foo': {'bar': 'baz'}}

>>> nest([('x[y]', '1'), ('x[y]', '2')])
{'x': {'y': ['1', '2']}}
Parameters:params – a list of query string parameter where each item is a tuple representing a key-value pair.
Raises:qstring.ParameterTypeError – if parameters of conflicting types are given.
qstring.unnest(obj)

Create a list of query string parameters from a nested object.

Examples:

>>> unnest({'foo': {'bar': 'baz'}})
[('foo[bar]', 'baz')]

>>> unnest({'x': {'y': ['1', '2']}})
[('x[y]', '1'), ('x[y]', '2')]
exception qstring.ParameterTypeError

This error is raised when nest() encounters parameters with conflicting types.

Changelog

0.2.1 (March 24, 2017)

  • Fixed qstring.unnest when values contain non-ASCII characters.

0.2.0 (September 1, 2015)

  • Changed qstring.nest to maintain the order of the given parameters in the returned nested object by returning OrderedDict instead of dict.

0.1.0 (July 14, 2015)

  • Initial public release.

License

The MIT License (MIT)

Copyright (c) 2015 Fast Monkeys Oy

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.