crandas.base#

class crandas.base.Session(base_path=None, **kwargs)#

Bases: object

This object stores the state specific to the connection to the VDL server. By default, the connect() method is invoked lazily, on the first crandas method that requires a connection to the VDL. Because of this, the user can first configure the variables; for example:

>>> import crandas
>>> from crandas.base import session
>>> session.endpoint = "https://example.com:10000/api/v1"
>>> session.base_path = Path("/cranmera")
>>> crandas.DataFrame({})
Raises:
  • ServerError – Passes through error from VDL and appropriate error code

  • ServerError – Passes through error from VDL in case error code is not known

connect()#

Establishes connections with other nodes/server and verifies if crandas and vdl versions are compatible

execute(cmd)#

Queries the VDL to execute the command cmd

Parameters:

cmd ((JSON-serializable) dict) – The command to be executed

Returns:

ret – Output of the VDL query in JSON form

Return type:

JSON

Raises:

ServerError – Passes through error from VDL and appropriate error code

reset()#

Disconnects and resets the current session.

Use this command if the MPC servers have been restarted.

set_base_path(base_path=None)#

Set a new path for the cranmera folder for the session

Parameters:

base_path (string, optional) – an explicit path, by default None

crandas.base.execute(cmd)#

Executes command

crandas.base.json_from_field_element(x)#

Turns field element into JSON string, field elements are represented in JSON as strings

crandas.base.json_to_field_element(x)#

Turns JSON into an integer

crandas.base.logger = <Logger crandas.base (WARNING)>#

Number of bits for the nonce used to guarantee freshness of VDL queries (see the add_nonce argument of vdl_query)

crandas.base.require_connected(fn)#

Creates a wrapper which checks whether the session is connected to the server, connects otherwise