Skip to main content

A base repository for FastAPI projects, inspired by Ruby on Rails' Active Record and Ransack.

Project description

FastAPI Repository

A base repository for FastAPI projects, inspired by Ruby on Rails' Active Record and Ransack. It provides a simple, intuitive, and asynchronous interface for data access using SQLAlchemy.

Key Features

  • Async-first: Designed for modern asynchronous Python.
  • Simple CRUD: find, create, update, destroy methods out of the box.
  • Powerful Filtering: Use Ransack-style operators (__icontains, __gt, etc.) for complex queries.
  • Relationship Loading: Control eager (joinedload) and lazy (lazyload) loading.
  • Default Scoping: Apply default conditions to all queries.

Installation

pip install fastapi-repository

Quick Start

  1. Define a repository for your SQLAlchemy model:

    # repositories.py
    from fastapi_repository import BaseRepository
    from sqlalchemy.ext.asyncio import AsyncSession
    from .models import User  # Your SQLAlchemy model
    
    class UserRepository(BaseRepository):
        def __init__(self, session: AsyncSession):
            super().__init__(session, model=User)
    
  2. Use it in your FastAPI application:

    # main.py
    from fastapi import FastAPI, Depends
    from sqlalchemy.ext.asyncio import AsyncSession
    from .database import get_session
    from .repositories import UserRepository
    
    app = FastAPI()
    
    @app.get("/users/{user_id}")
    async def get_user(user_id: int, session: AsyncSession = Depends(get_session)):
        repo = UserRepository(session)
        user = await repo.find(user_id)
        return user
    

Documentation

For a complete guide, including a full tutorial, API reference, and advanced usage, please see the Full Documentation.

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

fastapi_repository-0.0.8.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

fastapi_repository-0.0.8-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_repository-0.0.8.tar.gz.

File metadata

  • Download URL: fastapi_repository-0.0.8.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for fastapi_repository-0.0.8.tar.gz
Algorithm Hash digest
SHA256 3ea80408591913b01555ed8c019e3d64b74f4d710cf7e7626762fd468b4de52e
MD5 88ac0bccfd41e01b4ba196df771fada7
BLAKE2b-256 ec43ef618252e283e5a57c3a39932cd6a3f1baed5e46d54d0181d34d893bb6e3

See more details on using hashes here.

File details

Details for the file fastapi_repository-0.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_repository-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 524fb16bebe40ee13d5053c903efbc293d7eb2546906d6daf991bc624bd98bf9
MD5 30a8c418c621ed5cb4299cda0847f226
BLAKE2b-256 aab7ccc0d86ae46c08f3cbad402231fbc6ebb96ed4dfc9ce7518d305cb3a7ac4

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