F
FasORM
v0.1.0

Laravel Eloquent-Style ORM for FastAPI

FasORM brings expressive Active Record models, intuitive relationship eager-loading, automatic JSON serialization, and an artisan-style CLI to modern Python async web applications.

Why FasORM?

Expressive Active Record

Define fields directly as class attributes and use clean Active Record syntax like User.create(...) or User.find(1).

SQLAlchemy 2.0 & Alembic Engine

Built directly on SQLAlchemy 2.0 async engine and Alembic, providing enterprise reliability and full migration support.

Eager Loading & with_count

Eliminate N+1 query problems with intuitive eager loading (with_("posts")) and relation count aggregations (with_count("posts")).

Artisan-Style CLI

Scaffold models, run migrations, generate seeders, and inspect migration status with the powerful fasorm CLI.

Quickstart in 5 Minutes

Get up and running with FasORM in just a few simple steps:

1. Installation

Bash
pip install fasorm

2. Initialize your project

Bash
fasorm init

3. Define a Model & Migration

app/models/user.py
from fasorm import Model, String, Boolean, HasMany

class User(Model):
    name = String()
    email = String(unique=True)
    is_active = Boolean(default=True)
    posts = HasMany("Post")

4. Perform Queries in FastAPI

main.py
from fastapi import FastAPI
from fasorm import init_db
from app.models.user import User

app = FastAPI()

# Initialize DB connection on startup
init_db("sqlite+aiosqlite:///app.db")

@app.get("/users")
async def get_users():
    # Eager-load posts and count related records
    users = await User.with_count("posts").where(is_active=True).to_dict()
    return {"data": users}

Explore Documentation