xplain.XplainSession

xplain.XplainSession

class xplain.XplainSession(url=None, user=None, password=None, profile=None, _session=None)

Bases: object

Unified xplain session with namespaced API.

Single entry point for all xplain operations. Every method from both Xsession and XplainClient is accessible through one of 8 namespaces.

Namespaces:

query: Query execution, results, aggregation, navigation select: Selection/filtering, references, selection sets temporal: Relative time dimensions, sequences, longitudinal analysis dimensions: Dimension/attribute CRUD, 30+ calculated dimension types models: Predictive modeling, causal discovery data: Object management, files, import/export, sampling, user data explore: Object structure, hierarchy navigation config: Server settings, performance, diagnostics, batch execution

Examples

Create and query:

from xplain import XplainSession

xp = XplainSession.from_profile("mimic")
xp.startup("Mimic")
df = xp.query.attribute("Patients", "Gender", "Gender")

Selections:

xp.select.values("Patients", "Gender", ["Male"])
xp.select.clear_all()

Temporal analysis:

xp.temporal.time_since(
    event=("Prescriptions", "Date"),
    reference=("Admissions", "AdmitTime"),
    name="DaysSinceAdmit",
    since="first", unit="DAY",
)

Auto-delegated methods (no wrapper needed):

xp.dimensions.add_ratio_dimension(...)
xp.models.build_predictive_model(...)
xp.data.load_object(file={...})
xp.config.set_max_threads(4)
__init__(url=None, user=None, password=None, profile=None, _session=None)

Create a unified xplain session.

