Skip to main content

Hazelcast Python Client

Project description

PyPI Read the Docs License

Hazelcast is an open-source distributed in-memory data store and computation platform that provides a wide variety of distributed data structures and concurrency primitives.

Hazelcast Python client is a way to communicate to Hazelcast clusters and access the cluster data. The client provides a Future-based asynchronous API suitable for wide ranges of use cases.

Installation

Hazelcast

Hazelcast Python client requires a working Hazelcast cluster to run. This cluster handles the storage and manipulation of the user data.

A Hazelcast cluster consists of one or more cluster members. These members generally run on multiple virtual or physical machines and are connected to each other via the network. Any data put on the cluster is partitioned to multiple members transparent to the user. It is therefore very easy to scale the system by adding new members as the data grows. Hazelcast cluster also offers resilience. Should any hardware or software problem causes a crash to any member, the data on that member is recovered from backups and the cluster continues to operate without any downtime.

The quickest way to start a single member cluster for development purposes is to use our Docker images.

docker run -p 5701:5701 hazelcast/hazelcast:latest

You can also use our ZIP or TAR distributions. Once you have downloaded, you can start the Hazelcast member using the bin/hz-start script.

Client

pip install hazelcast-python-client

Overview

Usage

import hazelcast

# Connect to Hazelcast cluster.
client = hazelcast.HazelcastClient()

# Get or create the "distributed-map" on the cluster.
distributed_map = client.get_map("distributed-map")

# Put "key", "value" pair into the "distributed-map" and wait for
# the request to complete.
distributed_map.set("key", "value").result()

# Try to get the value associated with the given key from the cluster
# and attach a callback to be executed once the response for the
# get request is received. Note that, the set request above was
# blocking since it calls ".result()" on the returned Future, whereas
# the get request below is non-blocking.
get_future = distributed_map.get("key")
get_future.add_done_callback(lambda future: print(future.result()))

# Do other operations. The operations below won't wait for
# the get request above to complete.

print("Map size:", distributed_map.size().result())

# Shutdown the client.
client.shutdown()

If you are using Hazelcast and the Python client on the same machine, the default configuration should work out-of-the-box. However, you may need to configure the client to connect to cluster nodes that are running on different machines or to customize client properties.

Configuration

import hazelcast

client = hazelcast.HazelcastClient(
    cluster_name="cluster-name",
    cluster_members=[
        "10.90.0.2:5701",
        "10.90.0.3:5701",
    ],
    lifecycle_listeners=[
        lambda state: print("Lifecycle event >>>", state),
    ]
)

print("Connected to cluster")
client.shutdown()

Refer to the documentation to learn more about supported configuration options.

Features

  • Distributed, partitioned and queryable in-memory key-value store implementation, called Map

  • Eventually consistent cache implementation to store a subset of the Map data locally in the memory of the client, called Near Cache

  • Additional data structures and simple messaging constructs such as Set, MultiMap, Queue, Topic

  • Cluster-wide unique ID generator, called FlakeIdGenerator

  • Distributed, CRDT based counter, called PNCounter

  • Distributed concurrency primitives from CP Subsystem such as FencedLock, Semaphore, AtomicLong

  • Similarity search using VectorCollection (Beta)

  • Integration with Hazelcast Cloud

  • Support for serverless and traditional web service architectures with Unisocket and Smart operation modes

  • Ability to listen to client lifecycle, cluster state, and distributed data structure events

  • and many more

Getting Help

You can use the following channels for your questions and development/usage issues:

Contributing

We encourage any type of contribution in the form of issue reports or pull requests.

Issue Reports

For issue reports, please share the following information with us to quickly resolve the problems:

  • Hazelcast and the client version that you use

  • General information about the environment and the architecture you use like Python version, cluster size, number of clients, Java version, JVM parameters, operating system etc.

  • Logs and stack traces, if any

  • Detailed description of the steps to reproduce the issue

Pull Requests

Contributions are submitted, reviewed and accepted using the pull requests on GitHub. For an enhancement or larger feature, please create a GitHub issue first to discuss.

Development

  1. Clone the GitHub repository.

  2. Run python setup.py install to install the Python client.

If you are planning to contribute:

  1. Run pip install -r requirements-dev.txt to install development dependencies.

  2. Use black to reformat the code by running the black --config black.toml . command.

  3. Use mypy to check type annotations by running the mypy hazelcast command.

  4. Make sure that tests are passing by following the steps described in the next section.

Testing

In order to test Hazelcast Python client locally, you will need the following:

  • Supported Java virtual machine <https://docs.hazelcast.com/hazelcast/latest/deploy/versioning-compatibility#supported-java-virtual-machines>

  • Apache Maven <https://maven.apache.org/>

Set the environment variables for credentials:

export HZ_SNAPSHOT_INTERNAL_USERNAME=YOUR_MAVEN_USERNAME
export HZ_SNAPSHOT_INTERNAL_PASSWORD=YOUR_MAVEN_PASSWORD

Following command starts the tests:

python3 run_tests.py

Test script automatically downloads hazelcast-remote-controller and Hazelcast. The script uses Maven to download those.

License

Apache 2.0 License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hazelcast_python_client-5.7.0.tar.gz (350.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hazelcast_python_client-5.7.0-py3-none-any.whl (572.8 kB view details)

Uploaded Python 3

File details

Details for the file hazelcast_python_client-5.7.0.tar.gz.

File metadata

  • Download URL: hazelcast_python_client-5.7.0.tar.gz
  • Upload date:
  • Size: 350.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for hazelcast_python_client-5.7.0.tar.gz
Algorithm Hash digest
SHA256 79e7c6e77453e53af29bb2454504e1b8d3a422527813116ee44379c18ee9849f
MD5 9378c16c7b3f359f1be46024f6ff2fd0
BLAKE2b-256 36edf0336ad540c7689ace88c4fcc59ec160e72e8c296d6fabd8f18a7a7c3e13

See more details on using hashes here.

File details

Details for the file hazelcast_python_client-5.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hazelcast_python_client-5.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6a218295af38730bd1781a6b2fefbf24851f1d6abb472f0bfe927a281b3f83b7
MD5 d9a3e98c553aaa02636de9880d3a1ea5
BLAKE2b-256 95d62bf6347f6a346ca7462cb048d1a20dfce3ba3ad8cb9d525e88abc95123f8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page