<!-- # hard line break macro for HTML -->

# fiftyone.core.expression_ast

Serializable syntax trees for view expressions.

Copyright 2017-2026, Voxel51, Inc.
<br/>
[voxel51.com](https://voxel51.com/)
<br/>
<br/>

`ViewExpression.to_mongo()` lowers an expression to a MongoDB aggregation
expression, and that lowering is one-way: `F("x") & F("y")` and
`F("x").all([...])` both produce `{"$and": [...]}`, `F("x").exists()`
produces the same shape as a comparison against `null`, and 20 operators
lower into multi-node idioms (`length()` becomes
`{"$size": {"$ifNull": ["$x", []]}}`). Nothing downstream of the lowering can
tell which operator the caller used.

This module records the construction itself, so an expression built in the App
can be reconstructed here as the same `F(...)` / `E(...)` calls, and one
built in Python can be rendered in the App as structure rather than as opaque
MongoDB. The lowering is unchanged and remains what the aggregation pipeline
consumes.

Node forms:

```default
{"t": "field",  "path": "conf"}                      a ViewField
{"t": "lit",    "v": 0.5}                            a JSON literal
{"t": "call",   "op": "__gt__", "self": <node>,
                "args": [<node>], "kwargs": {}}      an instance method
{"t": "static", "op": "any",
                "args": [<node>], "kwargs": {}}      a static constructor
{"t": "list",   "items": [<node>]}                   a list operand
{"t": "dict",   "entries": [[<node>, <node>]]}       a dict operand
{"t": "mongo",  "expr": {...}}                       raw MongoDB, no syntax
```

The `mongo` form is the fallback: expressions built by passing MongoDB
directly to `E({...})`, and expressions arriving from a view saved before
this module existed, carry no construction to record. They round trip
losslessly as MongoDB, and callers can tell the difference by checking
[`is_reconstructible()`](#fiftyone.core.expression_ast.is_reconstructible).

**Classes:**

| [`FieldNode`](#fiftyone.core.expression_ast.FieldNode)     | A [`fiftyone.core.expressions.ViewField`](fiftyone.core.expressions.md#fiftyone.core.expressions.ViewField).   |
|------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|
| [`LiteralNode`](#fiftyone.core.expression_ast.LiteralNode) |                                                                                                                |
| [`CallNode`](#fiftyone.core.expression_ast.CallNode)       | An instance method or operator applied to a target expression.                                                 |
| [`StaticNode`](#fiftyone.core.expression_ast.StaticNode)   | A static constructor such as `E.any` or `E.literal`.                                                           |
| [`ListNode`](#fiftyone.core.expression_ast.ListNode)       | A list operand, whose items may themselves be expressions.                                                     |
| [`DictNode`](#fiftyone.core.expression_ast.DictNode)       | A dict operand, whose keys and values may themselves be expressions.                                           |
| [`MongoNode`](#fiftyone.core.expression_ast.MongoNode)     | Raw MongoDB, for an expression that recorded no syntax.                                                        |

**Data:**

| [`AST_VERSION`](#fiftyone.core.expression_ast.AST_VERSION)   | Version of the syntax tree format.                |
|--------------------------------------------------------------|---------------------------------------------------|
| [`AST_KEY`](#fiftyone.core.expression_ast.AST_KEY)           | Envelope key identifying a serialized expression. |

**Functions:**

| [`records_expression_syntax`](#fiftyone.core.expression_ast.records_expression_syntax)(cls)   | Class decorator that records how each expression was constructed.   |
|-----------------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| [`node_of`](#fiftyone.core.expression_ast.node_of)(expr)                                      | Returns the syntax tree node for an expression.                     |
| [`is_reconstructible`](#fiftyone.core.expression_ast.is_reconstructible)(expr)                | Whether an expression can be rendered as Python source.             |
| [`to_envelope`](#fiftyone.core.expression_ast.to_envelope)(expr)                              | Serializes an expression as a versioned envelope.                   |
| [`is_envelope`](#fiftyone.core.expression_ast.is_envelope)(value)                             | Whether a serialized value is an expression envelope.               |
| [`from_envelope`](#fiftyone.core.expression_ast.from_envelope)(value)                         | Reconstructs an expression from a versioned envelope.               |
| [`from_node`](#fiftyone.core.expression_ast.from_node)(node)                                  | Reconstructs an expression from a syntax tree node.                 |
| [`to_python`](#fiftyone.core.expression_ast.to_python)(expr[, field_var, expr_var])           | Renders an expression as Python source.                             |

### *class* fiftyone.core.expression_ast.FieldNode

Bases: `TypedDict`

A [`fiftyone.core.expressions.ViewField`](fiftyone.core.expressions.md#fiftyone.core.expressions.ViewField).

**Attributes:**

| [`t`](#fiftyone.core.expression_ast.FieldNode.t)       |    |
|--------------------------------------------------------|----|
| [`path`](#fiftyone.core.expression_ast.FieldNode.path) |    |

**Methods:**

| [`clear`](#fiftyone.core.expression_ast.FieldNode.clear)()                         | Remove all items from the dict.                                                                                                                                                                                                    |
|------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`copy`](#fiftyone.core.expression_ast.FieldNode.copy)()                           | Return a shallow copy of the dict.                                                                                                                                                                                                 |
| [`fromkeys`](#fiftyone.core.expression_ast.FieldNode.fromkeys)(iterable[, value])  | Create a new dictionary with keys from iterable and values set to value.                                                                                                                                                           |
| [`get`](#fiftyone.core.expression_ast.FieldNode.get)(key[, default])               | Return the value for key if key is in the dictionary, else default.                                                                                                                                                                |
| [`items`](#fiftyone.core.expression_ast.FieldNode.items)()                         | Return a set-like object providing a view on the dict's items.                                                                                                                                                                     |
| [`keys`](#fiftyone.core.expression_ast.FieldNode.keys)()                           | Return a set-like object providing a view on the dict's keys.                                                                                                                                                                      |
| [`pop`](#fiftyone.core.expression_ast.FieldNode.pop)(k[,d])                        | If the key is not found, return the default if given; otherwise, raise a KeyError.                                                                                                                                                 |
| [`popitem`](#fiftyone.core.expression_ast.FieldNode.popitem)()                     | Remove and return a (key, value) pair as a 2-tuple.                                                                                                                                                                                |
| [`setdefault`](#fiftyone.core.expression_ast.FieldNode.setdefault)(key[, default]) | Insert key with a value of default if key is not in the dictionary.                                                                                                                                                                |
| [`update`](#fiftyone.core.expression_ast.FieldNode.update)([E, ]\*\*F)             | If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v In either case, this is followed by: for k in F:  D[k] = F[k] |
| [`values`](#fiftyone.core.expression_ast.FieldNode.values)()                       | Return an object providing a view on the dict's values.                                                                                                                                                                            |

#### t *: Literal['field']*

#### path *: str*

#### clear()

Remove all items from the dict.

#### copy()

Return a shallow copy of the dict.

#### *classmethod* fromkeys(iterable, value=None,)

Create a new dictionary with keys from iterable and values set to value.

#### get(key, default=None,)

Return the value for key if key is in the dictionary, else default.

#### items()

Return a set-like object providing a view on the dict’s items.

#### keys()

Return a set-like object providing a view on the dict’s keys.

#### pop(k) → v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise,
raise a KeyError.

#### popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order.
Raises KeyError if the dict is empty.

#### setdefault(key, default=None,)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

#### update(\*\*F) → None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k]
If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
In either case, this is followed by: for k in F:  D[k] = F[k]

#### values()

Return an object providing a view on the dict’s values.

### *class* fiftyone.core.expression_ast.LiteralNode

Bases: `TypedDict`

**Methods:**

| [`clear`](#fiftyone.core.expression_ast.LiteralNode.clear)()                         | Remove all items from the dict.                                                                                                                                                                                                    |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`copy`](#fiftyone.core.expression_ast.LiteralNode.copy)()                           | Return a shallow copy of the dict.                                                                                                                                                                                                 |
| [`fromkeys`](#fiftyone.core.expression_ast.LiteralNode.fromkeys)(iterable[, value])  | Create a new dictionary with keys from iterable and values set to value.                                                                                                                                                           |
| [`get`](#fiftyone.core.expression_ast.LiteralNode.get)(key[, default])               | Return the value for key if key is in the dictionary, else default.                                                                                                                                                                |
| [`items`](#fiftyone.core.expression_ast.LiteralNode.items)()                         | Return a set-like object providing a view on the dict's items.                                                                                                                                                                     |
| [`keys`](#fiftyone.core.expression_ast.LiteralNode.keys)()                           | Return a set-like object providing a view on the dict's keys.                                                                                                                                                                      |
| [`pop`](#fiftyone.core.expression_ast.LiteralNode.pop)(k[,d])                        | If the key is not found, return the default if given; otherwise, raise a KeyError.                                                                                                                                                 |
| [`popitem`](#fiftyone.core.expression_ast.LiteralNode.popitem)()                     | Remove and return a (key, value) pair as a 2-tuple.                                                                                                                                                                                |
| [`setdefault`](#fiftyone.core.expression_ast.LiteralNode.setdefault)(key[, default]) | Insert key with a value of default if key is not in the dictionary.                                                                                                                                                                |
| [`update`](#fiftyone.core.expression_ast.LiteralNode.update)([E, ]\*\*F)             | If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v In either case, this is followed by: for k in F:  D[k] = F[k] |
| [`values`](#fiftyone.core.expression_ast.LiteralNode.values)()                       | Return an object providing a view on the dict's values.                                                                                                                                                                            |

**Attributes:**

| [`t`](#fiftyone.core.expression_ast.LiteralNode.t)   |    |
|------------------------------------------------------|----|

#### clear()

Remove all items from the dict.

#### copy()

Return a shallow copy of the dict.

#### *classmethod* fromkeys(iterable, value=None,)

Create a new dictionary with keys from iterable and values set to value.

#### get(key, default=None,)

Return the value for key if key is in the dictionary, else default.

#### items()

Return a set-like object providing a view on the dict’s items.

#### keys()

Return a set-like object providing a view on the dict’s keys.

#### pop(k) → v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise,
raise a KeyError.

#### popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order.
Raises KeyError if the dict is empty.

#### setdefault(key, default=None,)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

#### update(\*\*F) → None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k]
If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
In either case, this is followed by: for k in F:  D[k] = F[k]

#### values()

Return an object providing a view on the dict’s values.

#### t *: Literal['lit']*

#### v *: None | [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | int | float | str | List[None | [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | int | float | str | List[JSONValue] | Dict[str, JSONValue]] | Dict[str, None | [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | int | float | str | List[JSONValue] | Dict[str, JSONValue]]*

#### as *: Literal['date', 'timedelta']*

### *class* fiftyone.core.expression_ast.CallNode

Bases: `TypedDict`

An instance method or operator applied to a target expression.

**Attributes:**

| [`t`](#fiftyone.core.expression_ast.CallNode.t)           |    |
|-----------------------------------------------------------|----|
| [`op`](#fiftyone.core.expression_ast.CallNode.op)         |    |
| [`self`](#fiftyone.core.expression_ast.CallNode.self)     |    |
| [`args`](#fiftyone.core.expression_ast.CallNode.args)     |    |
| [`kwargs`](#fiftyone.core.expression_ast.CallNode.kwargs) |    |

**Methods:**

| [`clear`](#fiftyone.core.expression_ast.CallNode.clear)()                         | Remove all items from the dict.                                                                                                                                                                                                    |
|-----------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`copy`](#fiftyone.core.expression_ast.CallNode.copy)()                           | Return a shallow copy of the dict.                                                                                                                                                                                                 |
| [`fromkeys`](#fiftyone.core.expression_ast.CallNode.fromkeys)(iterable[, value])  | Create a new dictionary with keys from iterable and values set to value.                                                                                                                                                           |
| [`get`](#fiftyone.core.expression_ast.CallNode.get)(key[, default])               | Return the value for key if key is in the dictionary, else default.                                                                                                                                                                |
| [`items`](#fiftyone.core.expression_ast.CallNode.items)()                         | Return a set-like object providing a view on the dict's items.                                                                                                                                                                     |
| [`keys`](#fiftyone.core.expression_ast.CallNode.keys)()                           | Return a set-like object providing a view on the dict's keys.                                                                                                                                                                      |
| [`pop`](#fiftyone.core.expression_ast.CallNode.pop)(k[,d])                        | If the key is not found, return the default if given; otherwise, raise a KeyError.                                                                                                                                                 |
| [`popitem`](#fiftyone.core.expression_ast.CallNode.popitem)()                     | Remove and return a (key, value) pair as a 2-tuple.                                                                                                                                                                                |
| [`setdefault`](#fiftyone.core.expression_ast.CallNode.setdefault)(key[, default]) | Insert key with a value of default if key is not in the dictionary.                                                                                                                                                                |
| [`update`](#fiftyone.core.expression_ast.CallNode.update)([E, ]\*\*F)             | If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v In either case, this is followed by: for k in F:  D[k] = F[k] |
| [`values`](#fiftyone.core.expression_ast.CallNode.values)()                       | Return an object providing a view on the dict's values.                                                                                                                                                                            |

#### t *: Literal['call']*

#### op *: str*

#### self *: [FieldNode](#fiftyone.core.expression_ast.FieldNode) | [LiteralNode](#fiftyone.core.expression_ast.LiteralNode) | [CallNode](#fiftyone.core.expression_ast.CallNode) | [StaticNode](#fiftyone.core.expression_ast.StaticNode) | [ListNode](#fiftyone.core.expression_ast.ListNode) | [DictNode](#fiftyone.core.expression_ast.DictNode) | [MongoNode](#fiftyone.core.expression_ast.MongoNode)*

#### args *: List[[FieldNode](#fiftyone.core.expression_ast.FieldNode) | [LiteralNode](#fiftyone.core.expression_ast.LiteralNode) | [CallNode](#fiftyone.core.expression_ast.CallNode) | [StaticNode](#fiftyone.core.expression_ast.StaticNode) | [ListNode](#fiftyone.core.expression_ast.ListNode) | [DictNode](#fiftyone.core.expression_ast.DictNode) | [MongoNode](#fiftyone.core.expression_ast.MongoNode)]*

#### kwargs *: Dict[str, [FieldNode](#fiftyone.core.expression_ast.FieldNode) | [LiteralNode](#fiftyone.core.expression_ast.LiteralNode) | [CallNode](#fiftyone.core.expression_ast.CallNode) | [StaticNode](#fiftyone.core.expression_ast.StaticNode) | [ListNode](#fiftyone.core.expression_ast.ListNode) | [DictNode](#fiftyone.core.expression_ast.DictNode) | [MongoNode](#fiftyone.core.expression_ast.MongoNode)]*

#### clear()

Remove all items from the dict.

#### copy()

Return a shallow copy of the dict.

#### *classmethod* fromkeys(iterable, value=None,)

Create a new dictionary with keys from iterable and values set to value.

#### get(key, default=None,)

Return the value for key if key is in the dictionary, else default.

#### items()

Return a set-like object providing a view on the dict’s items.

#### keys()

Return a set-like object providing a view on the dict’s keys.

#### pop(k) → v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise,
raise a KeyError.

#### popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order.
Raises KeyError if the dict is empty.

#### setdefault(key, default=None,)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

#### update(\*\*F) → None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k]
If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
In either case, this is followed by: for k in F:  D[k] = F[k]

#### values()

Return an object providing a view on the dict’s values.

### *class* fiftyone.core.expression_ast.StaticNode

Bases: `TypedDict`

A static constructor such as `E.any` or `E.literal`.

**Attributes:**

| [`t`](#fiftyone.core.expression_ast.StaticNode.t)           |    |
|-------------------------------------------------------------|----|
| [`op`](#fiftyone.core.expression_ast.StaticNode.op)         |    |
| [`args`](#fiftyone.core.expression_ast.StaticNode.args)     |    |
| [`kwargs`](#fiftyone.core.expression_ast.StaticNode.kwargs) |    |

**Methods:**

| [`clear`](#fiftyone.core.expression_ast.StaticNode.clear)()                         | Remove all items from the dict.                                                                                                                                                                                                    |
|-------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`copy`](#fiftyone.core.expression_ast.StaticNode.copy)()                           | Return a shallow copy of the dict.                                                                                                                                                                                                 |
| [`fromkeys`](#fiftyone.core.expression_ast.StaticNode.fromkeys)(iterable[, value])  | Create a new dictionary with keys from iterable and values set to value.                                                                                                                                                           |
| [`get`](#fiftyone.core.expression_ast.StaticNode.get)(key[, default])               | Return the value for key if key is in the dictionary, else default.                                                                                                                                                                |
| [`items`](#fiftyone.core.expression_ast.StaticNode.items)()                         | Return a set-like object providing a view on the dict's items.                                                                                                                                                                     |
| [`keys`](#fiftyone.core.expression_ast.StaticNode.keys)()                           | Return a set-like object providing a view on the dict's keys.                                                                                                                                                                      |
| [`pop`](#fiftyone.core.expression_ast.StaticNode.pop)(k[,d])                        | If the key is not found, return the default if given; otherwise, raise a KeyError.                                                                                                                                                 |
| [`popitem`](#fiftyone.core.expression_ast.StaticNode.popitem)()                     | Remove and return a (key, value) pair as a 2-tuple.                                                                                                                                                                                |
| [`setdefault`](#fiftyone.core.expression_ast.StaticNode.setdefault)(key[, default]) | Insert key with a value of default if key is not in the dictionary.                                                                                                                                                                |
| [`update`](#fiftyone.core.expression_ast.StaticNode.update)([E, ]\*\*F)             | If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v In either case, this is followed by: for k in F:  D[k] = F[k] |
| [`values`](#fiftyone.core.expression_ast.StaticNode.values)()                       | Return an object providing a view on the dict's values.                                                                                                                                                                            |

#### t *: Literal['static']*

#### op *: str*

#### args *: List[[FieldNode](#fiftyone.core.expression_ast.FieldNode) | [LiteralNode](#fiftyone.core.expression_ast.LiteralNode) | [CallNode](#fiftyone.core.expression_ast.CallNode) | [StaticNode](#fiftyone.core.expression_ast.StaticNode) | [ListNode](#fiftyone.core.expression_ast.ListNode) | [DictNode](#fiftyone.core.expression_ast.DictNode) | [MongoNode](#fiftyone.core.expression_ast.MongoNode)]*

#### kwargs *: Dict[str, [FieldNode](#fiftyone.core.expression_ast.FieldNode) | [LiteralNode](#fiftyone.core.expression_ast.LiteralNode) | [CallNode](#fiftyone.core.expression_ast.CallNode) | [StaticNode](#fiftyone.core.expression_ast.StaticNode) | [ListNode](#fiftyone.core.expression_ast.ListNode) | [DictNode](#fiftyone.core.expression_ast.DictNode) | [MongoNode](#fiftyone.core.expression_ast.MongoNode)]*

#### clear()

Remove all items from the dict.

#### copy()

Return a shallow copy of the dict.

#### *classmethod* fromkeys(iterable, value=None,)

Create a new dictionary with keys from iterable and values set to value.

#### get(key, default=None,)

Return the value for key if key is in the dictionary, else default.

#### items()

Return a set-like object providing a view on the dict’s items.

#### keys()

Return a set-like object providing a view on the dict’s keys.

#### pop(k) → v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise,
raise a KeyError.

#### popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order.
Raises KeyError if the dict is empty.

#### setdefault(key, default=None,)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

#### update(\*\*F) → None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k]
If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
In either case, this is followed by: for k in F:  D[k] = F[k]

#### values()

Return an object providing a view on the dict’s values.

### *class* fiftyone.core.expression_ast.ListNode

Bases: `TypedDict`

A list operand, whose items may themselves be expressions.

**Attributes:**

| [`t`](#fiftyone.core.expression_ast.ListNode.t)   |    |
|---------------------------------------------------|----|

**Methods:**

| [`items`](#fiftyone.core.expression_ast.ListNode.items)()                         | Return a set-like object providing a view on the dict's items.                                                                                                                                                                     |
|-----------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`clear`](#fiftyone.core.expression_ast.ListNode.clear)()                         | Remove all items from the dict.                                                                                                                                                                                                    |
| [`copy`](#fiftyone.core.expression_ast.ListNode.copy)()                           | Return a shallow copy of the dict.                                                                                                                                                                                                 |
| [`fromkeys`](#fiftyone.core.expression_ast.ListNode.fromkeys)(iterable[, value])  | Create a new dictionary with keys from iterable and values set to value.                                                                                                                                                           |
| [`get`](#fiftyone.core.expression_ast.ListNode.get)(key[, default])               | Return the value for key if key is in the dictionary, else default.                                                                                                                                                                |
| [`keys`](#fiftyone.core.expression_ast.ListNode.keys)()                           | Return a set-like object providing a view on the dict's keys.                                                                                                                                                                      |
| [`pop`](#fiftyone.core.expression_ast.ListNode.pop)(k[,d])                        | If the key is not found, return the default if given; otherwise, raise a KeyError.                                                                                                                                                 |
| [`popitem`](#fiftyone.core.expression_ast.ListNode.popitem)()                     | Remove and return a (key, value) pair as a 2-tuple.                                                                                                                                                                                |
| [`setdefault`](#fiftyone.core.expression_ast.ListNode.setdefault)(key[, default]) | Insert key with a value of default if key is not in the dictionary.                                                                                                                                                                |
| [`update`](#fiftyone.core.expression_ast.ListNode.update)([E, ]\*\*F)             | If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v In either case, this is followed by: for k in F:  D[k] = F[k] |
| [`values`](#fiftyone.core.expression_ast.ListNode.values)()                       | Return an object providing a view on the dict's values.                                                                                                                                                                            |

#### t *: Literal['list']*

#### items()

Return a set-like object providing a view on the dict’s items.

#### clear()

Remove all items from the dict.

#### copy()

Return a shallow copy of the dict.

#### *classmethod* fromkeys(iterable, value=None,)

Create a new dictionary with keys from iterable and values set to value.

#### get(key, default=None,)

Return the value for key if key is in the dictionary, else default.

#### keys()

Return a set-like object providing a view on the dict’s keys.

#### pop(k) → v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise,
raise a KeyError.

#### popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order.
Raises KeyError if the dict is empty.

#### setdefault(key, default=None,)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

#### update(\*\*F) → None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k]
If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
In either case, this is followed by: for k in F:  D[k] = F[k]

#### values()

Return an object providing a view on the dict’s values.

### *class* fiftyone.core.expression_ast.DictNode

Bases: `TypedDict`

A dict operand, whose keys and values may themselves be expressions.

**Attributes:**

| [`t`](#fiftyone.core.expression_ast.DictNode.t)             |    |
|-------------------------------------------------------------|----|
| [`entries`](#fiftyone.core.expression_ast.DictNode.entries) |    |

**Methods:**

| [`clear`](#fiftyone.core.expression_ast.DictNode.clear)()                         | Remove all items from the dict.                                                                                                                                                                                                    |
|-----------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`copy`](#fiftyone.core.expression_ast.DictNode.copy)()                           | Return a shallow copy of the dict.                                                                                                                                                                                                 |
| [`fromkeys`](#fiftyone.core.expression_ast.DictNode.fromkeys)(iterable[, value])  | Create a new dictionary with keys from iterable and values set to value.                                                                                                                                                           |
| [`get`](#fiftyone.core.expression_ast.DictNode.get)(key[, default])               | Return the value for key if key is in the dictionary, else default.                                                                                                                                                                |
| [`items`](#fiftyone.core.expression_ast.DictNode.items)()                         | Return a set-like object providing a view on the dict's items.                                                                                                                                                                     |
| [`keys`](#fiftyone.core.expression_ast.DictNode.keys)()                           | Return a set-like object providing a view on the dict's keys.                                                                                                                                                                      |
| [`pop`](#fiftyone.core.expression_ast.DictNode.pop)(k[,d])                        | If the key is not found, return the default if given; otherwise, raise a KeyError.                                                                                                                                                 |
| [`popitem`](#fiftyone.core.expression_ast.DictNode.popitem)()                     | Remove and return a (key, value) pair as a 2-tuple.                                                                                                                                                                                |
| [`setdefault`](#fiftyone.core.expression_ast.DictNode.setdefault)(key[, default]) | Insert key with a value of default if key is not in the dictionary.                                                                                                                                                                |
| [`update`](#fiftyone.core.expression_ast.DictNode.update)([E, ]\*\*F)             | If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v In either case, this is followed by: for k in F:  D[k] = F[k] |
| [`values`](#fiftyone.core.expression_ast.DictNode.values)()                       | Return an object providing a view on the dict's values.                                                                                                                                                                            |

#### t *: Literal['dict']*

#### entries *: List[List[[FieldNode](#fiftyone.core.expression_ast.FieldNode) | [LiteralNode](#fiftyone.core.expression_ast.LiteralNode) | [CallNode](#fiftyone.core.expression_ast.CallNode) | [StaticNode](#fiftyone.core.expression_ast.StaticNode) | [ListNode](#fiftyone.core.expression_ast.ListNode) | [DictNode](#fiftyone.core.expression_ast.DictNode) | [MongoNode](#fiftyone.core.expression_ast.MongoNode)]]*

#### clear()

Remove all items from the dict.

#### copy()

Return a shallow copy of the dict.

#### *classmethod* fromkeys(iterable, value=None,)

Create a new dictionary with keys from iterable and values set to value.

#### get(key, default=None,)

Return the value for key if key is in the dictionary, else default.

#### items()

Return a set-like object providing a view on the dict’s items.

#### keys()

Return a set-like object providing a view on the dict’s keys.

#### pop(k) → v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise,
raise a KeyError.

#### popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order.
Raises KeyError if the dict is empty.

#### setdefault(key, default=None,)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

#### update(\*\*F) → None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k]
If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
In either case, this is followed by: for k in F:  D[k] = F[k]

#### values()

Return an object providing a view on the dict’s values.

### *class* fiftyone.core.expression_ast.MongoNode

Bases: `TypedDict`

Raw MongoDB, for an expression that recorded no syntax.

**Attributes:**

| [`t`](#fiftyone.core.expression_ast.MongoNode.t)       |    |
|--------------------------------------------------------|----|
| [`expr`](#fiftyone.core.expression_ast.MongoNode.expr) |    |

**Methods:**

| [`clear`](#fiftyone.core.expression_ast.MongoNode.clear)()                         | Remove all items from the dict.                                                                                                                                                                                                    |
|------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [`copy`](#fiftyone.core.expression_ast.MongoNode.copy)()                           | Return a shallow copy of the dict.                                                                                                                                                                                                 |
| [`fromkeys`](#fiftyone.core.expression_ast.MongoNode.fromkeys)(iterable[, value])  | Create a new dictionary with keys from iterable and values set to value.                                                                                                                                                           |
| [`get`](#fiftyone.core.expression_ast.MongoNode.get)(key[, default])               | Return the value for key if key is in the dictionary, else default.                                                                                                                                                                |
| [`items`](#fiftyone.core.expression_ast.MongoNode.items)()                         | Return a set-like object providing a view on the dict's items.                                                                                                                                                                     |
| [`keys`](#fiftyone.core.expression_ast.MongoNode.keys)()                           | Return a set-like object providing a view on the dict's keys.                                                                                                                                                                      |
| [`pop`](#fiftyone.core.expression_ast.MongoNode.pop)(k[,d])                        | If the key is not found, return the default if given; otherwise, raise a KeyError.                                                                                                                                                 |
| [`popitem`](#fiftyone.core.expression_ast.MongoNode.popitem)()                     | Remove and return a (key, value) pair as a 2-tuple.                                                                                                                                                                                |
| [`setdefault`](#fiftyone.core.expression_ast.MongoNode.setdefault)(key[, default]) | Insert key with a value of default if key is not in the dictionary.                                                                                                                                                                |
| [`update`](#fiftyone.core.expression_ast.MongoNode.update)([E, ]\*\*F)             | If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v In either case, this is followed by: for k in F:  D[k] = F[k] |
| [`values`](#fiftyone.core.expression_ast.MongoNode.values)()                       | Return an object providing a view on the dict's values.                                                                                                                                                                            |

#### t *: Literal['mongo']*

#### expr *: None | [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | int | float | str | List[None | [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | int | float | str | List[JSONValue] | Dict[str, JSONValue]] | Dict[str, None | [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | int | float | str | List[JSONValue] | Dict[str, JSONValue]]*

#### clear()

Remove all items from the dict.

#### copy()

Return a shallow copy of the dict.

#### *classmethod* fromkeys(iterable, value=None,)

Create a new dictionary with keys from iterable and values set to value.

#### get(key, default=None,)

Return the value for key if key is in the dictionary, else default.

#### items()

Return a set-like object providing a view on the dict’s items.

#### keys()

Return a set-like object providing a view on the dict’s keys.

#### pop(k) → v, remove specified key and return the corresponding value.

If the key is not found, return the default if given; otherwise,
raise a KeyError.

#### popitem()

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order.
Raises KeyError if the dict is empty.

#### setdefault(key, default=None,)

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

#### update(\*\*F) → None.  Update D from mapping/iterable E and F.

If E is present and has a .keys() method, then does:  for k in E.keys(): D[k] = E[k]
If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
In either case, this is followed by: for k in F:  D[k] = F[k]

#### values()

Return an object providing a view on the dict’s values.

### fiftyone.core.expression_ast.AST_VERSION *= 1*

Version of the syntax tree format.

Bump this when a node form changes meaning. Readers reject envelopes they don’t
understand rather than guessing, and fall back to the MongoDB the envelope is
serialized alongside.

### fiftyone.core.expression_ast.AST_KEY *= '_fo_expr'*

Envelope key identifying a serialized expression.

Chosen so it cannot collide with a MongoDB operator (which are `$`-prefixed),
which is what lets a decoder distinguish a persisted expression from a raw
aggregation expression without ambiguity.

### fiftyone.core.expression_ast.records_expression_syntax(cls: [type](fiftyone.brain.internal.core.elasticsearch.md#fiftyone.brain.internal.core.elasticsearch.ElasticsearchSimilarityConfig.type)) → [type](fiftyone.brain.internal.core.elasticsearch.md#fiftyone.brain.internal.core.elasticsearch.ElasticsearchSimilarityConfig.type)

Class decorator that records how each expression was constructed.

Wraps every expression-building method on the class so that the returned
expression carries the operator and operands that produced it. Applied to
[`fiftyone.core.expressions.ViewExpression`](fiftyone.core.expressions.md#fiftyone.core.expressions.ViewExpression), this covers all ~130
operators without touching them individually.

### fiftyone.core.expression_ast.node_of(expr: [ViewExpression](fiftyone.core.expressions.md#fiftyone.core.expressions.ViewExpression)) → [FieldNode](#fiftyone.core.expression_ast.FieldNode) | [LiteralNode](#fiftyone.core.expression_ast.LiteralNode) | [CallNode](#fiftyone.core.expression_ast.CallNode) | [StaticNode](#fiftyone.core.expression_ast.StaticNode) | [ListNode](#fiftyone.core.expression_ast.ListNode) | [DictNode](#fiftyone.core.expression_ast.DictNode) | [MongoNode](#fiftyone.core.expression_ast.MongoNode)

Returns the syntax tree node for an expression.

Expressions built from raw MongoDB have no recorded syntax and yield a
`mongo` node.

### fiftyone.core.expression_ast.is_reconstructible(expr: [ViewExpression](fiftyone.core.expressions.md#fiftyone.core.expressions.ViewExpression)) → [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool)

Whether an expression can be rendered as Python source.

False for expressions built by handing MongoDB to `E({...})`, and for
anything containing such a subexpression.

### fiftyone.core.expression_ast.to_envelope(expr: [ViewExpression](fiftyone.core.expressions.md#fiftyone.core.expressions.ViewExpression)) → Dict[str, Dict[str, int | [FieldNode](#fiftyone.core.expression_ast.FieldNode) | [LiteralNode](#fiftyone.core.expression_ast.LiteralNode) | [CallNode](#fiftyone.core.expression_ast.CallNode) | [StaticNode](#fiftyone.core.expression_ast.StaticNode) | [ListNode](#fiftyone.core.expression_ast.ListNode) | [DictNode](#fiftyone.core.expression_ast.DictNode) | [MongoNode](#fiftyone.core.expression_ast.MongoNode)]]

Serializes an expression as a versioned envelope.

### fiftyone.core.expression_ast.is_envelope(value: Any) → [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool)

Whether a serialized value is an expression envelope.

### fiftyone.core.expression_ast.from_envelope(value: Dict[str, Dict[str, int | [FieldNode](#fiftyone.core.expression_ast.FieldNode) | [LiteralNode](#fiftyone.core.expression_ast.LiteralNode) | [CallNode](#fiftyone.core.expression_ast.CallNode) | [StaticNode](#fiftyone.core.expression_ast.StaticNode) | [ListNode](#fiftyone.core.expression_ast.ListNode) | [DictNode](#fiftyone.core.expression_ast.DictNode) | [MongoNode](#fiftyone.core.expression_ast.MongoNode)]]) → [ViewExpression](fiftyone.core.expressions.md#fiftyone.core.expressions.ViewExpression)

Reconstructs an expression from a versioned envelope.

* **Raises:**
  **ValueError** – if the envelope’s version is not understood, so callers can
      fall back to the MongoDB representation rather than misread a tree

### fiftyone.core.expression_ast.from_node(node: [FieldNode](#fiftyone.core.expression_ast.FieldNode) | [LiteralNode](#fiftyone.core.expression_ast.LiteralNode) | [CallNode](#fiftyone.core.expression_ast.CallNode) | [StaticNode](#fiftyone.core.expression_ast.StaticNode) | [ListNode](#fiftyone.core.expression_ast.ListNode) | [DictNode](#fiftyone.core.expression_ast.DictNode) | [MongoNode](#fiftyone.core.expression_ast.MongoNode)) → [ViewExpression](fiftyone.core.expressions.md#fiftyone.core.expressions.ViewExpression)

Reconstructs an expression from a syntax tree node.

### fiftyone.core.expression_ast.to_python(expr: [ViewExpression](fiftyone.core.expressions.md#fiftyone.core.expressions.ViewExpression), field_var: str = 'F', expr_var: str = 'E') → str

Renders an expression as Python source.

* **Parameters:**
  * **expr** – a [`fiftyone.core.expressions.ViewExpression`](fiftyone.core.expressions.md#fiftyone.core.expressions.ViewExpression)
  * **field_var** ( *"F"*) – the name bound to
    [`fiftyone.core.expressions.ViewField`](fiftyone.core.expressions.md#fiftyone.core.expressions.ViewField)
  * **expr_var** ( *"E"*) – the name bound to
    [`fiftyone.core.expressions.ViewExpression`](fiftyone.core.expressions.md#fiftyone.core.expressions.ViewExpression)
* **Returns:**
  Python source for the expression. Subexpressions built from raw
  MongoDB render as `E(<mongo>)`, which is accurate but opaque.
