Server-side decorators for caching, tracking, and queue emission. Polyglot sibling of the Node `server-decorator` npm package.
Project description
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.
License
MIT.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file server_decorator-2.0.0.tar.gz.
File metadata
- Download URL: server_decorator-2.0.0.tar.gz
- Upload date:
- Size: 126.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42bd14b58afe1c522dbf361f139b6fcce5b482abfd34ea2f3f68358d27f84fa3
|
|
| MD5 |
d5e54c4d91ea3abc93bb9595978941cb
|
|
| BLAKE2b-256 |
0f16ed3476d53c7f6848d140977c8142d9f634b685886c980b776954ea664e02
|
Provenance
The following attestation bundles were made for server_decorator-2.0.0.tar.gz:
Publisher:
publish-python.yml on montionugera/node-server-decorator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
server_decorator-2.0.0.tar.gz -
Subject digest:
42bd14b58afe1c522dbf361f139b6fcce5b482abfd34ea2f3f68358d27f84fa3 - Sigstore transparency entry: 1485902114
- Sigstore integration time:
-
Permalink:
montionugera/node-server-decorator@5b1a6c749aaebff69657e1ce82222ae9281318a7 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/montionugera
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@5b1a6c749aaebff69657e1ce82222ae9281318a7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file server_decorator-2.0.0-py3-none-any.whl.
File metadata
- Download URL: server_decorator-2.0.0-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0af7511b5d23e165e60f97effce892d3f2a77cbbbe7b84f35c8c135bba253d32
|
|
| MD5 |
8cacc2b36a3d2b68942a8761872f144d
|
|
| BLAKE2b-256 |
1778a4edd1126b33f005b70e78654f36645a013ff32519a0b5e7e9d0d685bfcf
|
Provenance
The following attestation bundles were made for server_decorator-2.0.0-py3-none-any.whl:
Publisher:
publish-python.yml on montionugera/node-server-decorator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
server_decorator-2.0.0-py3-none-any.whl -
Subject digest:
0af7511b5d23e165e60f97effce892d3f2a77cbbbe7b84f35c8c135bba253d32 - Sigstore transparency entry: 1485902132
- Sigstore integration time:
-
Permalink:
montionugera/node-server-decorator@5b1a6c749aaebff69657e1ce82222ae9281318a7 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/montionugera
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@5b1a6c749aaebff69657e1ce82222ae9281318a7 -
Trigger Event:
push
-
Statement type: