Hazelcast Python Client

Hazelcast enables you to use an unparalleled range of massively scalable data structures with your Python applications. You can:

  • Use the Hazelcast Near Cache feature to store frequently read data in your Python process. This provides faster read speeds than traditional caches such as Redis or Memcached.
  • Access all of the Hazelcast data structures plus distributed queues, topics, and more with the Hazelcast IMDG Python Client.
  • Support JSON or serialized objects.

Quick Start + Download

Quick Start

You can install Hazelcast Python Client via:
$ pip install hazelcast-python-client

Downloads

Version Downloads Documentation
Hazelcast IMDG Python Client 5.3.0 (latest)
06/12/2023
Hazelcast IMDG Python Client 5.2.0
03/31/2023
Hazelcast IMDG Python Client 5.1
04/29/2022
Hazelcast IMDG Python Client 4.2.2
10/19/2021

For all downloads please see the Download Archives

Previous Releases

Code Samples

import hazelcast

# Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
client = hazelcast.HazelcastClient()
# Get the Distributed Map from Cluster.
my_map = client.get_map("my-distributed-map").blocking()
# Standard Put and Get
my_map.put("key", "value")
my_map.get("key")
# Concurrent Map methods, optimistic updating
my_map.put_if_absent("somekey", "somevalue")
my_map.replace_if_same("key", "value", "newvalue")
# Shutdown this Hazelcast Client
client.shutdown()
Get this code sample on Github
import hazelcast

# Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
client = hazelcast.HazelcastClient()
# Get a Blocking Queue called "my-distributed-queue"
queue = client.get_queue("my-distributed-queue").blocking()
# Offer a String into the Distributed Queue
queue.offer("item")
# Poll the Distributed Queue and return the String
item = queue.poll()
# Timed blocking Operations
queue.offer("anotheritem", 0.5)
another_item = queue.poll(5)
# Indefinitely blocking Operations
queue.put("yetanotheritem")
print(queue.take())
# Shutdown this Hazelcast Client
client.shutdown()
Get this code sample on Github
import hazelcast


def print_on_message(topic_message):
    print("Got message", topic_message.message)


# Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
client = hazelcast.HazelcastClient()
# Get a Topic called "my-distributed-topic"
topic = client.get_topic("my-distributed-topic").blocking()
# Add a Listener to the Topic
topic.add_listener(print_on_message)
# Publish a message to the Topic
topic.publish("Hello to distributed world")
# Shutdown this Hazelcast Client
client.shutdown()
Get this code sample on Github
import hazelcast

# Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
client = hazelcast.HazelcastClient()
# Get the Distributed List from Cluster.
my_list = client.get_list("my-distributed-list").blocking()
# Add element to the list
my_list.add("item1")
my_list.add("item2")

# Remove the first element
print("Removed:", my_list.remove_at(0))
# There is only one element left
print("Current size is", my_list.size())
# Clear the list
my_list.clear()
# Shutdown this Hazelcast Client
client.shutdown()
Get this code sample on Github
import hazelcast

# Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
client = hazelcast.HazelcastClient()
# Get a Replicated Map called "my-replicated-map"
rmap = client.get_replicated_map("my-replicated-map").blocking()
# Put and Get a value from the Replicated Map
replaced_value = rmap.put("key", "value")
# key/value replicated to all members
print("replaced value =", replaced_value)
# Will be None as its first update
value = rmap.get("key")
# the value is retrieved from a random member in the cluster
print("value for key =", value)
# Shutdown this Hazelcast Client
client.shutdown()
Get this code sample on Github
import hazelcast

# Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
client = hazelcast.HazelcastClient()
# Get the Distributed Set from Cluster.
my_set = client.get_set("my-distributed-set").blocking()
# Add items to the set with duplicates
my_set.add("item1")
my_set.add("item1")
my_set.add("item2")
my_set.add("item2")
my_set.add("item2")
my_set.add("item3")
# Get the items. Note that there are no duplicates.
for item in my_set.get_all():
    print(item)
# Shutdown this Hazelcast Client
client.shutdown()
Get this code sample on Github
import hazelcast

# Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
client = hazelcast.HazelcastClient()
# Get the Distributed MultiMap from Cluster.
multi_map = client.get_multi_map("my-distributed-multimap").blocking()
# Put values in the map against the same key
multi_map.put("my-key", "value1")
multi_map.put("my-key", "value2")
multi_map.put("my-key", "value3")
# Print out all the values for associated with key called "my-key"
values = multi_map.get("my-key")
print(values)
# remove specific key/value pair
multi_map.remove("my-key", "value2")
# Shutdown this Hazelcast Client
client.shutdown()
Get this code sample on Github
import hazelcast

# Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1
client = hazelcast.HazelcastClient()
rb = client.get_ringbuffer("rb").blocking()
# add two items into ring buffer
rb.add(100)
rb.add(200)
# we start from the oldest item.
# if you want to start from the next item, call rb.tailSequence()+1
sequence = rb.head_sequence()
print(rb.read_one(sequence))
sequence += 1
print(rb.read_one(sequence))
# Shutdown this Hazelcast Client
client.shutdown()
Get this code sample on Github