Skip to main content

Shared base repository and service utilities for SQLAlchemy-backed FastAPI apps.

Project description

Repository Core

A powerful and flexible base repository and service utilities package for SQLAlchemy-backed FastAPI applications.

Overview

Repository Core provides a set of base classes and utilities to help you implement clean and maintainable repository and service patterns in your FastAPI applications. It's designed to work seamlessly with SQLAlchemy and follows best practices for database operations and business logic separation.

Features

  • Base repository classes for common CRUD operations
  • Service layer abstractions for business logic
  • SQLAlchemy model utilities
  • Exceptions
  • Schema validation
  • Utility functions for common operations

Installation

pip install repository-core

Requirements

  • Python >= 3.13
  • FastAPI >= 0.115.2
  • SQLAlchemy >= 2.0.40

Usage Guide

1. Setting Up Base Models

from repository_core.models import BaseModel

class User(BaseModel):
    __tablename__ = "users"
    
    email = Column(String, unique=True, nullable=False)
    name = Column(String)

2. Creating a Repository

from repository_core.repository import BaseRepository
from repository_core.models import BaseModel

class UserRepository(BaseRepository):
    def __init__(self, session):
        super().__init__(session, User) #Access all the methods of base-repository
    
    # Add custom repository methods here
    async def get_by_email(self, email: str) -> Optional[User]:
        return await self.get_one(User.email == email)

3. Implementing a Service

from repository_core.services import BaseService
from repository_core.schemas import BaseSchema

class UserService(BaseService):
    def __init__(self, repository: UserRepository):
        super().__init__(repository)
    
    # Add custom service methods here
    async def create_user(self, data: UserCreate) -> User:
        return await self.create(data)

Project Structure

repository_core/
├── models/         # Base model classes
├── repository/     # Base repository implementations
├── services/       # Base service implementations
├── schemas/        # Pydantic schemas
├── exceptions/     # Custom exceptions
└── utils/          # Utility functions

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

abs_repository_core-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

abs_repository_core-0.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file abs_repository_core-0.1.0.tar.gz.

File metadata

  • Download URL: abs_repository_core-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.13.3 Darwin/23.6.0

File hashes

Hashes for abs_repository_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ee0cb57a7f6838638209a06490248dc1c2ab810be025834976b8f0066c1827b9
MD5 2c56bc29fb2c4c4978e29b6660bcd475
BLAKE2b-256 c0bf3a033f96af2454c51b225a07d8b4b0b0361d04f84ff0f59cdeb050f02154

See more details on using hashes here.

File details

Details for the file abs_repository_core-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for abs_repository_core-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ffddb1c094a3bb2470ff01be561b15f53d2b5ed389ff4ac50c96634ea7864397
MD5 0098aa302a55759f8f688f606b82a579
BLAKE2b-256 c52f7d6d7a68ba1398b2ec86b41dd0425f22be9d8b79f6ec6f66184ec5a990a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page