Parameters
  • url – Server URL (e.g., “http://localhost:8080”)

  • user – Username

  • password – Password

  • profile – Profile name from ~/.xplainpyrc

  • _session – Pre-created Xsession (internal use)

add_quantile_based_attributes(object_name=None, dimension=None, quantiles=None, quantiles_attribute_name=None, ranges_attribute_name=None, use_names_as_postfix=False, selections=None, sample_size=None, script_file=None, script_file_ownership='PUBLIC')

Generate quantile-based attributes for FLOAT/DOUBLE dimensions.

build_formula(response, predictors)

Dynamically build an R-style formula for Patsy.

build_predictive_model(model_name, xmodel_configuration_file_name, target_event_object)

build predictive model [BETA!!].

build_tree_data(json_object)

Convert complex JSON structure into a format suitable for D3.js tree visualization.

collapsible_tree()

Generate and visualize a collapsible tree using hierarchical data.

property config: xplain.unified_session.config

Server configuration, performance, diagnostics.

convert_to_dataframe(data)

Convert query result JSON to pandas DataFrame format.

count_attribute(attribute_name, object_name=None, dimension_name=None, request_name=None, data_frame=True)

Convenient method to count an attribute. Automatically resolves object and dimension.

create_contingency_table(df, var1, var2)

Create a contingency table (frequency table) for two variables.

property data: xplain.unified_session.data

objects, files, import/export.

Type

Data management

property dimensions: xplain.unified_session.dimensions

Dimension and attribute management (30+ types).

download_result(filename, save_as)

download a file from result directory of server and save it to.

download_selections(objects, selection_set=None)

returns the selection as json for given objects and selection set.

execute_query(query, data_frame=True)

Execute an analytical query and return results.

property explore: xplain.unified_session.explore

Object structure exploration and hierarchy navigation.

classmethod from_profile(profile, **kwargs)

Create session from a named profile in ~/.xplainpyrc.

Parameters
  • profile – Profile name

  • **kwargs – Additional Xsession parameters

Returns

XplainSession instance

classmethod from_session_id(url, session_id)

Attach to an existing server session.

Parameters
  • url – Server URL

  • session_id – Existing HTTP session ID

Returns

XplainSession instance

gen_xtable(data, xtable_config, file_name)

gen_xtable.

get(params=None)

Send a GET request to the /xplainsession endpoint.

get_analysis(**kwargs)

Get analysis as a serializable dict.

Parameters

**kwargs – Options (get_as_script, drop_results, etc.)

get_attribute_info(object_name, dimension_name, attribute_name)

find and retrieves the details of an attribute.

get_current_xplain_session()

Get the current xplain session instance.

get_dimension_info(object_name, dimension_name)

find and retrieves the details of a dimension.

get_full_object_structure()

Returns a flat list of all objects with their parent, dimensions, and attributes.

get_importer()

Get the importer instance for managing database connections and imports.

get_independent_variables_of_model(model_name)

get the list of independent variables of given predictive model.

get_instance_as_dataframe(elements)

get a pandas dataframe representation of the xplain artifacts.

get_model_names()

list all loaded predictive models.

get_object_info(object_name, root=None)

find and display the details of a xobject in json.

get_open_sequences(sequence_name)

Retrieves details of open sequences by name.

get_queries()

get the list of the existing query ids.

get_result(query_name, data_frame=True)

get the result of the query.

get_root_object()

[Beta] Retrieve the root object.

get_selections()

display all global selections in the current xplain session.

get_sequence_transition_matrix(sequence_name)

Retrieves the transition matrix for the specified sequence.

get_session()

get_session.

get_session_id()

Get the current Xplain session identifier.

get_session_state()

Get the current session state dict.

get_state_hierarchy(object_name, dimension_name, attribute_name, state=None, levels=None, request_name=None)

Retrieve the hierarchical structure of states for a given attribute.

get_tree_details(object_name=None, dimension_name=None, attribute_name=None)

get the metadata details of certain xplain object, dimension or.

get_variable_details(model_name, data_frame=True)

Retrieve the details of the independent variables for a predictive model.

get_variable_list(model_name)

get the list of independent variables of given predictive model.

get_xobject(object_name)

[Beta] Retrieve the object with the given name.

http_get(entrypoint, params=None)

Performs an HTTP GET request to the specified endpoint.

http_post(entrypoint, payload_json=None, data=None, files=None, params=None)

Performs an HTTP POST request to the specified endpoint.

list_analyses()

List available xanalysis configurations.

list_existing_analyses()

List available xanalysis configurations.

list_files(ownership, file_type, file_extension=None)

Lists files with the specified ownership and type.

load_analysis(file)

Load a saved analysis.

Parameters

file – File specification dict

load_from_session_id(session_id)

load xplain session by given exisiting session id.

load_result_file_as_df(filename)

Load a file from the session as a pandas DataFrame.

property models: xplain.unified_session.models

Predictive modeling and causal discovery.

open_attribute(object_name, dimension_name, attribute_name, request_name=None, data_frame=True)

Open an attribute and get counts grouped by its values.

open_query(query, data_frame=True)

perform the query and keep it open, the result of this query will be.

open_sequence(target_object, base_object, ranks, reverse, names, name_postfixes, dimensions_2_replicate, sort_dimension, zero_point_dimension, selections, selection_set_definition_rank, floating_semantics, attribute_2_copy, sequence_name, rank_dimension_name, rank_zero_is_first_instance_equal_or_greater_zero_point, transition_attribute, transition_level, open_marginal_queries, open_transition_queries, selection_set)

open_sequence.

perform(payload)

Send POST request against entry point /xplainsession with payload as.

post(payload)

Send POST request against entry point /xplainsession with payload as.

post_and_broadcast(payload)

Send a POST request and notify the backend of session updates.

post_file_download(file_name, file_type, ownership='PUBLIC', team=None, user=None, delete_after_download=True)

Triggers the flat table download functionality in XOE.

print_error()

Print the last error message.

print_last_stack_trace()

Print the stack trace of the last error.

property query: xplain.unified_session.query

Query execution, results, aggregation, navigation.

query_builder(name=None)

Start building a query using the fluent QueryBuilder API.

read_file(ownership, file_type, file_path)

Reads the specified file.

refresh()

synchronize the session content with the backend.

resume_analysis(**kwargs)

Resume a previously saved analysis.

Parameters

**kwargs – Resume parameters (session, file, retain, etc.)

run(method)

perform xplain web api method and broadcast the change to other.

run_py(file_name, options, ownership)

Executes a Python script file on the server.

run_statsmodels(df, formula, model_type='logit')

Fit a statistical model to the provided dataframe using the specified formula and model type.

save_analysis(file=None, **kwargs)

Save current analysis state.

Parameters
  • file – File specification dict

  • **kwargs – Additional save parameters (drop_results, etc.)

property select: xplain.unified_session.select

Selection and filtering operations.

property session_id

Get the current session ID.

set_default_broadcast(broadcast)

set default broadcast behaviour so that other xplain client sharing.

show_tree()

show object tree.

show_tree_details()

Display the details of the object tree.

startup(model)

Load xplain session by given startup configuration file name without file extension

Parameters

startup_file (string) – the file name of startup configuration,

startup_from_xview_config(xview_config)

load xplain session by given view configuration json.

store_xsession(response_json)

Store session details from the response.

structure()

Get the full object structure of the current session.

Returns

Nested object/dimension/attribute structure

Return type

dict

property temporal: xplain.unified_session.temporal

Temporal and longitudinal analysis.

terminate()

End the session and release server resources.

upload_data(file_name)

upload the file from current local directory to data directory on.

upload_xmodel(model_or_path, filename=None, ownership='PUBLIC')

Upload an .xmodel configuration file to the server’s public model store.

validate_db(db_connection_config)

Validates a database connection configuration.