FraiseQL is deliberately opinionated about FastAPI. Async-first, type-safe, LLM-optimized development.
FraiseQL isn't just compatible with FastAPIβit's built for FastAPI. This opinionated choice aligns performance, architecture, and developer experience around a common philosophy: speed, type safety, and clarity.
| Benefit | Why It Matters | Result |
|---|---|---|
| Async-First | Both FraiseQL and FastAPI built on async/await | β Fully non-blocking stack |
| Minimal Overhead | FastAPI adds <0.5ms, FraiseQL adds <0.1ms | β Sub-50ms responses |
| Type Safety | Pydantic + Python 3.13+ type hints | β Catch errors at dev time |
| CQRS Architecture | Database-layer separation (Views/Functions) | β Queries β Views, Mutations β Functions |
| LLM-Optimized | Explicit types, decorators, DI patterns | β AI-assisted development |
import fraiseql
from uuid import UUID
@fraiseql.type
class User:
"""User account.
Fields:
id: Unique identifier
username: Display name
email: Contact email
"""
id: UUID
username: str
email: str
@fraiseql.query
async def users(info) -> list[User]:
"""Get all users."""
db = info.context["db"]
return await db.find("users")
@fraiseql.mutation
async def create_user(
info,
username: str,
email: str
) -> User:
"""Create new user."""
db = info.context["db"]
user_id = await db.insert(
"users",
{"username": username, "email": email}
)
return await db.find_one(
"users", id=user_id
)
from fraiseql.fastapi import (
create_fraiseql_app
)
# Create complete app
app = create_fraiseql_app(
database_url="postgresql://...",
types=[User],
mutations=[create_user],
queries=[users],
title="My API",
production=False
)
# FastAPI instance ready
# /graphql endpoint configured
# Start server
import uvicorn
uvicorn.run(
app,
host="0.0.0.0",
port=8000
)
# Query (POST /graphql)
query {
users {
id
username
email
}
}
# Mutation (POST /graphql)
mutation {
createUser(
username: "alice"
email: "alice@example.com"
) {
id
username
}
}
Async/await throughout. FastAPI + FraiseQL + asyncpg = fully non-blocking, sub-50ms responses.
GraphQL queries execute PostgreSQL Views, mutations execute Functions. True separation of concerns at the database level.
Explicit type hints, decorator patterns, dependency injection. AI tools understand and generate code confidently.
FastAPI's DI system integrates seamlessly. Clean, testable, maintainable code.
OpenAPI schema + GraphQL schema. Your API is self-documenting out of the box.
Pydantic models + Python 3.13+ type hints. Catch errors before deployment.
FraiseQL + FastAPI is designed for the AI-assisted development era. Here's why Claude, Copilot, and other LLMs excel with this stack:
LLMs understand intent from function signatures
@fraiseql.query
async def user(
info, id: UUID
) -> User | None:
"""Get user by ID.
Returns:
User if found, else None
"""
db = info.context["db"]
return await db.find_one(
"users", id=id
)
Self-documenting code with clear, repeatable patterns
@fraiseql.type
class Post:
"""Blog post.
Fields:
id: Unique identifier
title: Post headline
author_id: Ref to User.id
"""
id: UUID
title: str
author_id: UUID
Clear contracts with documented fields
@fraiseql.input
class CreatePostInput:
"""Input for new post.
Fields:
title: Headline
content: Post body
tags: Optional tags
"""
title: str
content: str
tags: list[str] | None = None
LLMs understand success/error shapes from type signatures
@fraiseql.mutation
async def create_post(
info,
input: CreatePostInput
) -> CreatePostSuccess | CreatePostError:
"""Create new post.
Returns:
Success with post or Error
"""
db = info.context["db"]
# Validation logic...
return CreatePostSuccess(
post=new_post
)
β AI tools generate correct, maintainable code
Every layer of the stack is opinionated for the same goals:
Bottom line: FraiseQL + FastAPI is the "golden path"βtested, documented, optimized.
| Approach | Flexibility | Performance | Developer Experience |
|---|---|---|---|
| Framework-Agnostic | β High flexibility | β Lowest common denominator | β Generic patterns |
| Multi-Framework Support | β Some flexibility | β Compromises for compatibility | β Inconsistent DX |
| FraiseQL (FastAPI-Native) | β Opinionated choice | β Optimized async stack | β Best-in-class DX |
FraiseQL's philosophy: Being opinionated allows optimization. FastAPI's async-first, type-safe architecture aligns perfectly with FraiseQL's performance goals and PostgreSQL-first approach.
FastAPI-native integration is available in FraiseQL v0.9.5+