savant_rs.match_query

class savant_rs.match_query.EtcdCredentials(username, password)
class savant_rs.match_query.FloatExpression

A class allowing to define a float expression

static between(a, b)

Between expression

In JSON/YAML: between

Parameters:
  • a (float) – Lower bound

  • b (float) – Upper bound

Returns:

Float expression

Return type:

FloatExpression

Example

from savant_rs.match_query import FloatExpression as FE
FE.between(0.5, 0.7)
static eq(v)

Eq expression

In JSON/YAML: eq

Parameters:

v (float) – Value to compare with

Returns:

Float expression

Return type:

FloatExpression

Example

from savant_rs.match_query import FloatExpression as FE
FE.eq(0.5)
static ge(v)

Ge expression

In JSON/YAML: ge

Parameters:

v (float) – Value to compare with

Returns:

Float expression

Return type:

FloatExpression

Example

from savant_rs.match_query import FloatExpression as FE
FE.ge(0.5)
static gt(v)

Gt expression

In JSON/YAML: gt

Parameters:

v (float) – Value to compare with

Returns:

Float expression

Return type:

FloatExpression

Example

from savant_rs.match_query import FloatExpression as FE
FE.gt(0.5)
static le(v)

Le expression

In JSON/YAML: le

Parameters:

v (float) – Value to compare with

Returns:

Float expression

Return type:

FloatExpression

Example

from savant_rs.match_query import FloatExpression as FE
FE.le(0.5)
static lt(v)

Lt expression

In JSON/YAML: lt

Parameters:

v (float) – Value to compare with

Returns:

Float expression

Return type:

FloatExpression

Example

from savant_rs.match_query import FloatExpression as FE
FE.lt(0.5)
static ne(v)

Ne expression

In JSON/YAML: ne

Parameters:

v (float) – Value to compare with

Returns:

Float expression

Return type:

FloatExpression

Example

from savant_rs.match_query import FloatExpression as FE
FE.ne(0.5)
static one_of(*list)

One of expression

In JSON/YAML: one_of

Parameters:

*list (*list of float) – List of values to compare with

Returns:

Float expression

Return type:

FloatExpression

Example

from savant_rs.match_query import FloatExpression as FE
FE.one_of(0.5, 0.7, 0.9)
class savant_rs.match_query.IntExpression

A class allowing to define an integer expression

static between(a, b)

Between expression

In JSON/YAML: between

Parameters:
  • a (int) – Lower bound

  • b (int) – Upper bound

Returns:

Int expression

Return type:

IntExpression

Example

from savant_rs.match_query import IntExpression as IE
IE.between(5, 7)
static eq(v)

Eq expression

In JSON/YAML: eq

Parameters:

v (int) – Value to compare with

Returns:

Int expression

Return type:

IntExpression

Example

from savant_rs.match_query import IntExpression as IE
IE.eq(5)
static ge(v)

Ge expression

In JSON/YAML: ge

Parameters:

v (int) – Value to compare with

Returns:

Int expression

Return type:

IntExpression

Example

from savant_rs.match_query import IntExpression as IE
IE.ge(5)
static gt(v)

Gt expression

In JSON/YAML: gt

Parameters:

v (int) – Value to compare with

Returns:

Int expression

Return type:

IntExpression

Example

from savant_rs.match_query import IntExpression as IE
IE.gt(5)
static le(v)

Le expression

In JSON/YAML: le

Parameters:

v (int) – Value to compare with

Returns:

Int expression

Return type:

IntExpression

Example

from savant_rs.match_query import IntExpression as IE
IE.le(5)
static lt(v)

Lt expression

In JSON/YAML: lt

Parameters:

v (int) – Value to compare with

Returns:

Int expression

Return type:

IntExpression

Example

from savant_rs.match_query import IntExpression as IE
IE.lt(5)
static ne(v)

Ne expression

In JSON/YAML: ne

Parameters:

v (int) – Value to compare with

Returns:

Int expression

Return type:

IntExpression

Example

from savant_rs.match_query import IntExpression as IE
IE.ne(5)
static one_of(*list)

One of expression

In JSON/YAML: one_of

Parameters:

