Abstract Backend provides a pluggable backend layer for Python services. Applications code against shared protocols while concrete providersโRedis, Kafka, AWS SQS, or your own implementationโare discovered at runtime. Install a provider with pip, remove it with pip uninstall, and keep your business logic unchanged.
- ๐ซ Stop copying backend code โ Extracted from real MCP server projects so multiple services can share the same queue abstraction.
- ๐ Protocol-first design โ Contracts live in
abe/types.py, keeping providers honest with structural typing and contract tests. - ๐ Runtime discovery โ
load_backend()selects implementations via Python entry points, driven by environment variables. - ๐ Operational clarity โ Logging helpers, contract suites, and documentation make backends observable and portable.
- ๐ฎ Queue provider protocols covering publish, consume, and lifecycle operations.
- โ๏ธ AsyncLoopConsumer helper to execute handlers against any compliant backend.
- ๐ชต Logging utilities for consistent configuration across providers and apps.
- ๐งช Contract tests to validate third-party implementations.
- ๐ Documentation & examples detailing architecture, provider lifecycle, and runtime flow.
Install the core library:
pip install abstract-backendThen install one or more providers, for example the Redis backend:
pip install abe-redisSet QUEUE_BACKEND=redis (the entry-point exposed by abe-redis) and load_backend() will resolve the correct provider at runtime.
from abe.backends.message_queue.loader import load_backend
from abe.backends.message_queue.consumer import AsyncLoopConsumer
async def process(payload: dict[str, object]) -> None:
...
async def main() -> None:
backend = load_backend()
consumer = AsyncLoopConsumer(backend, group="billing")
await consumer.run(process)See docs/contents/development/architecture/ for diagrams explaining the flow and provider relationships.
- Implement the protocols from
abe/types.py(especiallyMessageQueueBackendProtocol). - Expose a
from_env()constructor for runtime configuration. - Register an entry point under
abe.backends.message_queueinpyproject.toml. - Run the contract tests in
test/contract_test/backends/message_queue/against your provider. - Publish your package to PyPI; users activate it with
pip installandQUEUE_BACKEND.
The showcase at /docs/src/pages/showcase.tsx highlights template and reference implementations such as abe-redis.
- Install dev dependencies with
uv pip install -r pyproject.tomlor your preferred tool. - Run tests:
uv run pytest. - Type checking:
uv run mypy. - Linting:
uv run pylint abe tests.
The project follows black formatting and pylint linting (see .pre-commit-config.yaml).
- Developer docs live under
docs/contents/development/and include architecture, provider lifecycle, and layer integration guides. - A Showcase page (
/docs/src/pages/showcase.tsx) lists template and implementation repositories with release badges. - Run
cd docs && pnpm startfor local previews.
- GitHub Actions definitions reside in
.github/workflows/. - Reusable workflows leverage the logging, testing, and packaging helpers of this project.
docusaurus.config.tsanddocs/contents/development/sidebars.tsmanage documentation navigation.
This project is licensed under the MIT License.