Skip to main content

Redis-streams transport for clamator (pre-1.0).

Project description

clamator-over-redis

Redis-streams transport for clamator. Implements the Transport interface from clamator-protocol so JSON-RPC traffic flows over Redis streams between processes — typically a Py service and a TS service, or two Py services on different hosts.

Install

pip install clamator-over-redis clamator-protocol redis

Quickstart

Contracts are authored in TypeScript and the Python sibling is produced by @clamator/codegen:

npx @clamator/codegen --src contracts --out-py generated

The emitted generated/arith.py exports Pydantic models, a typed ArithClient, an ArithService ABC, and the arith_contract Contract object.

Server — subclass the generated ArithService ABC:

# server.py
import asyncio

from clamator_over_redis import RedisRpcServer

from generated.arith import (
    AddParams, AddResult, PingParams, ArithService, arith_contract,
)


class Arith(ArithService):
    async def add(self, params: AddParams) -> AddResult:
        return AddResult(sum=params.a + params.b)

    async def ping(self, params: PingParams) -> None:
        pass


async def main() -> None:
    server = RedisRpcServer(key_prefix="my-app")
    server.register_service(arith_contract, Arith())
    await server.start()
    await asyncio.Event().wait()  # serve until cancelled


if __name__ == "__main__":
    asyncio.run(main())

Client — call methods on the generated ArithClient:

# client.py
import asyncio

from clamator_over_redis import RedisRpcClient

from generated.arith import ArithClient, AddParams


async def main() -> None:
    transport = RedisRpcClient(key_prefix="my-app")
    await transport.start()

    arith = ArithClient(transport)
    result = await arith.add(AddParams(a=2, b=3))
    print(result)  # AddResult(sum=5)

    await transport.stop()


if __name__ == "__main__":
    asyncio.run(main())

By default the connection is built from $REDIS_URL (or redis://localhost:6379). Pass redis_url= for a different URL, or redis= for a pre-built redis.asyncio.Redis instance.

Key surface

  • RedisRpcServer(*, key_prefix, redis=None, redis_url=None, ...)register_service(contract, handler_obj), start(), stop().
  • RedisRpcClient(*, key_prefix, redis=None, redis_url=None, default_timeout_ms=30_000)start(), stop(). The instance is a ClamatorClient, so it can be wrapped by a generated *Client proxy.

When to reach for this vs. clamator-over-memory

  • clamator-over-memory — tests, embedded scenarios, anything single-process.
  • clamator-over-redis — cross-process, cross-host, durable streams, production.

Links

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

clamator_over_redis-0.1.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

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

clamator_over_redis-0.1.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file clamator_over_redis-0.1.0.tar.gz.

File metadata

  • Download URL: clamator_over_redis-0.1.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for clamator_over_redis-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cd2cc1ea26835bfbeceee56b37276f906f2ce35410ca6fdc78c148a236d144f4
MD5 4dfcf100313d665bc0a436e7e65ef564
BLAKE2b-256 99d6868980329de9c1d82925dbb197535e64de2fd02ff16cee1d86ec16425204

See more details on using hashes here.

File details

Details for the file clamator_over_redis-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for clamator_over_redis-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c35fbd917fc803d69a968428e9a221a45f11a485fcfe914fefd7e079aa414a62
MD5 424d446f123e445fab3cd5ad3afb5bf1
BLAKE2b-256 f448cdd15d17e6bfa5a1aee1b51e2b6c5bf0d49a5ca57280817a09a9d8db221a

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