*list (*list of int) – List of values to compare with

Returns:

Int expression

Return type:

IntExpression

Example

from savant_rs.match_query import IntExpression as IE
IE.one_of(5, 7, 9)
class savant_rs.match_query.MatchQuery

A class allowing to define a Query based on expressions

static and_(*list)

And predicate

In JSON/YAML: and

Parameters:

*list (*list of MatchQuery)

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import IntExpression as IE
from savant_rs.match_query import StringExpression as SE

q = MQ.and_(
    MQ.id(IE.eq(5)),
    MQ.label(SE.eq("hello"))
)
print(q.yaml, "\n", q.json)
static attribute_defined(namespace, label)

True if object’s attribute is defined.

In JSON/YAML: attribute.defined

Parameters:
  • namespace (str) – Attribute namespace

  • label (str) – Attribute label

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.attribute_defined("classifier", "hint")
print(q.yaml, "\n", q.json)
static attributes_empty()

True if object doesn’t have attributes

In JSON/YAML: attributes.empty

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.attributes_empty()
print(q.yaml, "\n", q.json)
static attributes_jmes_query(e)

True if JMES Query executed on attributes converted in JSON format returns True.

Syntax: https://jmespath.org/specification.html

In JSON/YAML: attributes.jmes_query

Parameters:

e (str) – JMES Query to run on object’s attributes

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.attributes_jmes_query("[? (hint == 'morphological-classifier') && (namespace == 'classifier')]")
print(q.yaml, "\n", q.json)
static box_angle(e)

True if object’s box angle matches the given float expression.

In JSON/YAML: bbox.angle

Parameters:

