Skip to main content

This package provides methods for safely describing App Engine Search API Query as a json structure (a QSpec).

Project description

# im_qsb This package provides methods for safely describing App Engine Search API Query as a json structure (a QSpec).

You can construct a QSpec manually or by using the qsb_X methods

You can render any QSpec to a Search API Query String using render_query_string()

The github repo is [here](

[![Build Status](](

## Install

Use the python package for this library. You can find the package online [here](

Change to your Python App Engine project’s root folder and do the following:

> pip install im_qsb –target lib

Or add it to your requirements.txt. You’ll also need to set up vendoring, see [app engine vendoring instructions here](

# QSpec

A QSpec is a json structure for describing a Search Engine API query, which is converted to a querystring using the following rules:

## string QSpec: <string or unicode> => a quote delimited and escaped unicode string value, eg: ‘Fred “Freddy” Frog’ => u‘“Fred "Freddy" Frog”’

qsb_string(<string or unicode>)

## number QSpec: <number>: a numeric value, eg: 47 => u’47’


## boolean QSpec: <boolean>: ‘1’ or ‘0’, eg: True => ‘1’,


## unquoted QSpec: { “unquoted”: <string or unicode> }: an escaped but not quote delimited unicode string value, eg: { “unquoted”: ‘Fred “Freddy” Frog’ } => u’Fred "Freddy" Frog’

qsb_unquoted(<string or unicode>)

## field QSpec: { “fieldname”: <string or unicode> }: a valid fieldname, with invalid characters replaced with “_”, eg: ‘first*name’ => u’firse_name’

qsb_field(<string or unicode>)

## equality QSpec { “op”: “=”, “field”: <field QSpec>, “value”: <QSpec> }: an equality comparison, eg: {“op”:”=”, “field”: {“fieldname”:”name”}, “value”: “Frodo”} => u’name:”Frodo”’

qsb_eq(<field QSpec>, <QSpec>)

## inequality QSpec { “op”: “!=”, “field”: <field QSpec>, “value”: <QSpec> }: an inequality comparison, eg: {“op”:”!=”, “field”: {“fieldname”:”name”}, “value”: “Frodo”} => u’NOT (name:”Frodo”)’

qsb_neq(<field QSpec>, <QSpec>)

## paren QSpec { “op”: “paren”, “arg”: <QSpec> }: wraps parens around a QSpec, eg: {“op”: “paren”, “arg”: 47} => u’(47)’


## stem QSpec { “op”: “stem”, “arg”: <QSpec> }: adds a stem to a QSpec, eg: {“op”: “stem”, “arg”: “Harry”} => u’~”Harry”’


## less-than QSpec { “op”: “<”, “field”: <field QSpec>, “value”: <QSpec> }: a less-than comparison, eg: {“op”:”<”, “field”: {“fieldname”:”amount”}, “value”: 43} => u’amount<43’

qsb_lt(<field QSpec>, <QSpec>)

## less-than-or-equal-to QSpec { “op”: “<=”, “field”: <field QSpec>, “value”: <QSpec> }: a less-than-or-equal-to comparison, eg: {“op”:”<=”, “field”: {“fieldname”:”amount”}, “value”: 47.2} => u’amount<=47.2’

qsb_le(<field QSpec>, <QSpec>)

## greater-than QSpec { “op”: “>”, “field”: <field QSpec>, “value”: <QSpec> }: a greater-than comparison, eg: {“op”:”>”, “field”: {“fieldname”:”amount”}, “value”: -1} => u’amount>-1’

qsb_gt(<field QSpec>, <QSpec>)

## greater-than-or-equal-to QSpec { “op”: “>=”, “field”: <field QSpec>, “value”: <QSpec> }: a greater-than-or-equal-to comparison, eg: {“op”:”>=”, “field”: {“fieldname”:”amount”}, “value”: 0} => u’amount>=0’

qsb_ge(<field QSpec>, <QSpec>)

## and QSpec { “op”: “AND”, args: [<list of QSpec>] }: a space separated list of QSpecs, which is a valid way to express AND relationships. eg: {“op”:”AND”, “args”: [“X”, “Y”, “Z”] => u‘“X” “Y” “Z”’

qsb_and(<QSpec>, …)

## or QSpec { “op”: “OR”, args: [<list of QSpec>] }: an OR separated list of QSpecs. eg: {“op”:”OR”, “args”: [“noodle”, {“quoted”: “poodle”}]} => u‘“noodle” OR poodle’

qsb_or(<QSpec>, …)

## not QSpec { “op”: “NOT”, arg: <QSpec> }: a negation of a QSpecs. eg: {“op”:”NOT”, “args”:”noodle”} => u’NOT “noodle”’


## geopoint QSpec { “op”: “geopoint”, left: <number QSpec>, right: <number QSpec> }: a geopoint specification, eg: {“op”:”geopoint”, “left”: 12, “right”: 42.7} => u’geopoint(12,42.7)’

qsb_geopoint(<number QSpec>, <number QSpec>)

## distance QSpec { “op”: “distance”, left: <QSpec>, right: <QSpec> }: a distance specification, eg: {“op”: “distance”, “left”: {“op”:”geopoint”, “left”: 12, “right”: 42.7}, “right”: {“fieldname”: “home”}} => u’distance(geopoint(12,42.7),home)’

qsb_distance(<QSpec>, <QSpec>)

Project details

Download files

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

Files for im-qsb, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size im_qsb-0.1.1-py2.py3-none-any.whl (7.2 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size im_qsb-0.1.1.tar.gz (4.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page