server-decorator (Python)
Server-side decorators for caching, tracking, and queue emission. Polyglot sibling of the Node server-decorator npm package — both share the wire-format contracts in ../../../contracts.
Install
pip install server-decorator # core
pip install server-decorator[redis] # + redis adapter
pip install server-decorator[rabbitmq] # + aio-pika adapter
pip install server-decorator[kafka] # + aiokafka adapter
pip install server-decorator[all] # all adapters
Requires Python 3.10+. asyncio only — no trio/anyio (Decision #10).
Quick start
Method form
from server_decorator import tracking, cache, emit_on_success, CACHE_MISS
class InMemoryCache:
def __init__(self): self._d = {}
def get(self, key): return self._d.get(key, CACHE_MISS)
def set(self, key, val, ttl): self._d[key] = val
class OrderService:
@tracking
@cache(InMemoryCache(), ttl=300)
@emit_on_success(use_events=True)
async def create_order(self, customer_id: str, total: float) -> dict:
return {"customer_id": customer_id, "total": total, "status": "pending"}
Class form (auto-wrap every public method)
from server_decorator import tracking_class
@tracking_class()
class OrderService:
async def create_order(self, ...): ... # auto-wrapped
async def cancel_order(self, ...): ... # auto-wrapped
def _internal(self): ... # SKIPPED (leading underscore)
tracking_class, cache_class, and emit_on_success_class accept include, exclude, and include_private to override the default predicates.
Sync vs async
Method-level decorators auto-detect coroutines via inspect.iscoroutinefunction and wrap accordingly (Decision #5). For @emit_on_success(use_queue=True) on a sync method called outside an event loop, the side effect runs on a single-worker ThreadPoolExecutor so the caller doesn't block (D-C). To drain in-flight emits at process exit:
import atexit
from server_decorator.decorators.emit_on_success import _EMIT_EXECUTOR
atexit.register(_EMIT_EXECUTOR.shutdown, wait=True)
Caching None / falsy values
CacheAdapter.get returns CACHE_MISS (a module-level sentinel) when a key is absent — None/0/""/False are valid cached values. See ../../../contracts/rules/cache-adapter.md.
Consuming events
from server_decorator import ConsumerRegistry, on_event, RedisStreamConsumer
import redis.asyncio as redis
registry = ConsumerRegistry()
registry.register(
"orders",
RedisStreamConsumer(redis.from_url("redis://localhost:6379"), stream="orders", group="email-svc"),
)
@on_event("OrderService.createOrder", consumer="orders")
async def send_email(payload, meta):
... # return -> ack; raise -> redelivered
await registry.start()
# ... app runs ...
await registry.stop()
Delivery is at-least-once. A message can be delivered more than once (e.g. a crash between handler success and ack). Handlers must be idempotent. Ordering is not guaranteed under redelivery. Unparseable messages are acked + skipped; only handler failures stay pending for retry.
Available consumers
| Consumer | Dependency |
|---|---|
RedisStreamConsumer |
pip install server-decorator[redis] |
KafkaConsumer |
[kafka] |
RabbitMQConsumer |
[rabbitmq] |
BullMQConsumer |
[bullmq] |
All backends deliver at-least-once, so handlers must be idempotent; failed
messages stay pending/unacked (Redis/RabbitMQ) or are retried per attempts
(Kafka offset is not committed / BullMQ job attempts).
License
MIT.
Metadata
Release files for server-decorator 2.0.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| server_decorator-2.0.14-py3-none-any.whl | Python 3 | none | any | Details for server_decorator-2.0.14-py3-none-any.whl |
Release files / server_decorator-2.0.14-py3-none-any.whl
| Download URL | server_decorator-2.0.14-py3-none-any.whl |
|---|---|
| Size | 56.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4e0195c26eeef2a4f48ce90c8ffaef62cdd9f0dd36a4a8a0bdccb7ee41dd5cef
|
|
BLAKE2b-256 checksum How to use checksums |
7dd932e33b974bd330a965efd936e202468c58ae5c30844792236b0c60d26af3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.
Transparency logSecurity for server-decorator 2.0.14
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.
Full provenance
1 file in this release has been uploaded with provenance metadata.
Attestation for server_decorator-2.0.14-py3-none-any.whl
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 4, 2026.
Transparency logA 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.