e (FloatExpression) – Float expression to compare the object’s box angle with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.box_angle(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static box_angle_defined()

True if object’s box has angle defined.

In JSON/YAML: bbox.angle.defined

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.box_angle_defined()
print(q.yaml, "\n", q.json)
static box_area(e)

True if object’s box area (width x height) matches the given float expression.

In JSON/YAML: bbox.area

Parameters:

e (FloatExpression) – Float expression to compare the object’s box area with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.box_area(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static box_height(e)

True if object’s box height matches the given float expression.

In JSON/YAML: bbox.height

Parameters:

e (FloatExpression) – Float expression to compare the object’s box height with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.box_height(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static box_metric(bbox, metric_type, e)

True if the metric calculated between the current object box and specified box matches the expression.

Parameters:
Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE
from savant_rs.utils import BBoxMetricType
from savant_rs.primitives.geometry import RBBox

q = MQ.box_metric(RBBox(0.5, 0.5, 0.5, 0.5, 0.0), BBoxMetricType.IoU, FE.gt(0.5))
print(q.yaml, "\n", q.json)
static box_width(e)

True if object’s box width matches the given float expression.

In JSON/YAML: bbox.width

Parameters:

e (FloatExpression) – Float expression to compare the object’s box width with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.box_width(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static box_width_to_height_ratio(e)

True if object’s box aspect ratio (width / height) matches the given float expression.

In JSON/YAML: bbox.width_to_height_ratio

Parameters:

e (FloatExpression) – Float expression to compare the object’s box aspect ratio with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.box_width_to_height_ratio(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static box_x_center(e)

True if object’s box xc matches the given float expression.

In JSON/YAML: bbox.xc

Parameters:

e (FloatExpression) – Float expression to compare the object’s box xc with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.box_x_center(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static box_y_center(e)

True if object’s box yc matches the given float expression.

In JSON/YAML: bbox.yc

Parameters:

e (FloatExpression) – Float expression to compare the object’s box yc with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.box_y_center(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static confidence(e)

True if object’s confidence matches the given float expression.

In JSON/YAML: confidence

Parameters:

e (FloatExpression) – Float expression to compare the object’s confidence with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.confidence(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static confidence_defined()

True if object’s confidence is defined.

In JSON/YAML: confidence.defined

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.confidence_defined()
print(q.yaml, "\n", q.json)
static eval(exp)

True, when expression defined by evalexpr is computed. EvalExpr is a powerful way to define complex queries but is slower than explicit definition of expressions.

In JSON/YAML: eval

Parameters:
Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

# Available symbols:
#
#   - id: object id
#   - namespace: object namespace
#   - label: object label
#   - confidence: object confidence
#   - parent.id: parent object id
#   - parent.namespace: parent object namespace
#   - parent.label: parent object label
#   - bbox.xc: object bbox x center
#   - bbox.yc: object bbox y center
#   - bbox.width: object bbox width
#   - bbox.height: object bbox height
#   - bbox.angle: object bbox angle
#   - tracking_info.id: tracking id
#   - tracking_info.bbox.xc: tracking bbox x center
#   - tracking_info.bbox.yc: tracking bbox y center
#   - tracking_info.bbox.width: tracking bbox width
#   - tracking_info.bbox.height: tracking bbox height
#   - tracking_info.bbox.angle: tracking bbox angle
#   - frame.source: frame source
#   - frame.rate: frame rate
#   - frame.width: frame width
#   - frame.height: frame height
#   - frame.keyframe: frame keyframe
#   - frame.dts: frame dts
#   - frame.pts: frame pts
#   - frame.time_base.nominator: frame time base nominator
#   - frame.time_base.denominator: frame time base denominator
#
# Available functions:
#   - standard functions: https://docs.rs/evalexpr/11.3.0/evalexpr/index.html
#
#   - env("NAME", default): get environment variable, default also represents the type to cast env to
#   - config("NAME", default): get config variable, default also represents the type to cast config to
#
#   - is_boolean(value): check if value is boolean
#   - is_float(value): check if value is float
#   - is_int(value): check if value is int
#   - is_string(value): check if value is string
#   - is_tuple(value): check if value is tuple
#   - is_empty(value): check if value is empty
#
#   - ends_with(value, suffix): check if value ends with suffix
#   - starts_with(value, prefix): check if value starts with prefix
#
#   - etcd("KEY", default): get etcd variable, default also represents the type to cast etcd to
#
q = MQ.eval("""(etcd("pipeline_status", false) == true || env("PIPELINE_STATUS", false) == true) && frame.keyframe""")
print(q.yaml, "\n", q.json)
static frame_attribute_exists(namespace, label)

True if frame’s attribute is defined.

In JSON/YAML: frame.attribute.exists

Parameters:
  • namespace (str) – Attribute namespace

  • label (str) – Attribute label

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.frame_attribute_exists("age_gender", "age")
print(q.yaml, "\n", q.json)
static frame_attributes_empty()

True if frame’s attribute is not defined.

In JSON/YAML: frame.attribute.empty

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.frame_attribute_empty()
print(q.yaml, "\n", q.json)
static frame_attributes_jmes_query(e)

True if JMES Query executed on frame attributes converted in JSON format returns True.

Syntax: https://jmespath.org/specification.html

In JSON/YAML: frame.attributes.jmes_query

Parameters:

e (str) – JMES Query to run on frame’s attributes

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.frame_attributes_jmes_query("[? (source_id == 'source1')]")
print(q.yaml, "\n", q.json)
static frame_height(e)

True if frame height matches the given int expression.

In JSON/YAML: frame.height

Parameters:

e (IntExpression) – Integer expression to compare the frame’s height with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import IntExpression as IE

q = MQ.frame_height(IE.eq(1080))
print(q.yaml, "\n", q.json)
static frame_is_key_frame()

True if frame is key frame.

In JSON/YAML: frame.is_key_frame

Returns:

Query

Return type:

MatchQuery

Example

 from savant_rs.match_query import MatchQuery as MQ

q = MQ.frame_is_key_frame()
print(q.yaml, "\n", q.json)
static frame_no_video()

When the frame does not have associated video, because of sparsity, for example

In JSON/YAML: frame.no_video

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.frame_no_video()
print(q.yaml, "\n", q.json)
static frame_source_id(e)

True if frame source_id matches the given string expression.

In JSON/YAML: frame.source_id

Parameters:

e (StringExpression) – String expression to compare the frame’s source_id with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import StringExpression as SE

q = MQ.frame_source_id(SE.eq("source1"))
print(q.yaml, "\n", q.json)
static frame_transcoding_is_copy()

When the processing is configured in pass-through mode

In JSON/YAML: frame.transcoding.is_copy

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.frame_transcoding_is_copy()
print(q.yaml, "\n", q.json)
static frame_width(e)

True if frame width matches the given int expression.

In JSON/YAML: frame.width

Parameters:

e (IntExpression) – Integer expression to compare the frame’s width with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import IntExpression as IE

q = MQ.frame_width(IE.eq(1920))
print(q.yaml, "\n", q.json)
static from_json(json)

Loads query from JSON string.

Parameters:

json (str) – JSON string

Returns:

Query

Return type:

MatchQuery

Raises:

ValueError – If the JSON string is invalid

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.from_json('{"not":{"id":{"eq":5}}}')
print(q.yaml, "\n", q.json)
static from_yaml(yaml)

Loads query from YAML string.

Parameters:

yaml (str) – YAML string

Returns:

Query

Return type:

MatchQuery

Raises:

ValueError – If the YAML string is invalid

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.from_yaml("""
not:
  id:
    eq: 5
""")
static id(e)

True if object’s Id matches the given integer expression.

In JSON/YAML: object.id

Parameters:

e (IntExpression) – Integer expression to compare the object’s Id with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import IntExpression as IE

q = MQ.id(IE.eq(5))
print(q.yaml, "\n", q.json)
static idle()

Always true

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.idle()
print(q.yaml, "\n", q.json)
json

Dumps query to JSON string.

Returns:

JSON string

Return type:

str

json_pretty

Dumps query to pretty JSON string.

Returns:

Pretty JSON string

Return type:

str

static label(e)

True if object’s label matches the given string expression.

In JSON/YAML: label

Parameters:

e (StringExpression) – String expression to compare the object’s label with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import StringExpression as SE

q = MQ.label(SE.eq("person"))
print(q.yaml, "\n", q.json)
static namespace(e)

True if object’s namespace matches the given string expression.

In JSON/YAML: namespace

Parameters:

e (StringExpression) – String expression to compare the object’s namespace with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import StringExpression as SE

q = MQ.namespace(SE.eq("model1"))
print(q.yaml, "\n", q.json)
static not_(a)

Not predicate

In JSON/YAML: not

Parameters:

a (MatchQuery) – Query

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import IntExpression as IE

q = MQ.not_(MQ.id(IE.eq(5)))
print(q.yaml, "\n", q.json)
static or_(*list)

Or predicate

In JSON/YAML: or

Parameters:

*list (*list of MatchQuery)

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import IntExpression as IE
from savant_rs.match_query import StringExpression as SE

q = MQ.or_(
    MQ.namespace(SE.eq("model1")),
    MQ.namespace(SE.eq("model2"))
)
print(q.yaml, "\n", q.json)
static parent_defined()

True if object’s parent is defined.

In JSON/YAML: parent.defined

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.parent_defined()
print(q.yaml, "\n", q.json)
static parent_id(e)

True if object’s parent id matches the given int expression.

In JSON/YAML: parent.id

Parameters:

e (IntExpression) – Integer expression to compare the object’s parent id with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import IntExpression as IE

q = MQ.parent_id(IE.eq(5))
print(q.yaml, "\n", q.json)
static parent_label(e)

True if object’s parent label matches the given string expression.

In JSON/YAML: parent.label

Parameters:

e (StringExpression) – String expression to compare the object’s parent label with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import StringExpression as SE

q = MQ.parent_label(SE.eq("person"))
print(q.yaml, "\n", q.json)
static parent_namespace(e)

True if object’s parent namespace matches the given string expression.

In JSON/YAML: parent.namespace

Parameters:

e (StringExpression) – String expression to compare the object’s parent namespace with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import StringExpression as SE

q = MQ.parent_namespace(SE.eq("model1"))
print(q.yaml, "\n", q.json)
static stop_if_false(a)

Stop checking next objects If False predicate (short-circuit)

In JSON/YAML: stop_if_false

Parameters:

a (MatchQuery) – Query

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.stop_if_false(MQ.frame_is_key_frame())
print(q.yaml, "\n", q.json)
static stop_if_true(a)

Stop checking next objects If True predicate (short-circuit)

In JSON/YAML: stop_if_true

Parameters:

a (MatchQuery) – Query

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.stop_if_true(MQ.not_(MQ.frame_is_key_frame()))
print(q.yaml, "\n", q.json)
static track_box_angle(e)

True if object’s track bbox angle matches the given float expression.

In JSON/YAML: track.bbox.angle

Parameters:

e (FloatExpression) – Float expression to compare the object’s track bbox angle with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.track_box_angle(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static track_box_angle_defined()

True if object’s track box has angle defined.

In JSON/YAML: track.bbox.angle.defined

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.track_box_angle_defined()
print(q.yaml, "\n", q.json)
static track_box_area(e)

True if object’s track bbox area (width x height) matches the given float expression.

In JSON/YAML: track.bbox.area

Parameters:

e (FloatExpression) – Float expression to compare the object’s track bbox area with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.track_box_area(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static track_box_height(e)

True if object’s track bbox height matches the given float expression.

In JSON/YAML: track.bbox.height

Parameters:

e (FloatExpression) – Float expression to compare the object’s track bbox height with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.track_box_height(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static track_box_metric(bbox, metric_type, e)

True if the metric calculated between the current object track box and specified box matches the expression.

Parameters:
Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE
from savant_rs.utils import BBoxMetricType
from savant_rs.primitives.geometry import RBBox

q = MQ.track_box_metric(RBBox(0.5, 0.5, 0.5, 0.5, 0.0), BBoxMetricType.IoU, FE.gt(0.5))
print(q.yaml, "\n", q.json)
static track_box_width(e)

True if object’s track bbox width matches the given float expression.

In JSON/YAML: track.bbox.width

Parameters:

e (FloatExpression) – Float expression to compare the object’s track bbox width with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.track_box_width(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static track_box_width_to_height_ratio(e)

True if object’s track bbox aspect ratio (width / height) matches the given float expression.

In JSON/YAML: track.bbox.width_to_height_ratio

Parameters:

e (FloatExpression) – Float expression to compare the object’s track bbox aspect ratio with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.track_box_width_to_height_ratio(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static track_box_x_center(e)

True if object’s track bbox xc matches the given float expression.

In JSON/YAML: track.bbox.xc

Parameters:

e (FloatExpression) – Float expression to compare the object’s track bbox xc with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.track_box_x_center(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static track_box_y_center(e)

True if object’s track bbox yc matches the given float expression.

In JSON/YAML: track.bbox.yc

Parameters:

e (FloatExpression) – Float expression to compare the object’s track bbox yc with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import FloatExpression as FE

q = MQ.track_box_y_center(FE.gt(0.5))
print(q.yaml, "\n", q.json)
static track_id(e)

True if object’s track_id matches the given int expression.

In JSON/YAML: track.id

Parameters:

e (IntExpression) – Integer expression to compare the object’s track_id with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import IntExpression as IE

q = MQ.track_id(IE.eq(5))
print(q.yaml, "\n", q.json)
static track_id_defined()

True if object’s track id is defined.

In JSON/YAML: track.id.defined

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ

q = MQ.track_id_defined()
print(q.yaml, "\n", q.json)
static with_children(a, n)

True if query executed on children objects of an object returns a number of results matching the given integer expression.

E.g. If a person has at least one hand visible.

In JSON/YAML: with_children

Parameters:
  • a (MatchQuery) – Query to run on children objects to get the number of matching results

  • n (IntExpression) – Integer expression to compare the number retrieved for children with

Returns:

Query

Return type:

MatchQuery

Example

from savant_rs.match_query import MatchQuery as MQ
from savant_rs.match_query import IntExpression as IE
from savant_rs.match_query import StringExpression as SE

# More than one person among the children of the object

q = MQ.with_children(
    MQ.label(SE.eq("person")),
    IE.ge(1)
)
print(q.yaml, "\n", q.json)
yaml

Dumps query to YAML string.

Returns:

YAML string

Return type:

str

class savant_rs.match_query.QueryFunctions
static filter(v, q, no_gil=True)
static partition(v, q, no_gil=True)
class savant_rs.match_query.StringExpression

A class allowing to define a string expression

static contains(v)

Contains expression

In JSON/YAML: contains

Parameters:

v (str) – Value to compare with

Returns:

String expression

Return type:

StringExpression

Example

from savant_rs.match_query import StringExpression as SE
SE.contains("hello")
static ends_with(v)

Ends with expression

In JSON/YAML: ends_with

Parameters:

v (str) – Value to compare with

Returns:

String expression

Return type:

StringExpression

Example

from savant_rs.match_query import StringExpression as SE
SE.ends_with("hello")
static eq(v)

Eq expression

In JSON/YAML: eq

Parameters:

v (str) – Value to compare with

Returns:

String expression

Return type:

StringExpression

Example

from savant_rs.match_query import StringExpression as SE
SE.eq("hello")
static ne(v)

Ne expression

In JSON/YAML: ne

Parameters:

v (str) – Value to compare with

Returns:

String expression

Return type:

StringExpression

Example

from savant_rs.match_query import StringExpression as SE
SE.ne("hello")
static not_contains(v)

Not contains expression

In JSON/YAML: not_contains

Parameters:

v (str) – Value to compare with

Returns:

String expression

Return type:

StringExpression

Example

from savant_rs.match_query import StringExpression as SE
SE.not_contains("hello")
static one_of(*list)

One of expression

In JSON/YAML: one_of

Parameters:

*list (*list of str) – List of values to compare with

Returns:

String expression

Return type:

StringExpression

Example

from savant_rs.match_query import StringExpression as SE
SE.one_of("hello", "world")
static starts_with(v)

Starts with expression

In JSON/YAML: starts_with

Parameters:

v (str) – Value to compare with

Returns:

String expression

Return type:

StringExpression

Example

from savant_rs.match_query import StringExpression as SE
SE.starts_with("hello")
class savant_rs.match_query.TlsConfig(ca_cert, client_cert, client_key)
savant_rs.match_query.config_resolver_name()

Returns the system name of config resolver.

Returns:

The name of the config resolver.

Return type:

str

savant_rs.match_query.env_resolver_name()

Returns the system name of env resolver.

Returns:

The name of the env resolver.

Return type:

str

savant_rs.match_query.etcd_resolver_name()

Returns the system name of etcd resolver.

Returns:

The name of the etcd resolver.

Return type:

str

savant_rs.match_query.register_config_resolver(symbols)

Registers the Config resolver in the system runtime.

Parameters:

symbols (Dict[str, str]) – The symbols to register in the Config resolver.

savant_rs.match_query.register_env_resolver()

Registers the Env resolver in the system runtime.

savant_rs.match_query.register_etcd_resolver(hosts=Ellipsis, credentials=None, tls_config=None, watch_path='savant', connect_timeout=5, watch_path_wait_timeout=5)

Registers the Etcd resolver in the system runtime.

Parameters:
  • hosts (List[str]) – The list of hosts to connect to the Etcd server. Default is [“127.0.0.1:2379”].

  • credentials (Optional[EtcdCredentials]) – The username and password to connect to the Etcd server. Default is None.

  • tls_config (Optional[TlsConfig]) – The TLS configuration to connect to the Etcd server. Default is None.

  • watch_path (str) – The path to watch for changes in the Etcd server. Default is “savant”.

  • connect_timeout (int) – The timeout to connect to the Etcd server. In seconds. Default is 5 seconds.

  • watch_path_wait_timeout (int) – The timeout to wait for changes in the Etcd server. In seconds. Default is 5 seconds.

savant_rs.match_query.register_utility_resolver()

Registers the Utility resolver in the system runtime.

savant_rs.match_query.unregister_resolver(name)

Unregisters the resolver from the system runtime.

Parameters:

name (str) – The name of the resolver to unregister.

savant_rs.match_query.update_config_resolver(symbols)

Updates the Config resolver in the system runtime.

Parameters:

symbols (Dict[str, str]) – The symbols to update in the Config resolver.

savant_rs.match_query.utility_resolver_name()

Returns the system name of utility resolver.

Returns:

The name of the utility resolver.

Return type:

str