Python Backlooms framework
Project description
Backlooms
Backlooms is a modular Python framework designed for building robust microservices with a strong focus on background workers, dependency injection, and seamless integration with FastAPI and SQLAlchemy.
It provides a structured way to manage your application's lifecycle, configuration, and command-line interface.
Key Features
- Application Orchestration: A central
Applicationclass to wire up configuration, dependency injection, workers, and server adapters. - Dependency Injection: Effortless DI powered by
dependency-injector, with automatic module wiring and a convenient@injectdecorator. - Background Workers: A standardized way to define long-lived background tasks with graceful shutdown and lifecycle management.
- FastAPI Integration: Out-of-the-box support for FastAPI via a dedicated server adapter.
- Database Layer: Built-on top of SQLAlchemy and SQLModel, providing a clean Repository pattern and migration support (via Alembic).
- Flexible Auth: Modular authentication system supporting JWT, Bearer tokens, and password-based login.
- Async CLI: Unified command-line interface based on Typer, with native support for
asynccommands.
Installation
pip install backlooms
Note: Depending on your needs, you might want to install extra dependencies:
pip install "backlooms[db]" # For database support
pip install "backlooms[fastapi]" # For FastAPI integration
pip install "backlooms[full]" # For all features
Quick Start
1. Define Configuration
from backlooms import BaseConfig
class MyConfig(BaseConfig):
PROJECT_NAME: str = "My Microservice"
DATABASE_URL: str = "postgresql+asyncpg://user:pass@localhost/db"
2. Set Up Dependency Injection
from backlooms import DIContainer, inject
from dependency_injector import providers
from dependency_injector.wiring import Provide
class MyContainer(DIContainer):
# Your services and repositories go here
# config is automatically available as a provider
pass
@inject
async def my_function(service = Provide[MyContainer.my_service]):
await service.do_something()
3. Create a Background Worker
from backlooms.workers import BaseWorker
from contextlib import asynccontextmanager
class MyWorker(BaseWorker):
NAME = "my-worker"
DESCRIPTION = "Does important background work"
@asynccontextmanager
async def lifespan(self):
print("Worker starting...")
yield self
print("Worker stopping...")
4. Run the Application
from backlooms import Application
from backlooms.workers import WorkerRegistry
from backlooms.server.adapters.fastapi import FastAPIServerAdapter
from fastapi import APIRouter
# Setup workers
registry = WorkerRegistry()
registry.add(MyWorker)
# Setup server
router = APIRouter()
adapter = FastAPIServerAdapter(router=router, host="0.0.0.0", port=8000)
app = Application(
config=MyConfig(),
container_cls=MyContainer,
workers=registry,
server_adapter=adapter
)
if __name__ == "__main__":
app.run()
CLI Usage
Backlooms automatically generates a CLI for your application.
-
Run a specific worker:
python main.py run my-worker
-
Start server and all workers:
python main.py start
-
Start only the server:
python main.py start --server-only
-
Selective workers:
python main.py start --without-my-worker
Database & Repositories
Backlooms encourages the use of the Repository pattern.
from backlooms.db import BaseRepository
from sqlmodel import SQLModel, Field
class User(SQLModel, table=True):
id: int = Field(default=None, primary_key=True)
username: str
class UserRepository(BaseRepository[User, None]):
model = User
Authentication
The framework provides an IdentityManager to handle multiple authentication providers.
from backlooms.auth import IdentityManager
from backlooms.auth.providers.password import PasswordProvider
# Register providers in your container
identity_manager = IdentityManager(
auth_service=...,
user_service=...,
providers=[PasswordProvider()]
)
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 backlooms-0.1.0.tar.gz.
File metadata
- Download URL: backlooms-0.1.0.tar.gz
- Upload date:
- Size: 64.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b53fb4a182a0471cb366a3e49982f5934a776c54bef7d6485f6172f3bb00ccb6
|
|
| MD5 |
fa4abb71bff174b19e87da93c5b5e23c
|
|
| BLAKE2b-256 |
fe826372934fa8139123fd3a27df55c4cda371e9c4c59857f26d783096984e34
|
Provenance
The following attestation bundles were made for backlooms-0.1.0.tar.gz:
Publisher:
ci.yml on gleero/python-backlooms
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
backlooms-0.1.0.tar.gz -
Subject digest:
b53fb4a182a0471cb366a3e49982f5934a776c54bef7d6485f6172f3bb00ccb6 - Sigstore transparency entry: 991519532
- Sigstore integration time:
-
Permalink:
gleero/python-backlooms@f0da4a5067913f87701125fa96c0a62e0c2b3846 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gleero
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@f0da4a5067913f87701125fa96c0a62e0c2b3846 -
Trigger Event:
push
-
Statement type:
File details
Details for the file backlooms-0.1.0-py3-none-any.whl.
File metadata
- Download URL: backlooms-0.1.0-py3-none-any.whl
- Upload date:
- Size: 89.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
436bce4970be86eec21a156b068a9d2fa3fe31e9b28ba94176ac8fdeb1996784
|
|
| MD5 |
12b1833086479c41ab4b33d874c8adf8
|
|
| BLAKE2b-256 |
ec47aa8237308c659bb5d9f15fac009f4db48fc03ec79ef7d8ae8d887ccb66fd
|
Provenance
The following attestation bundles were made for backlooms-0.1.0-py3-none-any.whl:
Publisher:
ci.yml on gleero/python-backlooms
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
backlooms-0.1.0-py3-none-any.whl -
Subject digest:
436bce4970be86eec21a156b068a9d2fa3fe31e9b28ba94176ac8fdeb1996784 - Sigstore transparency entry: 991519540
- Sigstore integration time:
-
Permalink:
gleero/python-backlooms@f0da4a5067913f87701125fa96c0a62e0c2b3846 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/gleero
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@f0da4a5067913f87701125fa96c0a62e0c2b3846 -
Trigger Event:
push
-
Statement type: