skipcheck

TM1 client · Docs · Queries

ODataQuery

from skipcheck_tm1 import ODataQuery

Used in the walkthroughs Connect and list your cubes, Read and write cells, Run a process and read its result, Test your code against a real TM1, Add TM1 to a Spring Boot application.

OData query options: $select, $expand (with nested options), $filter, $orderby, $top, $skip, $count, custom options such as TM1's !sandbox, and parameter aliases. Immutable: each method returns a new query.

query = (
    ODataQuery.none()
    .select("Name", "Type")
    .expand("Hierarchies", lambda h: h.select("Name").top(5))
    .filter(Filter.starts_with(ODataProperty.of("Name"), "Q"))
    .to_query_string()
)
# $select=Name,Type&$expand=Hierarchies($select=Name;$top=5)&$filter=startswith(Name,'Q'), each value encoded

Options are written in a fixed order, lowercase with $ as OData 4.0 requires, and each value is percent-encoded once by to_query_string. Nested options inside $expand are separated by ;.

Members

__init__ constructor
none staticNo options.
of staticquery (or none), with the keyword options added.
selectAdds properties to $select, after any already selected.
expandExpands a navigation property, with nested options.
filterSets $filter, replacing any set before.
order_byAdds an ascending $orderby key, after any keys already added.
order_by_descendingAdds a descending $orderby key, after any keys already added.
topSets $top.
skipSets $skip.
with_countSets $count=true.
optionWith a value, a query with a custom option (!sandbox); without, that option's value, or None (as Java's two option methods).
aliasA parameter alias's value.
is_emptyTrue if this query has no options.
custom propertyThe custom options (those that are not OData system options), by name.
aliases propertyThe parameter aliases, by name with its @, each with its literal or JSON value.
paramsEvery option as (name, value), unencoded, in order.
to_query_stringThe encoded query string, without ?.

__init__

constructor
__init__(select: Any = None, expand: Any = None, filter: Filter | str | None = None, orderby: Any = None, top: int | None = None, skip: int | None = None, count: bool | None = None, search: str | None = None, custom: Mapping[str, str] | None = None, aliases: Mapping[str, str] | None = None)

none

static
none() -> ODataQuery

No options: the server's default response.

of

static
of(query: ODataQuery | None = None, **options: Any) -> ODataQuery

query (or none), with the keyword options added: what service methods do with their query and **options.

select

select(*properties: str | ODataProperty) -> ODataQuery

Adds properties to $select, after any already selected. Like every option here it's an instance method, so it works the same at the top level and inside expand. Returns a new query.

expand

expand(navigation: str | ODataProperty, options: Callable[[ODataQuery], ODataQuery] | ODataQuery | None = None) -> ODataQuery

Expands a navigation property, with nested options: a query, or a function of one (lambda h: h.select("Name")), applied to what's there for it already.

filter

filter(filter: Filter | str) -> ODataQuery

Sets $filter, replacing any set before. Returns a new query.

order_by

order_by(prop: str | ODataProperty) -> ODataQuery

Adds an ascending $orderby key, after any keys already added. Returns a new query.

order_by_descending

order_by_descending(prop: str | ODataProperty) -> ODataQuery

Adds a descending $orderby key, after any keys already added. Returns a new query.

top

top(n: int) -> ODataQuery

Sets $top: at most this many items, zero or more. Returns a new query.

skip

skip(n: int) -> ODataQuery

Sets $skip: skip this many items first, zero or more. Returns a new query.

with_count

with_count() -> ODataQuery

Sets $count=true: include the total number of matching items. Returns a new query.

option

option(name: str, value: str = _MISSING) -> Any

With a value, a query with a custom option (!sandbox); without, that option's value, or None (as Java's two option methods).

alias

alias(alias: Alias | str, literal_or_json: str) -> ODataQuery

A parameter alias's value: Fn(p=@p) with ?@p=….

is_empty

is_empty() -> bool

True if this query has no options.

custom

property
custom: dict[str, str]

The custom options (those that are not OData system options), by name.

aliases

property
aliases: dict[str, str]

The parameter aliases, by name with its @, each with its literal or JSON value.

params

params() -> list[tuple[str, str]]

Every option as (name, value), unencoded, in order.

to_query_string

to_query_string() -> str

The encoded query string, without ?.