sasctl.services.cas_management#

class sasctl._services.cas_management.CASManagement[source]#

Bases: Service

The CAS Management service provides the ability to manage and perform actions on common resources as they relate to Cloud Analytic Services (CAS).

classmethod create_session(properties: dict, server: str | None = None)[source]#

Creates a new session on the CAS server.

Parameters:
  • properties (dict) – Properties of the session. Valid keys are authenticationType (required), locale, name, nodeCount, timeOut.

  • server (str) – Name of the CAS server. Defaults to ‘cas-shared-default’.

Returns:

RestObj

classmethod del_table(name: str, query_params: dict | None = None, caslib: str | None = None, server: str | None = None)[source]#

Deletes a table from Caslib source. Note that is not an unload. This operation physically removes the source table (if the source is writable). For path-based caslibs, this physically removes the file.

Parameters:
  • name (str) – Name of the table.

  • query_params (dict) – Query parameters. The allowed query parameters are sessionId, sourceTableName, quiet, removeAcs. Note that the last three are required.

  • caslib (str) – Name of the caslib. Defaults to ‘Public’

  • server (str) – Server where the caslib is registered. Defaults to ‘cas-shared-default’.

Returns:

RestObj

Raises:

ValueError – If query_params is empty

classmethod delete_session(sess_id: str, server: str | None = None, query_params: dict | None = None)[source]#

Terminates a session on the CAS server.

Parameters:
  • sess_id (str) – A string indicating the Session id.

  • server (str) – Name of the CAS server. Defaults to ‘cas-shared-default’.

  • query_params (dict, optional) – Query parameters. Valid keys are force, superUserSessionId.

Returns:

RestObj

classmethod get_caslib(name: str, server: str | None = None)[source]#

Get a caslib by name.

Parameters:
  • name (str) – Name of the caslib

  • server (str, optional) – Name of the CAS server. Defaults to ‘cas-shared-default’.

Returns:

RestObj or None

classmethod get_server(item, refresh=False)#

Return a server instance.

Parameters:
  • item (str or dict) – Name, ID, or dictionary representation of the server.

  • refresh (bool, optional) – Obtain an updated copy of the server.

Returns:

RestObj or None – A dictionary containing the server attributes or None.

Notes

If item is a complete representation of the server it will be returned unless refresh is set. This prevents unnecessary REST calls when data is already available on the client.

classmethod get_table(name: str, caslib: str | dict | None = None, server: str | None = None)[source]#

Get a table by name.

Parameters:
  • name (str) – Name of the table.

  • caslib (str or dict, optional) – Name, ID, or dictionary representation of the caslib. Defaults to CASUSER.

  • server (str, optional) – Server where the caslib is registered.

Returns:

RestObj or None

classmethod list_caslibs(server: str | dict, filter_: str | None = None)[source]#

List caslibs available on a server.

Parameters:
  • server (str or dict) – Name, ID, or dictionary representation of the server.

  • filter (str, optional) – A formatted filter string.

Returns:

list – A collection of RestObj instances.

classmethod list_servers(filter=None, start=None, limit=None, **kwargs)#

List all servers available in the environment.

Parameters:
  • filter (str, optional)

  • start (int, optional) – Zero-based index of the first item to return. Defaults to 0.

  • limit (int, optional) – The maximum number of items to return. Defaults to 20.

Returns:

list – A list of dictionaries containing the servers.

Notes

See the filtering reference for details on the filter parameter.

classmethod list_sessions(query_params: dict | None = None, server: str | None = None)[source]#

Returns a collection of sessions available on the CAS server.

Parameters:
  • query_params (dict, optional) – Query parameters. Valid keys are start, limit, filter, sortBy, excludeItemLink, sessionId.

  • server (str, optional) – Name of the CAS server. Defaults to ‘cas-shared-default’.

Returns:

list – A collection of RestObj instances.

classmethod list_tables(caslib: str | dict, server: str | None = None, filter_: str | None = None)[source]#

List tables available in a caslib.

Parameters:
  • caslib (str or dict) – Name, ID, or dictionary representation of the caslib.

  • server (str, optional) – Server where the caslib is registered.

  • filter (str, optional) – Filter string in the https://developer.sas.com/reference/filtering / format.

Returns:

