Skip to content

munlicode/core_sdk

Repository files navigation

Core SDK

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.


🚀 Installation

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"

Installing Optional Dependencies

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://..."

🏗️ Core Architectural Pattern

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").

Example: Wiring up the AuthService in FastAPI

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(...)

🛠️ For Developers (Contributing)

  1. Clone the repo:

    git clone git@github.com:munlicode/core_sdk.git
    cd core_sdk
  2. Install dependencies:

    • This will install uv if you don't have it and set up the virtual environment.
    uv sync
  3. Run tests:

    uv run pytest

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages