Skip to content

Latest commit

 

History

History
42 lines (30 loc) · 1.33 KB

README.md

File metadata and controls

42 lines (30 loc) · 1.33 KB

Nested Query String Encoder

Build Status

Query string encoder that supports nested query strings in the format of Rack::Utils and Node qs.

Installation

install nested_query_string via pip:

pip install nested_query_string

Usage

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'

Gotchas

  1. 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