list – A collection of RestObj instances.

classmethod promote_table(name: str, sess_id: str, caslib: str, server: str | None = None)[source]#

Changes the scope of a loaded CAS table from session to global scope. Operation valid only on a session table. Promote target is the same Caslib that contains the session table.

Parameters:
  • name (str) – Name of the table.

  • sess_id (str) – The session ID

  • caslib (str) – Name of the caslib.

  • server (str) – Server where the caslib is registered. Defaults to ‘cas-shared-default’.

Returns:

RestObj

classmethod save_table(name: str, caslib: str, properties: dict | None = None, sess_id: str | None = None, server: str | None = None)[source]#

Saves a CAS table to a source table

Parameters:
  • name (str) – Name of the table.

  • sess_id (str) – The session ID

  • caslib (str) – Name of the caslib.

  • properties (dict, optional) – Properties of the table. Valid keys are caslibName, format, replace, compress, tableName, sourceTableName, parameters.

  • server (str) – Server where the caslib is registered. Defaults to ‘cas-shared-default’.

Returns:

RestObj

classmethod update_state_table(value: str, name: str, caslib: str | None = None, server: str | None = None, *, query_params: dict | None = None, body: dict | None = None)[source]#

Modifies the state of a table to loaded or unloaded. Returns loaded or unloaded to indicate the state after the operation.

Parameters:
  • value (str) – State to which to set the table. Valid values include loaded or unloaded.

  • name (str) – Name of the table.

  • caslib (str, optional) – Name of the caslib. Defaults to ‘Public’.

  • server (str, optional) – Server where the caslib is registered. Defaults to ‘cas-shared-default’.

  • query_params (dict, optional) – Additional query parameters. Valid keys are sessionId, scope, sourceTableName, createRelationships

  • body (dict, optional) – Extra instructions providing greater control over the output when a state change to loaded is requested. Valid keys are copies, label, outputCaslibName, outputTableName, parameters, replace, replaceMode, scope.

Returns:

RestObj

classmethod upload_file(file: str | TextIO, name: str, caslib: str | None = None, server: str | None = None, header: bool | None = None, format_: str | None = None, *, detail: dict | None = None)[source]#

Upload a file to a CAS table.

Uploads the contents of a CSV, XLS, XLSX, SAS7BDT or SASHDAT file to a newly created CAS table.

Parameters:
  • file (str or TextIO) – File containing data to upload or path to the file.

  • name (str) – Name of the table to create

  • caslib (str, optional) – caslib in which the table will be created. Defaults to ‘Public’.

  • server (str, optional) – CAS server on which the table will be created. Defaults to cas-shared-default.

  • header (bool, optional) – Whether the first row of data contains column headers. Defaults to True.

  • format (str, optional) – Choose from {“csv”, “xls”, “xlsx”, “sas7bdat”, “sashdat”}. File of input file. Not required if format can be discerned from the file path.

  • detail (dict, optional) – Additional body parameters. Allowed parameters are ‘sessionId’, ‘variables’, ‘label’, ‘scope’, ‘replace’, ‘encoding’, ‘allowTruncation’, ‘allowEmbeddedNewLines’, ‘delimiter’, ‘varchars’, ‘scanRows’, ‘threadCount’, ‘stripBlanks’, ‘sheetName’, ‘password’, ‘decryptionKey’, ‘stringLengthMultiplier’, ‘varcharConversionThreshold’.

Returns:

RestObj – Table reference

sasctl._services.cas_management.check_keys(valid_keys: list, input_keys: list, parameters: str)[source]#

Compares the input_keys against the valid_keys to see if they are allowed to be passed as parameters in the request.

Parameters:
  • valid_keys (list) – List of allowed parameters

  • input_keys (list) – List of input parameters

  • parameters (str) – String describing the type of parameters that are being tested.

Raises:

ValueError – if input_keys are not valid

sasctl._services.cas_management.check_required_key(required_key: str | list, input_keys: list, parameters: str)[source]#

Check whether the required parameters are in the list of input_key.

Parameters:
  • required_key (str or list) – Required parameters

  • input_keys (list) – The input parameters

  • parameters (str) – String describing the type of parameters that are being tested.

Raises:
  • ValueError – if required_key is not present.

  • TypeError – if required_key is neither a list or a string.