Skip to main content

Remote Procedure Call over Redis on Python

Project description

Remote Procedure Call over Redis

This library provides an RPC implementation over Redis.
To forward a request from the client to the service for the execution of the method, Redis Streams is used together with Consumer Groupss to distribute requests.
To forward the result of the method execution from the service to the client, Redis PubSub is used with unique client and request identifiers

Features

  • Transparent forwarding of arguments and return value
  • Supports/forces the use of Python type hints
  • Built-in consistency check client-side with the server-side
  • Supports multiple server-side instances at the same time, balancing via Redis
  • Zeroconf, does not require open ports, addresses, HTTP API implementation, etc. Only Redis.
  • Uses the built-in capabilities of Redis 5.0+ to forwarding in both directions

Installation

pip install rpc-over-redis

Using

First, you need to declare the server-side (service) app:
server.py

import os
from rpc_over_redis.core import RPCOverRedisService

redis_url = os.environ['REDIS_URL']     # REDIS_URL=redis://:password@redis/0

# initializing server-side
r = RPCOverRedisService(
    redis_url,
    'SmartEchoService'
)

@r.register
def echo() -> None:
    print('echo is called')
    pass

r.run_forever()

Then, you need to create a header class with empty methods.
Now you can use it like a regular class. The arguments and the return value will be transparently passed through Redis

import os
from rpc_over_redis.core import RPCOverRedisClient

class SmartEchoService(RPCOverRedisClient):
    def __init__(self, conn_url: str):
        super().__init__(conn_url, self.__class__.__name__, strict_validate_schema=True)

    def echo(self) -> None:
        ...

# initializing client-side
client = SmartEchoService(os.environ['REDIS_URL'])       # REDIS_URL=redis://:password@redis/0

# execute remote methods as local class methods...
client.echo()  # none returned

More examples see here

Additional options

// TODO

Limitations

  • Only built-in types that allow to be converted to json/string should be used as arguments and return values.

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

rpc-over-redis-0.0.5.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

rpc_over_redis-0.0.5-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file rpc-over-redis-0.0.5.tar.gz.

File metadata

  • Download URL: rpc-over-redis-0.0.5.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for rpc-over-redis-0.0.5.tar.gz
Algorithm Hash digest
SHA256 0d05064461e6b08043dc51cb3b6398285021b06cb02be7bf0a4fa41af81ed39b
MD5 d8d7d93d99187628d7b586c32ae1c15b
BLAKE2b-256 0942529d3a356ebd35605219b6e35170c052defffbc088d2e8c631895dc23bcb

See more details on using hashes here.

File details

Details for the file rpc_over_redis-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: rpc_over_redis-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for rpc_over_redis-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e56468a8f3d56de3555095b4de432181981abd7a9d51af48b521e2dc7ebb8d6e
MD5 0696cd1d2b306d1887823a080bbd9079
BLAKE2b-256 b83fa504f6b62331513685dad9120e4b2fa298fae61de3787ce9a010c0653895

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