Marshmallow schema for generating mongoengine filters in url query.
Project description
Marshmallow Mongoengine Query Schema
Mongoengine filters in your API with no effort!
A marshmallow schema for use in url query which checks for possible mongoengine query filters (as well as only
and order_by
args)
and converts their types based on requirements for filters (eg. ints for number comparition operators)
and fields themselves (eg. list inner type when using for example list__0
)
Supports all mongoengine filters except geo queries
Note: This has nothing to do with marshmallow-mongoengine, I just couldn't think of better name
Usage:
from marshmallow_mongoengine_query_schema import QuerySchema
class SomeQuerySchema(QuerySchema):
__query_fields__ = SomeSchema().declared_fields
class Meta: # optional settings
query_enable_filters = False
query_enable_only = True
query_enable_order_by = False
query_allowed_infixes = ['__']
Usage in url:
example.com/someendpoint?no_comments=5&name__startswith=b&list__size=2&list__0=somestring
Every type is converted automatically but there's couple of things to point out:
When list type is needed, comma delimited list is used in url:
?list=a,b,c,d
match
operator and__raw__
are expecting a dictionary(json):?__raw__={"name": "hello"}
Installation
Very complicated black magic stuff:
pip3 install marshmallow_mongoengine_query_schema
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for marshmallow_mongoengine_query_schema-1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59d0a6374c2f83e2cdaaa91e6827a98be0508cad440c8d3686b0761e7eeb2e50 |
|
MD5 | 7788be304267e10a11269317e5bc222b |
|
BLAKE2b-256 | 66ba1b779660ca9238a66e0b6f83784583ff2ba11d6dfe98abfbfb2b2196a5ee |