Skip to content

fduseless/fast-params

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fast Params

Support Rails style QueryParams and FormData for Starlette and FastAPI.

you can also used it in other frameworks, if your params or forms follow this protocol.

@runtime_checkable
class MultiDict(Protocol):
    def multi_items(self) -> list[tuple[str, Any]]: ...

Install

pip install fast-params

Usage

from fast_params import ParamParser
from starlette.datastructures import MultiDict

def test_parse_simple():
    parser = ParamParser()
    params = MultiDict({
        "a": 1,
        "b": 2
    })
    expect = {
        "a": 1,
        "b": 2
    }
    assert parser(params) == expect

def test_array():
    parser = ParamParser()
    params = MultiDict([
        ("a", 1),
        ("b[]", 2),
        ("c[d]", 3),
        ("c[f]", 4),
        ("f[d][]", 5),
        ("f[d][]", 6),
    ])
    expect = {
        "a": 1,
        "b": [2],
        "c": {
            "d": 3,
            "f": 4
        },
        "f": {
            "d": [5, 6]
        }
    }
    assert parser(params) == expect

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages