Skip to content

cine-io/nested-query-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A querystring encoder with nesting support

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages