Query string encoder that supports nested query strings in the format of Rack::Utils and Node qs.
install nested_query_string via pip:
pip install nested_query_string
import nested_query_string
from nested_query_string import NestedQueryString
NestedQueryString.encode({'abc': 'def', 'ghi': 1})
# => 'abc=def&ghi=1'
# with nested list
NestedQueryString.encode({'abc': ['def', 'ghi']})
# => 'abc[]=def&abc[]=ghi'
# with nested dictionary
NestedQueryString.encode({'abc': {'def': 'ghi', 'jkl': 'mno'}, 'pqr': 'stu'})
# => 'abc[def]=ghi&abc[jkl]=mno&pqr=stu'
- The parameters are not guaranteed to be in a specific order.
- This library doesn't handle stringifing dates or other classes. If you're worried about sending unsupported classes as values, surround with a try/except:
import nested_query_string from nested_query_string import NestedQueryString, UnsupportedParameterClassException try: NestedQueryString.encode({'abc': NestedQueryString}) except UnsupportedParameterClassException: # handle exception