pyignite.client module

This module contains Client class, that lets you communicate with Apache Ignite cluster node by the means of Ignite binary client protocol.

To start the communication, you may connect to the node of their choice by instantiating the Client object and calling connect() method with proper parameters.

The whole storage room of Ignite cluster is split up into named structures, called caches. For accessing the particular cache in key-value style (a-la Redis or memcached) you should first create the Cache object by calling create_cache() or get_or_create_cache() methods, than call Cache methods. If you wish to create a cache object without communicating with server, there is also a get_cache() method that does just that.

For using Ignite SQL, call sql() method. It returns a generator with result rows.

register_binary_type() and query_binary_type() methods operates the local (class-wise) registry for Ignite Complex objects.

class pyignite.client.Client(compact_footer: Optional[bool] = None, partition_aware: bool = True, event_listeners: Optional[Sequence] = None, **kwargs)

Synchronous Client implementation.

__init__(compact_footer: Optional[bool] = None, partition_aware: bool = True, event_listeners: Optional[Sequence] = None, **kwargs)

Initialize client.

For the use of the SSL-related parameters see https://docs.python.org/3/library/ssl.html#ssl-certificates.

Parameters
  • compact_footer – (optional) use compact (True, recommended) or full (False) schema approach when serializing Complex objects. Default is to use the same approach the server is using (None). Apache Ignite binary protocol documentation on this topic: https://ignite.apache.org/docs/latest/binary-client-protocol/data-format#schema

  • partition_aware – (optional) try to calculate the exact data placement from the key before to issue the key operation to the server node, True by default,

  • event_listeners – (optional) event listeners,

  • timeout – (optional) sets timeout (in seconds) for each socket operation including connect. 0 means non-blocking mode, which is virtually guaranteed to fail. Can accept integer or float value. Default is None (blocking mode),

  • handshake_timeout – (optional) sets timeout (in seconds) for performing handshake (connection) with node. Default is 10.0 seconds,

  • use_ssl – (optional) set to True if Ignite server uses SSL on its binary connector. Defaults to use SSL when username and password has been supplied, not to use SSL otherwise,

  • ssl_version – (optional) SSL version constant from standard ssl module. Defaults to TLS v1.2,

  • ssl_ciphers – (optional) ciphers to use. If not provided, ssl default ciphers are used,

  • ssl_cert_reqs

    (optional) determines how the remote side certificate is treated:

    • ssl.CERT_NONE − remote certificate is ignored (default),

    • ssl.CERT_OPTIONAL − remote certificate will be validated, if provided,

    • ssl.CERT_REQUIRED − valid remote certificate is required,

  • ssl_keyfile – (optional) a path to SSL key file to identify local (client) party,

  • ssl_keyfile_password – (optional) password for SSL key file, can be provided when key file is encrypted to prevent OpenSSL password prompt,

  • ssl_certfile – (optional) a path to ssl certificate file to identify local (client) party,

  • ssl_ca_certfile – (optional) a path to a trusted certificate or a certificate chain. Required to check the validity of the remote (server-side) certificate,

  • username – (optional) user name to authenticate to Ignite cluster,

  • password – (optional) password to authenticate to Ignite cluster.

close()

This property remembers Complex object schema encoding approach when decoding any Complex object, to use the same approach on Complex object encoding.

Returns

True if compact schema was used by server or no Complex object decoding has yet taken place, False if full schema was used.

connect(*args)

Connect to Ignite cluster node(s).

Parameters

args – (optional) host(s) and port(s) to connect to.

create_cache(settings: Union[str, dict]) pyignite.cache.Cache

Creates Ignite cache by name. Raises CacheError if such a cache is already exists.

Parameters

settings – cache name or dict of cache properties’ codes and values. All cache properties are documented here: Cache Properties. See also the cache creation example,

Returns

Cache object.

get_best_node(cache: Union[int, str, pyignite.cache.BaseCache], key: Optional[Any] = None, key_hint: Optional[pyignite.datatypes.base.IgniteDataType] = None) pyignite.connection.connection.Connection

Returns the node from the list of the nodes, opened by client, that most probably contains the needed key-value pair. See IEP-23.

This method is not a part of the public API. Unless you wish to extend the pyignite capabilities (with additional testing, logging, examining connections, et c.) you probably should not use it.

Parameters
  • cache – Ignite cache, cache name or cache id,

  • key – (optional) pythonic key,

  • key_hint – (optional) Ignite data type, for which the given key should be converted,

Returns

Ignite connection object.

get_binary_type(binary_type: Union[str, int]) dict

Gets the binary type information from the Ignite server. This is quite a low-level implementation of Ignite thin client protocol’s OP_GET_BINARY_TYPE operation. You would probably want to use query_binary_type() instead.

Parameters

binary_type – binary type name or ID,

Returns

binary type description − a dict with the following fields:

  • type_exists: True if the type is registered, False otherwise. In the latter case all the following fields are omitted,

  • type_id: Complex object type ID,

  • type_name: Complex object type name,

  • affinity_key_field: string value or None,

  • is_enum: False in case of Complex object registration,

  • schemas: a list, containing the Complex object schemas in format: OrderedDict[field name: field type hint]. A schema can be empty.

get_cache(settings: Union[str, dict]) pyignite.cache.Cache

