Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

marshmallow_mongoengine_query_schema-1.3.tar.gz (4.7 kB view details)

Uploaded Source

File details

Details for the file marshmallow_mongoengine_query_schema-1.3.tar.gz.

File metadata

  • Download URL: marshmallow_mongoengine_query_schema-1.3.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for marshmallow_mongoengine_query_schema-1.3.tar.gz
Algorithm Hash digest
SHA256 59d0a6374c2f83e2cdaaa91e6827a98be0508cad440c8d3686b0761e7eeb2e50
MD5 7788be304267e10a11269317e5bc222b
BLAKE2b-256 66ba1b779660ca9238a66e0b6f83784583ff2ba11d6dfe98abfbfb2b2196a5ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page