Tm1Session
from skipcheck_tm1 import Tm1SessionUsed in the walkthroughs Connect and list your cubes, Test your code against a real TM1, Add TM1 to a Spring Boot application.
One TM1 session, shared by every service. Thread-safe, and safe to share between any number of concurrent callers: TM1 runs requests on one session in parallel.
- Login is lazy and happens once. The first request logs in, and concurrent first requests share that login. Only the login carries the credentials; every other request carries just the session cookie, since a request with credentials and no cookie makes TM1 open another session.
- Close it.
closeends the TM1 session. Otherwise it stays open on the server, counting against its sessions, until it times out. - Any request.
executeandstreamsend anyTm1Request, so anything the services don't cover yet is still reachable.
Build a session with CAM security and a label:
# CAM security, with a label that shows in Sessions and Threads
return (
Tm1Session.builder()
.address("https://tm1.example.com:8010")
.authenticator(auth.cam_namespace("alice", password, "LDAP"))
.session_context("Sales planning")
.build()
)
Or log in with a CAM passport, such as one from exchanging an OIDC token with Cognos:
# CAM passports expire, so the session calls the function for a current one on every login
return Tm1Session.builder().address("https://tm1.example.com:8010").authenticator(auth.cam_passport(cognos)).build()
Send a request no service covers yet, here streaming a collection:
# GET MessageLogEntries through the session itself: the latest 20 entries
newest = ODataQuery.none().order_by_descending(MessageLogEntry.TIME_STAMP).top(20)
return session.stream(Tm1Request.list(ODataPath.of("MessageLogEntries"), newest, MessageLogEntry))
Run a service's requests in a sandbox by giving it a sandbox view of the session:
# The cell: every dimension, in the cube's order
cell = {"Region": "North", "Month": "Jan"}
SandboxService(session).create(SandboxPatch.builder().name("What-if").build())
CellService(session.with_sandbox("What-if")).update("Sales", cell, 1200)
The asyncio flavor, skipcheck_tm1.aio, has the same methods to await, on AsyncTm1Session.
Members
__init__ constructor | The server is base_url (the service root), or address read by dialect (http://tm1:8010 → http://tm1:8010/api/v1/). |
with_sandbox | A view of this session whose requests run in sandbox name. |
without_sandbox | A view of this session whose requests run outside any sandbox, in base data. |
with_change_set | A view of this session whose writes are recorded in change set change_set (its ID, from BeginChangeSet). |
without_change_set | A view of this session whose writes go into no change set. |
with_async | A view of this session whose requests TM1 runs asynchronously (OData's Prefer. |
without_async | A view of this session whose requests run synchronously, as usual. |
batch | Starts a JSON $batch. |
async_every property | How often this view polls an async request's monitor (Java's async()), or None. |
builder static | The settings one by one, as the Java client's Tm1Session.builder(). |
sandbox property | The sandbox this view's requests run in, or None for base data. |
change_set property | The ID of the change set this view's writes are recorded in, or None. |
base_url property | The service root, such as http://localhost:8010/api/v1/, always ending in /. |
logged_in property | Whether it holds a login now (it logs in on the first request). |
is_closed property | Whether close was called. |
impersonating property | The user this session impersonates, if any. |
timeouts property | The session's timeouts, by kind of work. |
error_classifier property | How the session classifies error responses. |
connect | Logs in now, rather than on the first request, and returns this session. |
login | Logs in now (see connect). |
session_id | The TM1 session's ID (ActiveSession's), logging in first if needed. |
close | Ends the TM1 session (ActiveSession/tm1.Close), for every view. |
version | The server's product version, such as 11.8.03500.6. |
capabilities | What the server's own $metadata defines, and its versions. |
service_root property | The service root, such as http://localhost:8010/api/v1/, always ending in /. |
execute | Sends a request and reads its answer; in a batch, queues it and returns a Deferred. |
stream | The items of a collection, fetching pages as they're needed (Java's stream). |
collect | Every item of a collection, as a list, following TM1's next links. |
iterate | The items of a collection, page by page, following TM1's next links. |
request | Sends one request the services have no method for, and returns the raw reply. |
get_json | GET of path, with its answer as parsed JSON. |
__init__
constructor__init__(base_url: str | None = None, authenticator: Authenticator | None = None, *, address: str | None = None, dialect: Tm1Dialect = Tm1Dialect.V11, user: str | None = None, password: str | None = None, impersonate: str | None = None, session_context: str | None = None, sandbox: str | None = None, timeouts: Tm1Timeouts | None = None, error_classifier: Tm1ErrorClassifier | None = None, check_capabilities: bool = True, verify: bool | str | ssl.SSLContext = True, client: httpx2.AsyncClient | None = None, clock: Callable[[], float] | None = None)The server is base_url (the service root), or address read by dialect (http://tm1:8010 → http://tm1:8010/api/v1/). The login is authenticator, or user and password for TM1's own security. See builder for the same settings one by one, as in the Java client.
with_sandbox
with_sandbox(name: str) -> Tm1SessionA view of this session whose requests run in sandbox name: each gets TM1's !sandbox query option, unless the request sets its own. The view shares this session's login, cookie and connections, so it costs nothing; closing either closes both. Derived rather than set on the session, so one caller's sandbox can't leak into another caller's requests. TM1 evaluates NON EMPTY and filters in the request's sandbox, so every request of an operation needs it, cellset reads and deletes included; a service given this view gets that for free. A ValueError if name is blank.
without_sandbox
without_sandbox() -> Tm1SessionA view of this session whose requests run outside any sandbox, in base data.
with_change_set
with_change_set(change_set: str) -> Tm1SessionA view of this session whose writes are recorded in change set change_set (its ID, from BeginChangeSet): each request gets TM1's !ChangeSet query option, unless it sets its own, so UndoChangeSet can revert them together. Like with_sandbox, the view shares this session's login and connections; it keeps the sandbox, if any. A ValueError if the ID is blank.
without_change_set
without_change_set() -> Tm1SessionA view of this session whose writes go into no change set.
with_async
with_async(every: float | timedelta = 1.0) -> Tm1SessionA view of this session whose requests TM1 runs asynchronously (OData's Prefer: respond-async): each returns at once with a monitor, which the client polls every every seconds until the result is there, so a long process or chore never holds a request open for its whole run. Methods return what they always do. Cancelling the call before the result deletes the monitor, which stops the work on TM1: a process run ends as TM1UserException: Cancel. Raw byte requests (document content) aren't sent async. TM1 (11.8) sends no Retry-After, so every is the only pace. A ValueError if every isn't positive.
without_async
without_async() -> Tm1SessionA view of this session whose requests run synchronously, as usual.
batch
batch() -> Tm1SessionBatchStarts a JSON $batch: its Tm1SessionBatch.session is a view of this one (same sandbox and change set) whose requests are queued, and Tm1SessionBatch.run sends them together.
async_every
propertyasync_every: float | NoneHow often this view polls an async request's monitor (Java's async()), or None.
builder
staticbuilder() -> Tm1SessionBuilderThe settings one by one, as the Java client's Tm1Session.builder().
sandbox
propertysandbox: str | NoneThe sandbox this view's requests run in, or None for base data.
change_set
propertychange_set: str | NoneThe ID of the change set this view's writes are recorded in, or None.
base_url
propertybase_url: strThe service root, such as http://localhost:8010/api/v1/, always ending in /.
logged_in
propertylogged_in: boolWhether it holds a login now (it logs in on the first request).
is_closed
propertyis_closed: boolWhether close was called: it sends nothing more.
impersonating
propertyimpersonating: str | NoneThe user this session impersonates, if any.
timeouts
propertytimeouts: Tm1TimeoutsThe session's timeouts, by kind of work.
error_classifier
propertyerror_classifier: Tm1ErrorClassifierHow the session classifies error responses.
connect
connect() -> Tm1SessionLogs in now, rather than on the first request, and returns this session.
login
login() -> NoneLogs in now (see connect).
session_id
session_id() -> intThe TM1 session's ID (ActiveSession's), logging in first if needed.
close
close() -> NoneEnds the TM1 session (ActiveSession/tm1.Close), for every view: waits for a login in progress, and sends nothing if none ever succeeded. Afterwards the session refuses requests with Tm1SessionClosedError.
version
version() -> Tm1VersionThe server's product version, such as 11.8.03500.6.
capabilities
capabilities() -> Tm1CapabilitiesWhat the server's own $metadata defines, and its versions.
service_root
propertyservice_root: strThe service root, such as http://localhost:8010/api/v1/, always ending in /: Java's name for base_url.
execute
execute(request: Tm1Request[Any] | p.Call) -> AnySends a request and reads its answer; in a batch, queues it and returns a Deferred. A collection is read with stream or collect.
stream
stream(request: Tm1Request[Any] | p.Call) -> Iterator[Any]The items of a collection, fetching pages as they're needed (Java's stream). A page is asked for only once the items before it have been taken, and each response is read whole and closed before its items are given, so a stream that is stopped early, or fails, leaves no response open.
collect
collect(request: Tm1Request[Any] | p.Call) -> AnyEvery item of a collection, as a list, following TM1's next links. In a batch, a Deferred of that list: the first page comes in the batch's answer, and the pages after it, if TM1 sent a next link, are fetched with ordinary requests on the same session when the batch runs. TM1 (11.8) doesn't page, so that is untested against a server.
iterate
iterate(call: p.Call) -> Iterator[Any]The items of a collection, page by page, following TM1's next links: what stream iterates, for a call rather than a request. On an async view, the first page may come as an async result, and each page after it is asked for with an ordinary request, as the other clients do: a next link names a page TM1 has ready, not more work to wait for. Can't join a batch.
request
request(method: str, path: ODataPath | str, *, query: ODataQuery | None = None, json_body: Any = None, content: bytes | None = None, headers: dict[str, str] | None = None, accept: str = p.JSON) -> p.ReplySends one request the services have no method for, and returns the raw reply: its status, headers and content. path is relative to the service root; json_body is written as JSON, content sent as it is.
get_json
get_json(path: ODataPath | str, query: ODataQuery | None = None) -> AnyGET of path, with its answer as parsed JSON.