This package contains the shared business logic, interfaces, DTOs, and exceptions for the [Your Project Name] ecosystem. It is designed to be imported by all other applications (web APIs, background workers, etc.) to prevent code duplication and enforce a clean architecture.
This is a private package and should be installed directly from its Git repository via SSH.
# Install the base package
pip install "git+ssh://git@github.com:munlicode/core_sdk.git@master"This SDK uses "extras" to keep the base package light. You can install optional bundles as needed by your application.
# To install dependencies for auth (bcrypt, pyjwt)
pip install "core_sdk[auth] @ git+ssh://..."
# To install dependencies for OAuth providers
pip install "core_sdk[providers] @ git+ssh://..."
# To install all possible dependencies
pip install "core_sdk[all] @ git+ssh://..."This package follows the Dependency Inversion Principle. It provides interfaces (the "plugs") and services (the "logic"), but it is the job of the application to provide the concrete implementations (the "adapters").
The application is responsible for "wiring" the dependencies.
# In your application's main.py (the "wiring")
from fastapi import FastAPI, Depends
from core_sdk.services import AuthService
from core_sdk.interfaces import IUserGateway, IOneWayHasher, IUnitOfWork
# --- 1. Import your App's concrete adapters ---
from my_app.adapters import (
DatabaseUserGateway,
BcryptHasher,
SqlAlchemyUnitOfWork
)
# --- 2. Create the "Provider" functions ---
def get_uow(...) -> IUnitOfWork:
return SqlAlchemyUnitOfWork(...)
def get_hasher() -> IOneWayHasher:
return BcryptHasher()
def get_user_gateway(...) -> IUserGateway:
return DatabaseUserGateway(...)
def get_auth_service(
gateway: IUserGateway = Depends(get_user_gateway),
hasher: IPasswordHasher = Depends(get_hasher),
uow: IUnitOfWork = Depends(get_uow)
) -> AuthService:
# The DI container builds the service with its dependencies
return AuthService(gateway=gateway, hasher=hasher, uow=uow)
# --- 3. Use it in your API endpoint ---
app = FastAPI()
@app.post("/register")
async def register_user(
auth_service: AuthService = Depends(get_auth_service)
):
# The endpoint is clean and only knows about the service
await auth_service.create_user(...)-
Clone the repo:
git clone git@github.com:munlicode/core_sdk.git cd core_sdk -
Install dependencies:
- This will install uv if you don't have it and set up the virtual environment.
uv sync
-
Run tests:
uv run pytest