Skip to main content

mongo query as a predicate function

Project description

mgqpy

codecov

MongoDB query as a predicate function

This aims to be consistent with how MongoDB's matches documents. This includes traversal across nested dicts and lists, None and field-presence/absence handling.

Installation

pip install mgqpy

Usage

from mgqpy import Query

predicate = Query({"foo.bar": {"$gt": 1}})

inputs = [
    {"foo": [{"bar": [1, 2]}]},
    {"foo": {"bar": 1}},
    {"foo": {"bar": 2}},
    {"foo": None},
]

filtered = filter(predicate.match, inputs)

assert list(filtered) == [
    {"foo": [{"bar": [1, 2]}]},
    {"foo": {"bar": 2}},
]

Supported operators

Comparison query operators

  • $eq
  • $eq (implicit), e.g. {"foo": None}
  • $ne
  • $gt
  • $gte
  • $lt
  • $lte
  • $in
  • $nin

Logical query operators

  • $and
  • $and (implicit), e.g. {"foo": 1, "bar": "baz"}
  • $or
  • $not
  • $nor

Evaluation query operators

  • $regex
  • $regex (implicit), e.g. {"foo": re.compile('^bar')}
  • $mod

Array query operators

  • $all
  • $elemMatch
  • $size

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

mgqpy-0.5.1.tar.gz (89.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mgqpy-0.5.1-py2.py3-none-any.whl (4.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file mgqpy-0.5.1.tar.gz.

File metadata

  • Download URL: mgqpy-0.5.1.tar.gz
  • Upload date:
  • Size: 89.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for mgqpy-0.5.1.tar.gz
Algorithm Hash digest
SHA256 0cef58b49b4b9f9a18b711680e7aed3f3be45184bd326d1b2ec92c9bba680acf
MD5 d2df27bc903eef28c5ab059dde8ea396
BLAKE2b-256 e8597224c8850277c7aff005a5253f035cd29f88c156bd5805da209d6c4cfc43

See more details on using hashes here.

File details

Details for the file mgqpy-0.5.1-py2.py3-none-any.whl.

File metadata

  • Download URL: mgqpy-0.5.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for mgqpy-0.5.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1baca10ee3ab8fdf679f9ca2930fcf29c800bec413f7563e775f4abc56d37f09
MD5 6a03915fff32b4128ad90a49229fbb55
BLAKE2b-256 6445aa5b3dd4a4839c1d5e12000221a7192cd86a09cf76792c6aed759e41393b

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