linkr
Async messaging framework with three delivery modes: RPC, task and event.
Install
pip install linkr
Core model: App and mode servers
App— application infrastructure and client: lifecycle (init/close), hooks, middleware, exception handlers, serializers, and client operations (call,send,emit).- Mode servers — servers bound to an
Appand a queue scope. Each mode has its own server type and API:rpc = app.rpc(path=None, *, options=None)→RPC:@rpc.method(...),rpc.consume(),rpc.stop_consume()worker = app.worker(path=None, *, options=None)→Worker:@worker.task(...),worker.consume(),worker.stop_consume()bus = app.bus(path=None, *, options=None)→Bus:@bus.subscribe(...),bus.consume(),bus.stop_consume()
path=None (root) uses base queue app.name; path="group" uses base queue app.name.group. options configures backend-specific queue options for that server (QueueOptions, a sequence, or None). Repeated calls for the same mode/path return the same server when options match.
Delivery modes
| Mode | Registration | Client (App) |
Behaviour |
|---|---|---|---|
| RPC | @rpc.method("foo") |
await app.client.call("app.foo", (), {}) |
One consumer handles the call and returns a result. |
| Task | @worker.task("send") |
await app.client.send("app.email.send", (), {"user_id": 1}) |
One of the consumers handles the task. No result. |
| Event | @bus.subscribe("user.created") |
await app.client.emit("user.created", {"user_id": 1}) |
Matching subscribers receive the event. No result. |
Client methods take positional arguments as a tuple and keyword arguments as a dict:
await app.client.call("app.add", (2, 3), {})
await app.client.call("app.add", (), {"x": 2, "y": 3})
await app.client.send("app.email.send", (), {"user_id": 1})
await app.client.emit("user.created", {"user_id": 1})
Health checks
App and backends expose healthcheck() -> HealthStatus(ready, health):
ready=False, health=None— app/backend is not ready (not initialized, closed, or probe failed).ready=True, health=...— backend is ready andhealthreflects dependency/consumer health (backend-specific).
App.healthcheck() normalizes backend failures to HealthStatus(ready=False, health=None) and never returns the backend's HealthStatus instance.
LocalBackend reports healthy when ready; RmqBackend checks live AMQP connection/channel and broker-visible consumers for active queues (in parallel).
Handlers, local names, and addressing
Handler names in decorators are local to the server (leaf names, without .). The server scope defines the queue:
rpc = app.rpc()→ base queueapp@rpc.method("method")registers RPC leafmethodon queueapp(fully qualified:app.method)
rpc = app.rpc("group")→ base queueapp.group@rpc.method("method")registers RPC leafmethodon queueapp.group(fully qualified:app.group.method)
Calls use the queue-qualified path:
await app.client.call("app.method", (), {}) # root RPC server
await app.client.call("app.group.method", (), {}) # group RPC server
The last segment is the handler leaf; everything before it resolves to the target queue (same queue-qualified convention for send).
Example
import asyncio
from linkr import App, LocalBackend
async def main() -> None:
app = App("app", backend=LocalBackend())
root_rpc = app.rpc()
root_worker = app.worker()
@root_rpc.method("method")
def method() -> str:
return "root"
@root_worker.task("task")
async def task() -> None:
...
group_rpc = app.rpc("group")
group_worker = app.worker("group")
@group_rpc.method("method") # local name "method", not "group.method"
def group_method() -> str:
return "group"
@group_worker.task("task")
async def group_task() -> None:
...
await app.init()
await root_rpc.consume()
await root_worker.consume()
await group_rpc.consume()
await group_worker.consume()
print(await app.client.call("app.method", (), {})) # root server
print(await app.client.call("app.group.method", (), {})) # group server
await root_rpc.stop_consume()
await root_worker.stop_consume()
await group_rpc.stop_consume()
await group_worker.stop_consume()
await app.close()
asyncio.run(main())
RPC
Each RPC server consumes its queue and dispatches by leaf method name within that queue. Multiple RPC methods registered on the same server share that server's queue.
async with App("orders", backend=LocalBackend()) as app:
rpc = app.rpc()
@rpc.method("foo")
def foo() -> str:
return "foo"
@rpc.method("bar")
def bar() -> str:
return "bar"
await rpc.consume()
print(await app.client.call("orders.foo", (), {}))
print(await app.client.call("orders.bar", (), {}))
Use separate servers for separate queues/groups:
app = App("orders", backend=LocalBackend())
sa = app.rpc("serviceA")
sb = app.rpc("serviceB")
@sa.method("foo")
def foo() -> str:
return "foo"
@sb.method("bar")
def bar() -> str:
return "bar"
await app.init()
await sa.consume()
await sb.consume()
await app.client.call("orders.serviceA.foo", (), {})
await app.client.call("orders.serviceB.bar", (), {})
Tasks
A task has no response. Multiple consumers may listen on the same task queue; each task is handled by exactly one of them.
async with App("worker", backend=LocalBackend()) as app:
worker = app.worker("email")
@worker.task("send")
async def send_email(user_id: int) -> None:
...
await worker.consume()
await app.client.send("worker.email.send", (), {"user_id": 1})
Events
Events are published by topic (app.client.emit) and delivered to subscribers whose patterns match. Each Bus server has its own event queue and consumes only the subscriptions registered on that server.
async with App("billing", backend=LocalBackend()) as app:
bus = app.bus()
@bus.subscribe("user.created")
def on_user_created(user_id: int) -> None:
...
await bus.consume()
await app.client.emit("user.created", {"user_id": 1})
Wildcards are supported:
*matches exactly one segment:user.*matchesuser.created.#matches zero or more segments:user.#matchesuser.createdanduser.profile.updated.
Multiple subscribers in the same bus for the same topic are all called. Different bus servers (each with its own event queue) that subscribe to a matching topic will each receive the event.
Lifecycle and consuming
rpc = app.rpc()
worker = app.worker("email")
bus = app.bus()
await app.init()
await rpc.consume()
await worker.consume()
await bus.consume()
await rpc.stop_consume() # pause/resume per server
await worker.stop_consume()
await bus.stop_consume()
await app.close()
App.init()initializes the backend and middleware.App.close()stops all servers, closes middleware and backend.server.consume()starts consuming for that server (idempotent when already consuming).server.stop_consume()stops consuming for that server (pause). Handler registrations and subscriptions remain, so consuming can be started again.- There are no global
app.consume()/app.stop_consume()methods and no mode argument; manage consuming per mode server.
Queue options
Backend-specific queue options are configured per server when creating it:
from linkr.backends.rmq import RmqQueueOptions # backend-specific
rpc = app.rpc("serviceA", options=[RmqQueueOptions(prefetch_count=5, durable=True)])
email = app.worker("email", options=[RmqQueueOptions(prefetch_count=50)])
bus = app.bus(options=[RmqQueueOptions(prefetch_count=10)])
@rpc.method("ping")
def ping() -> str:
return "pong"
await app.init()
await rpc.consume()
Options are opaque to App; the active backend selects the types it understands. LocalBackend ignores transport options.
Hooks and middleware
Hooks and middleware are configured on App and apply across its servers:
from linkr import App, AppMiddleware, LocalBackend
from linkr.models import Request, Response
class LoggingMiddleware(AppMiddleware):
async def dispatch_server(self, call_next, request: Request) -> Response | None:
return await call_next()
app = App("orders", backend=LocalBackend(), middlewares=[LoggingMiddleware()])
See docs/ for details on hooks, middleware, dependency injection, validation, serializers, contracts, and backends.
Backends
LocalBackend— in-process backend for development/tests (no broker).RmqBackend— RabbitMQ backend (install extra:pip install "linkr[rabbitmq]").
License
MIT
Metadata
Release files for linkr 0.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| linkr-0.8.1.tar.gz | 47.0 kB | Without provenance | Details for linkr-0.8.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| linkr-0.8.1-py3-none-any.whl | Python 3 | none | any | Details for linkr-0.8.1-py3-none-any.whl |
Total release size: 98.8 kB
Release files / linkr-0.8.1.tar.gz
| Download URL | linkr-0.8.1.tar.gz |
|---|---|
| Size | 47.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f4ecd4e26bbc4f83eba89cfed5da83a2f0f95ef297a4a6d301bd101e8e558f27
|
|
BLAKE2b-256 checksum How to use checksums |
fc5e1b03a1619e20a0b1b88dd34c2846ba3f937e2b6d267ee5b9a45a83d45588
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.2 CPython/3.14.3 Darwin/27.2.0
|
Release files / linkr-0.8.1-py3-none-any.whl
| Download URL | linkr-0.8.1-py3-none-any.whl |
|---|---|
| Size | 51.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf3ec6c513592bc0a61f98e39872b35af310ccdc718acfdea0a15c51973b8e90
|
|
BLAKE2b-256 checksum How to use checksums |
ca61b913c8fd0772cb2f7c44fbc49d8d8019bfbcd2343cd4ab5e67a26fabd1bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.2 CPython/3.14.3 Darwin/27.2.0
|
Security for linkr 0.8.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.