Creates Cache object with a given cache name without checking it up on server. If such a cache does not exist, some kind of exception (most probably CacheError) may be raised later.

Parameters

settings – cache name or cache properties (but only PROP_NAME property is allowed),

Returns

Cache object.

get_cache_names() list

Gets existing cache names.

Returns

list of cache names.

get_cluster() pyignite.cluster.Cluster

Get client cluster facade.

Returns

Cluster instance.

get_or_create_cache(settings: Union[str, dict]) pyignite.cache.Cache

Creates Ignite cache, if not exist.

Parameters

settings – cache name or dict of cache properties’ codes and values. All cache properties are documented here: Cache Properties. See also the cache creation example,

Returns

Cache object.

property partition_aware
property partition_awareness_supported_by_protocol
property protocol_context

Returns protocol context, or None, if no connection to the Ignite cluster was not yet established.

This method is not a part of the public API. Unless you wish to extend the pyignite capabilities (with additional testing, logging, examining connections, et c.) you probably should not use it.

put_binary_type(type_name: str, affinity_key_field: str = None, is_enum=False, schema: dict = None)

Registers binary type information in cluster. Do not update binary registry. This is a literal implementation of Ignite thin client protocol’s OP_PUT_BINARY_TYPE operation. You would probably want to use register_binary_type() instead.

Parameters
  • type_name – name of the data type being registered,

  • affinity_key_field – (optional) name of the affinity key field,

  • is_enum – (optional) register enum if True, binary object otherwise. Defaults to False,

  • schema – (optional) when register enum, pass a dict of enumerated parameter names as keys and an integers as values. When register binary type, pass a dict of field names: field types. Binary type with no fields is OK.

query_binary_type(binary_type: Union[int, str], schema: Optional[Union[int, dict]] = None)

Queries the registry of Complex object classes.

Parameters
  • binary_type – Complex object type name or ID,

  • schema – (optional) Complex object schema or schema ID

Returns

found dataclass or None, if schema parameter is provided, a dict of {schema ID: dataclass} format otherwise.

property random_node: pyignite.connection.connection.Connection

Returns random usable node.

This method is not a part of the public API. Unless you wish to extend the pyignite capabilities (with additional testing, logging, examining connections, et c.) you probably should not use it.

register_binary_type(data_class: Type, affinity_key_field: Optional[str] = None)

Register the given class as a representation of a certain Complex object type. Discards autogenerated or previously registered class.

Parameters
  • data_class – Complex object class,

  • affinity_key_field – (optional) affinity parameter.

register_cache(cache_id: int)
sql(query_str: str, page_size: int = 1024, query_args: Optional[Iterable] = None, schema: str = 'PUBLIC', statement_type: int = 0, distributed_joins: bool = False, local: bool = False, replicated_only: bool = False, enforce_join_order: bool = False, collocated: bool = False, lazy: bool = False, include_field_names: bool = False, max_rows: int = - 1, timeout: int = 0, cache: Optional[Union[int, str, pyignite.cache.Cache]] = None) pyignite.cursors.SqlFieldsCursor

Runs an SQL query and returns its result.

Parameters
  • query_str – SQL query string,

  • page_size – (optional) cursor page size. Default is 1024, which means that client makes one server call per 1024 rows,

  • query_args – (optional) query arguments. List of values or (value, type hint) tuples,

  • schema – (optional) schema for the query. Defaults to PUBLIC,

  • statement_type

    (optional) statement type. Can be:

    • StatementType.ALL − any type (default),

    • StatementType.SELECT − select,

    • StatementType.UPDATE − update.

  • distributed_joins – (optional) distributed joins. Defaults to False,

  • local – (optional) pass True if this query should be executed on local node only. Defaults to False,

  • replicated_only – (optional) whether query contains only replicated tables or not. Defaults to False,

  • enforce_join_order – (optional) enforce join order. Defaults to False,

  • collocated – (optional) whether your data is co-located or not. Defaults to False,

  • lazy – (optional) lazy query execution. Defaults to False,

  • include_field_names – (optional) include field names in result. Defaults to False,

  • max_rows – (optional) query-wide maximum of rows. Defaults to -1 (all rows),

  • timeout – (optional) non-negative timeout value in ms. Zero disables timeout (default),

  • cache – (optional) Name or ID of the cache to use to infer schema. If set, ‘schema’ argument is ignored,

Returns

sql fields cursor with result rows as a lists. If include_field_names was set, the first row will hold field names.

tx_start(concurrency: pyignite.datatypes.transactions.TransactionConcurrency = TransactionConcurrency.PESSIMISTIC, isolation: pyignite.datatypes.transactions.TransactionIsolation = TransactionIsolation.REPEATABLE_READ, timeout: int = 0, label: Optional[str] = None) pyignite.transaction.Transaction

Start thin client transaction.

Parameters
  • concurrency – (optional) transaction concurrency, see TransactionConcurrency,

  • isolation – (optional) transaction isolation level, see TransactionIsolation,

  • timeout – (optional) transaction timeout in milliseconds,

  • label – (optional) transaction label.

Returns

Transaction instance.

unwrap_binary(value: Any) Any

Detects and recursively unwraps Binary Object or collections of BinaryObject.

Parameters

value – anything that could be a Binary Object or collection of BinaryObject,

Returns

the result of the Binary Object unwrapping with all other data left intact.