Skip to main content

In-process loopback transport for clamator (pre-1.0).

Project description

clamator-over-memory

In-process loopback transport for clamator. The shared MemoryBus connects a MemoryRpcServer and MemoryRpcClient running in the same Python process.

Install

pip install clamator-over-memory clamator-protocol

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. Wire server and client through a shared bus, talk via ArithClient:

# loopback.py
import asyncio

from clamator_over_memory import MemoryBus, MemoryRpcServer, MemoryRpcClient

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


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


async def main() -> None:
    bus = MemoryBus()
    server = MemoryRpcServer(bus=bus)
    server.register_service(arith_contract, Arith())
    await server.start()

    transport = MemoryRpcClient(bus=bus)
    await transport.start()

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

    await transport.stop()
    await server.stop()


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

MemoryBus() takes no arguments and is the only wiring needed. The loopback is synchronous within a single asyncio task — no timeouts, retries, or stream parameters.

Key surface

  • MemoryBus() — the connecting object passed to both server and client.
  • MemoryRpcServer(bus=...)register_service(contract, handler_obj), start(), stop().
  • MemoryRpcClient(bus=...)start(), stop(). Wrap with a generated *Client proxy for typed calls.

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

  • 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_memory-0.1.0.tar.gz (7.4 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_memory-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for clamator_over_memory-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6fa96f730d149f90e1a7acf76df49400ffacaa393d4cb88e8c2682ed9df0fc70
MD5 c25621ebb2338a997bb2552d908a785f
BLAKE2b-256 4f678edd52c6604f6b117285f9eca38b8e2a98f9f40148e002b51e6fbd7ddacf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for clamator_over_memory-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05b3037453ec603296f5aa7517c8deb7d3e3fa97387b6c5000d89240914af1de
MD5 8ad0dcae399a7d8f48bbf27008f9bcd2
BLAKE2b-256 9be9b9402f6bede5d8e8a46c4ef650f40b4dc1d74ba5186d2b1c2ec1cb7b7ca5

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