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.7.tar.gz (8.7 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.7-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_repository-0.0.7.tar.gz
  • Upload date:
  • Size: 8.7 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.7.tar.gz
Algorithm Hash digest
SHA256 18b6b24bd49e6e0925fc592db76f26af675f0fa9016ebfec021979c63d99e45b
MD5 5cc610f67a3ec821e0b43f665b4fa73b
BLAKE2b-256 bffcb3c596466cc226dadd2a336e34586f5d29970a81a249579a8f6e3c6ca214

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_repository-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 17b64e6de714f065b0d375d77fc95401a0a77ff109363c81f07e572c8372331a
MD5 ed7a7d24fa0e40e783291e9a27c65f09
BLAKE2b-256 4d60850de206a54aabfaddb8d587fd7f4d20da382c96d6e3a1a9987c3dd58594

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