Python Client
Install and use the experimental GridGain 9 Python client to connect to a cluster, configure connections, and work with distributed maps.
This is an experimental API. It can change significantly in later releases.
Getting Started
Prerequisites
To run the Python client, the following is required:
Python 3.10 or newer (3.10, 3.11, 3.12, 3.13 and 3.14 are tested)
Installation
To install Python Client, download it using pip.
pip install pygridgain>=9After this, you can import pygridgain into your project and use it.
import pygridgainLimitations
Current release has the following limitations:
Only Distributed Map API is currently available.
The client only works with binary data.
Connecting to Cluster
To connect to the cluster, use the connect() method:
You can also configure multiple endpoints for the failover and automatic load-balancing:
Client Configuration
Connection Timeout
You can configure client connection timeout with optional connection_timeout parameter. The client will try to connect for the specified time and fail if no connection is established.
The timeout is specified in seconds. To specify smaller time units, use decimals. For example, 10.5 sets the timeout to 10500 milliseconds.
The example below shows how to set client timeout:
Client Heartbeats
You can configure the client to periodically send messages to the server to keep the connection alive and avoid the idle timeout with an optional heartbeat_interval parameter.
By default, client heartbeat interval is set to 1/3 of ignite.clientConnector.idleTimeoutMillis configuration, or 0.5 seconds, whichever is larger. This configuration is sufficient to keep the client active in most scenarios.
The interval is specified in seconds. To specify smaller time units, use decimals. For example, 10.5 sets the heartbeat interval to 10500 milliseconds.
The example below shows how to set heartbeat interval:
SSL Configuration
If the cluster uses SSL encryption, you should specify the ssl configuration to allow the client to connect to the cluster safely. The example below shows how you can provide SSL configuration:
Authentication
If the cluster has authentication enabled, you should provide user credentials for your connection. The example below shows how you can configure authentication:
Working With Distributed Maps
The Python client provides an API for working with distributed maps.
Creating or Getting Map
You can use the get_or_create_binary_map method to get the distributed map. If a map with the specified name exists, the client will get it from the cluster. If not, a new map will be created.
Adding Data to Maps
There are 2 methods that can be used to add data to distributed maps:
putmethod adds a single value.put_allmethod adds a batch of values at the same time. Using this method is functionally equivalent to adding values individually withputmethod, but it works much faster for bigger amount of records..
Iterating Maps Entries
Instead of working with entries one by one, you can iterate through all of them:
Getting Data From Maps
You can check if the specific key exists on the cluster and get it with the following methods:
containsmethod only checks if the entry exists. It does not retrieve the value.getmethod retrieves the value associated with the specified key.
Deleting Data in Maps
You can delete data in distributed maps with the following methods:
popmethod deletes a specific entry and returns the value it used to contain.clearmethod fully removes all data from the distributed map.
Checking Map Information
You can get additional information about distributed maps with the following methods:
countmethod returns the number of entries in the distributed map.emptychecks if the distributed map is empty. This command works much faster thancount() == 0and should be used when you only care about the emptiness of the map.
Last updated
Was this helpful?

