pydeephaven.session#
This module implements the Session class which provides methods to connect to and interact with the Deephaven server.
- class Session(host=None, port=None, auth_type='Anonymous', auth_token='', never_timeout=True, session_type='python', use_tls=False, tls_root_certs=None, client_cert_chain=None, client_private_key=None, client_opts=None, extra_headers=None)[source]#
Bases:
object
A Session object represents a connection to the Deephaven data server. It contains a number of convenience methods for asking the server to create tables, import Arrow data into tables, merge tables, run Python scripts, and execute queries.
Session objects can be used in Python with statement so that whatever happens in the with statement block, they are guaranteed to be closed upon exit.
- tables#
names of the global tables available in the server after running scripts
- Type:
list[str]
- is_alive#
check if the session is still alive (may refresh the session)
- Type:
bool
Initializes a Session object that connects to the Deephaven server
- Parameters:
host (str) – the host name or IP address of the remote machine, default is ‘localhost’
port (int) – the port number that Deephaven server is listening on, default is 10000
auth_type (str) – the authentication type string, can be “Anonymous’, ‘Basic”, or any custom-built authenticator in the server, such as “io.deephaven.authentication.psk.PskAuthenticationHandler”, default is ‘Anonymous’.
auth_token (str) – the authentication token string. When auth_type is ‘Basic’, it must be “user:password”; when auth_type is “Anonymous’, it will be ignored; when auth_type is a custom-built authenticator, it must conform to the specific requirement of the authenticator
never_timeout (bool) – never allow the session to timeout, default is True
session_type (str) – the Deephaven session type. Defaults to ‘python’
use_tls (bool) – if True, use a TLS connection. Defaults to False
tls_root_certs (bytes) – PEM encoded root certificates to use for TLS connection, or None to use system defaults. If not None implies use a TLS connection and the use_tls argument should have been passed as True. Defaults to None
client_cert_chain (bytes) – PEM encoded client certificate if using mutual TLS. Defaults to None, which implies not using mutual TLS.
client_private_key (bytes) – PEM encoded client private key for client_cert_chain if using mutual TLS. Defaults to None, which implies not using mutual TLS.
client_opts (List[Tuple[str,Union[int,str]]) –
list of tuples for name and value of options to the underlying grpc channel creation. Defaults to None, which implies not using any channel options. See https://grpc.github.io/grpc/cpp/group__grpc__arg__keys.html for a list of valid options. Example options:
- [ (‘grpc.target_name_override’, ‘idonthaveadnsforthishost’),
(‘grpc.min_reconnect_backoff_ms’, 2000) ]
extra_headers (Dict[bytes, bytes]) – additional headers (and values) to add to server requests. Defaults to None, which implies not using any extra headers.
- Raises:
DHError –
- bind_table(name, table)[source]#
Binds a table to the given name on the server so that it can be referenced by that name.
- close()[source]#
Closes the Session object if it hasn’t timed out already.
- Raises:
DHError –
- Return type:
None
- import_table(data)[source]#
Imports the pyarrow table as a new Deephaven table on the server.
Deephaven supports most of the Arrow data types. However, if the pyarrow table contains any field with a data type not supported by Deephaven, the import operation will fail.
- input_table(schema=None, init_table=None, key_cols=None)[source]#
Creates an InputTable from either Arrow schema or initial table. When key columns are provided, the InputTable will be keyed, otherwise it will be append-only.
- property is_alive#
Whether the session is alive.
- plugin_client(exportable_obj)[source]#
Wraps a ticket as a PluginClient. Capabilities here vary based on the server implementation of the ObjectType, but most will at least send a response payload to the client, possibly including references to other objects. In some cases, depending on the server implementation, the client will also be able to send the same sort of messages back to the server.
Part of the experimental plugin API.
- Return type:
- query(table)[source]#
Creates a Query object to define a sequence of operations on a Deephaven table.
- run_script(script)[source]#
Runs the supplied Python script on the server.
- Parameters:
script (str) – the Python script code
- Raises:
DHError –
- Return type:
None
- time_table(period, start_time=None, blink_table=False)[source]#
Creates a time table on the server.
- Parameters:
period (Union[int, str]) – the interval at which the time table ticks (adds a row); units are nanoseconds or a time interval string, e.g. “PT00:00:.001” or “PT1S”
start_time (Union[int, str]) – the start time for the time table in nanoseconds or as a date time formatted string; default is None (meaning now)
blink_table (bool, optional) – if the time table should be a blink table, defaults to False
- Return type:
- Returns:
a Table object
- Raises:
DHError –