skipcheck

TM1 client · Docs · Dimensions and hierarchies

SubsetService

from skipcheck_tm1.services import SubsetService

Subsets: a hierarchy's public, private and session subsets (SubsetScope), their elements, and the operations bound to a subset or creating a session subset.

A static subset lists its elements; a dynamic one has an MDX Expression. Binding Elements in a subset PATCH appends to them, so update refuses it: add_elements appends by name and clear_elements empties the list.

Create a static subset, binding its elements:

# A static subset lists its elements, bound by their paths
elements = ODataPath.of("Dimensions").key("Region").nav("Hierarchies").key("Region").nav("Elements")
key_regions = SubsetPatch.builder().name("Key Regions").bind_elements(elements.key("North"), elements.key("South")).build()
return tm1.subsets.create("Region", "Region", SubsetScope.PUBLIC, key_regions)

Create a dynamic subset from an MDX expression:

# A dynamic subset has an MDX expression, evaluated each time it's read
leaves = SubsetPatch.builder().name("All Leaves").expression("{TM1FILTERBYLEVEL({TM1SUBSETALL([Region].[Region])}, 0)}").build()
return tm1.subsets.create("Region", "Region", SubsetScope.PUBLIC, leaves)

Replace a static subset's elements:

# A PATCH appends elements, so empty the list, then add the new ones in order
tm1.subsets.clear_elements("Region", "Region", SubsetScope.PUBLIC, "Key Regions")
tm1.subsets.add_elements("Region", "Region", SubsetScope.PUBLIC, "Key Regions", ["East", "West"])

Create a session subset and read its elements by the name TM1 gave it:

# TM1 names a session subset itself, ignoring the name sent: read it by the name
# it gives back
regions = SubsetPatch.builder().name("Regions").expression("{[Region].[Region].[Total].Children}").build()
subset = tm1.subsets.create_session_subset("Region", "Region", regions)
assert subset.name is not None
elements = tm1.subsets.elements("Region", "Region", SubsetScope.SESSION, subset.name, ODataQuery.none().select(Element.NAME))
return [element.name for element in elements]

The asyncio flavor, skipcheck_tm1.aio, has the same methods to await, on AsyncSubsetService.

Members

listGET …/Hierarchies('h')/Subsets (or the private or session ones).
getGET …/Subsets('s').
createCreates a subset.
updateChanges the properties the patch sets, such as a dynamic subset's expression; with etag, only if it hasn't changed since it was read.Raises ValueError if the patch sets or binds Elements, which TM1 appends.
add_elementsPATCH …/Subsets('s') binding Elements.
clear_elementsRemoves every element from a static subset; the elements stay in the hierarchy.
deleteDELETE …/Subsets('s').
elementsA static subset's elements in order, or what a dynamic one's expression gives now.
hierarchyGET …/Subsets('s')/Hierarchy.
save_asCopies a subset under a new name.
set_elementAdds an element to a static subset, or moves it if it's there.
set_element_beforetm1.SetElement with Before.
set_element_aftertm1.SetElement with After.
create_session_subsettm1.CreateSessionSubset with a definition.
create_session_subset_fromtm1.CreateSessionSubset with a reference.

list

list(dimension: str, hierarchy: str, scope: SubsetScope, query: ODataQuery | None = None, **options: Any) -> list[Subset]

GET …/Hierarchies('h')/Subsets (or the private or session ones). TM1 (11.8) lists no session subsets, though each reads by the name create_session_subset returned.

get

get(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, query: ODataQuery | None = None, **options: Any) -> Subset

GET …/Subsets('s').

create

create(dimension: str, hierarchy: str, scope: SubsetScope, subset: Any) -> Subset

POST …/Subsets: creates a subset: static with Elements@odata.bind (SubsetPatch.Builder.bind_elements), dynamic with an Expression.

update

update(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, patch: Any, etag: str | None = None) -> None

PATCH …/Subsets('s'): changes the properties the patch sets, such as a dynamic subset's expression; with etag, only if it hasn't changed since it was read.

Raises ValueError if the patch sets or binds Elements, which TM1 appends: use add_elements or clear_elements.

add_elements

add_elements(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, elements: Sequence[str]) -> None

PATCH …/Subsets('s') binding Elements: appends elements to a static subset, in order.

clear_elements

clear_elements(dimension: str, hierarchy: str, scope: SubsetScope, subset: str) -> None

DELETE …/Subsets('s')/Elements/$ref: removes every element from a static subset; the elements stay in the hierarchy.

TM1 REST Navigation Subset/Elements

delete

delete(dimension: str, hierarchy: str, scope: SubsetScope, subset: str) -> None

DELETE …/Subsets('s').

elements

elements(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, query: ODataQuery | None = None, **options: Any) -> list[Element]

GET …/Subsets('s')/Elements: a static subset's elements in order, or what a dynamic one's expression gives now.

TM1 REST Navigation Subset/Elements

hierarchy

hierarchy(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, query: ODataQuery | None = None, **options: Any) -> Hierarchy

GET …/Subsets('s')/Hierarchy.

TM1 REST Navigation Subset/Hierarchy

save_as

save_as(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, new_name: str, make_private: bool | None = None, make_static: bool | None = None) -> Subset

tm1.SaveAs: copies a subset under a new name: by default as public and keeping whether it's static or dynamic; make_private and make_static change that (a static copy holds the elements a dynamic one gives now).

TM1 REST Action Subset/SaveAs

set_element

set_element(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, element: str) -> None

tm1.SetElement: adds an element to a static subset, or moves it if it's there. TM1 (11.8) appends it when no position is given.

TM1 REST Action Subset/SetElement

set_element_before

set_element_before(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, element: str, before: str) -> None

tm1.SetElement with Before: places an element just before another in a static subset.

TM1 REST Action Subset/SetElement

set_element_after

set_element_after(dimension: str, hierarchy: str, scope: SubsetScope, subset: str, element: str, after: str) -> None

tm1.SetElement with After: places an element just after another in a static subset.

TM1 REST Action Subset/SetElement

create_session_subset

create_session_subset(dimension: str, hierarchy: str, definition: Any) -> Subset

tm1.CreateSessionSubset with a definition: creates a subset visible only to this session. TM1 (11.8) ignores the definition's Name and names it itself (like an ID, yExesF4AAIABAAAQ); the result has the name to use.

TM1 REST Action Hierarchy/CreateSessionSubset

create_session_subset_from

create_session_subset_from(dimension: str, hierarchy: str, scope: SubsetScope, subset: str) -> Subset

tm1.CreateSessionSubset with a reference: copies a subset into one visible only to this session.

TM1 REST Action Hierarchy/CreateSessionSubset