Skip to main content

Query pattern of containers of objects

Project description

SimpleQuery

query from containers of objects, in Python

Query pattern

The Query pattern uses criteria on classes and fields to retrieve value objects from a dataset. Those criteria are a field, an operator, and a value. For example, ('last_name', =, 'Fowler') or ('price', <, 100.00).

Installation

pip install simple-query

Usage

all() returns the matching objects for a query, and filter(*criteria) returns a new, filtered query, where criteria = field, operator, value.

For example:

from simple_query.query import Query
from operator import eq, gt, lt

people = [
    Person('Ada Lovelace'),
    Person('Grace Hopper'),
    Person('Jean Bartik')]

Query(people).all()
# [Person('Ada Lovelace'), Person('Grace Hopper'), Person('Jean Bartik')]

Query(people).filter('last_name', eq, 'Lovelace').all()
# [Person('Ada Lovelace')]

Query(people) \
    .filter('first_name', gt, 'B') \
    .filter('last_name', lt, 'C').all()
# [Person('Jean Bartik')]

Setting up development environment

It is always recommended to use a virtual environment for each Python appplication. Create the environment once, after cloning this repository to your machine.

python3 -m venv .env

For each terminal session going forward, work on the virtual environment and use its copy of python.

source .env/bin/activate

Upgrade pip

pip install -U pip

Install developer requirements for a nicer test runner (see Running Tests)

pip install -r requirements/dev.txt

Running tests

Tests are written in unittest syntax, so no additional package are needed to run them

python -m unittest discover

For a more informative output, as well as plugins for color and watch mode, use nose test runner. You can also use the test runner of your choice.

nosetests --rednose --with-watch

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

simple_query-0.0.2.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

simple_query-0.0.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file simple_query-0.0.2.tar.gz.

File metadata

  • Download URL: simple_query-0.0.2.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for simple_query-0.0.2.tar.gz
Algorithm Hash digest
SHA256 95f262f24ddebdc7c186275be831c829d78fb2ba1e11d45a7f6535aea655842b
MD5 c2e502288016309dc024feb0509b1cec
BLAKE2b-256 48e71c9f37231d34cf628a2ed889af675e53928d6b0203e4495d58cdfffc5bf9

See more details on using hashes here.

File details

Details for the file simple_query-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: simple_query-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for simple_query-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1a32c683fbc95f850dcbe5302dffdf9c8f287c84ca1ec35b49800237a2a6bae8
MD5 88d6fa4775c8581dd8712edcbe8cc5ab
BLAKE2b-256 81b10a63261ef432cf890756596acdc3a4eac4cd787b76e5ba7d73034d1c8107

See more details on using hashes here.

Supported by

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