Skip to main content

Python implementation of a Redis-compatible API using websockets.

Project description

PyPI version npm version Coverage Status PyTest zincware

ZnSocket - Redis-like Key-Value Store in Python

ZnSocket provides a Redis-compatible API using python-socketio and Python objects for storage. It is designed for testing and applications requiring key-value storage while being easily installable via pip. For production, consider using redis-py and a Redis instance.

[!IMPORTANT] ZnSocket is not designed for large data. The maximum size for a single communication is 100 MB. Although this value can be adapted, you will notice slow data transfers for large files.

Installation

To install ZnSocket, use:

pip install znsocket

Example

Start the ZnSocket server using the CLI:

znsocket --port 5000

For additional options, run:

znsocket --help

Here's a simple example of how to use the ZnSocket client:

from znsocket import Client

# Connect to the ZnSocket server
c = Client.from_url("znsocket://127.0.0.1:5000")

# Set and get a value
c.set("name", "Fabian")
assert c.get("name") == "Fabian"

[!NOTE] ZnSocket does not encode/decode strings. Using it is equivalent to using Redis.from_url(storage, decode_responses=True) in the Redis client.

Lists

ZnSocket provides a synchronized version of the Python list implementation. Unlike a regular Python list, the data in znsocket.List is not stored locally; instead, it is dynamically pushed to and pulled from the server.

Below is a step-by-step example of how to use znsocket.List to interact with a ZnSocket server.

from znsocket import Client, List

# Connect to the ZnSocket server using the provided URL
client = Client.from_url("znsocket://127.0.0.1:5000")

# Create a synchronized list associated with the specified key
sync_list = List(r=client, key="list:1")

# Extend the list with multiple elements
sync_list.extend(["a", "b", "c", "d"])

# Print every second element from the list
print(sync_list[::2])

Dicts

ZnSocket provides a synchronized version of the Python dict implementation similar to the list implementation.

Below is a step-by-step example of how to use znsocket.Dict to interact with a ZnSocket server.

from znsocket import Client, Dict

# Connect to the ZnSocket server using the provided URL
client = Client.from_url("znsocket://127.0.0.1:5000")

# Create a synchronized dict associated with the specified key
sync_dict = Dict(r=client, key="dict:1")

# Add an item to the synchronized dict
sync_dict["Hello"] = "World"

# Print the added item
print(sync_dict["Hello"])

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

znsocket-0.2.5.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

znsocket-0.2.5-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file znsocket-0.2.5.tar.gz.

File metadata

  • Download URL: znsocket-0.2.5.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for znsocket-0.2.5.tar.gz
Algorithm Hash digest
SHA256 c6181237638bb2e087d09ad9e73e9d0c8099348fca788b89c26bb923257cf2a8
MD5 4385e2902c2d3932615bb46aba66174b
BLAKE2b-256 d464779e66101170234edd1d4c860e6aa24a337d2daf0422f4a6b3fbe21a8ba7

See more details on using hashes here.

File details

Details for the file znsocket-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: znsocket-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for znsocket-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 d4682ea0ee4ff872502b1a6ad5ecd8050e53918329a261307fd88a0e3feefec5
MD5 b3acb9cc772d503d2855758de531c326
BLAKE2b-256 c5dc8879ff346faf4c9170533ff53f6a0fd0c0bdb9c8dcb73f89880876e1743c

See more details on using hashes here.

Supported by

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