skipcheck

TM1 client · Docs · Reading and writing data

SandboxService

from skipcheck_tm1.services import SandboxService

Sandboxes: private copies of the data a user writes to before publishing. They belong to the user the session is for.

Reading and writing in a sandbox go through a session view: Tm1Session.with_sandbox or Tm1Client.with_sandbox, which add TM1's !sandbox option to every request. This service manages the sandboxes themselves.

Create a sandbox, write to it, and publish the changes to base data:

# Write to a new sandbox, leaving base data alone until the changes are published
cell = {"Version": "Budget", "Region": "North", "Month": "Jan", "Measure": "Revenue"}
tm1.sandboxes.create(SandboxPatch.builder().name("What If").build())
tm1.with_sandbox("What If").cells.update("Sales", cell, 1500)
tm1.sandboxes.publish("What If")

Read a cell in base data and in a sandbox:

# The same cell read in base data and in a sandbox: the same query, through a
# client for each
mdx = (
    "SELECT {[Month].[Month].[Jan]} ON 0, {[Region].[Region].[North]} ON 1 FROM [Sales] WHERE ([Version].[Version].[Budget], [Measure].[Measure].[Revenue])"
)
values = ODataQuery.none().select(CellsetCell.VALUE)

def first(cellset, cells):
    return next(cells).value

base = tm1.cellsets.stream(mdx, values, 1, first)
what_if = tm1.with_sandbox("What If").cellsets.stream(mdx, values, 1, first)
return f"base {base}, what-if {what_if}"

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

Members

listThe session user's sandboxes.
getThe sandbox, or a Tm1NotFoundError if there's none.
createCreates an empty sandbox; it needs a name.
updateChanges the properties the patch sets, such as IncludeInSandboxDimension.
deleteDELETE Sandboxes('name'), with its unpublished changes.
loadLoads the sandbox into memory.
unloadFrees the sandbox's memory, keeping its changes.
discard_changesThrows away the sandbox's changes, keeping the sandbox.
publishWrites the sandbox's changes to base data.
mergeCopies the sandbox's changes into sandbox target.

list

list(query: ODataQuery | None = None, **options: Any) -> list[Sandbox]

GET Sandboxes: the session user's sandboxes.

TM1 REST EntitySet Sandboxes

get

get(name: str, query: ODataQuery | None = None, **options: Any) -> Sandbox

GET Sandboxes('name'): the sandbox, or a Tm1NotFoundError if there's none.

TM1 REST EntitySet Sandboxes

create

create(sandbox: Any) -> Sandbox

POST Sandboxes: creates an empty sandbox; it needs a name.

TM1 REST EntitySet Sandboxes

update

update(name: str, patch: Any) -> None

PATCH Sandboxes('name'): changes the properties the patch sets, such as IncludeInSandboxDimension.

TM1 REST EntitySet Sandboxes

delete

delete(name: str) -> None

DELETE Sandboxes('name'), with its unpublished changes.

TM1 REST EntitySet Sandboxes

load

load(name: str) -> None

tm1.Load: loads the sandbox into memory.

TM1 REST Action Sandbox/Load

unload

unload(name: str) -> None

tm1.Unload: frees the sandbox's memory, keeping its changes.

TM1 REST Action Sandbox/Unload

discard_changes

discard_changes(name: str) -> None

tm1.DiscardChanges: throws away the sandbox's changes, keeping the sandbox.

TM1 REST Action Sandbox/DiscardChanges

publish

publish(name: str, conflicts: ConflictResolution | None = None, allow_queueing: bool = False, clean_after: bool = False) -> None

tm1.Publish: writes the sandbox's changes to base data. With conflicts, the options are sent too: what to do with cells changed in base data since the sandbox's changes, whether to wait for a lock rather than fail (allow_queueing), and whether to empty the sandbox once published (clean_after).

TM1 REST Action Sandbox/Publish

merge

merge(name: str, target: str, conflicts: ConflictResolution | None = None, allow_queueing: bool = False, clean_after: bool = False) -> None

tm1.Merge: copies the sandbox's changes into sandbox target. With conflicts, the options are sent too: what to do with cells the target changed too, whether to wait for a lock rather than fail, and whether to empty this sandbox once merged.

TM1 REST Action Sandbox/Merge