FastAPI DataTables
A simple integration of DataTables.js (or any standard DataTables-like frontend library) with FastAPI and SQLAlchemy.
This package makes it easy to implement:
- Server-side pagination
- Sorting
- Searching (deep search supported)
- Filtering
- Transforming query results
Perfect for handling large datasets efficiently while keeping your API clean and async-friendly.
🚀 Installation
pip install fp-datatables
📖 Quick Start Example
1. Setup database and models
from fastapi import FastAPI, Depends
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker, declarative_base
from sqlalchemy import Column, Integer, String, select
from datatables import DataTables, DataTablesRequest, DataTablesResponse
from pydantic import BaseModel
DATABASE_URL = "sqlite+aiosqlite:///./students.db"
engine = create_async_engine(DATABASE_URL, echo=False, future=True)
async_session = sessionmaker(bind=engine, class_=AsyncSession, expire_on_commit=False)
Base = declarative_base()
# Dependency for DB session
async def get_db() -> AsyncSession:
async with async_session() as session:
yield session
# Model
class Student(Base):
__tablename__ = "students"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, nullable=False)
age = Column(Integer, nullable=False)
email = Column(String, nullable=False, unique=True)
# Schema
class StudentSchema(BaseModel):
id: int
name: str
age: int
2. Setup FastAPI app
app = FastAPI()
@app.on_event("startup")
async def startup():
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
3. Insert test data
import random
from faker import Faker
faker = Faker()
@app.get("/insert_students")
async def insert_students():
async with async_session() as session:
students = [
Student(
name=faker.name(),
age=random.randint(18, 25),
email=faker.unique.email(),
)
for _ in range(1000)
]
session.add_all(students)
await session.commit()
return {"message": "1000 random students inserted successfully!"}
4. Datatables API endpoint
@app.post("/students", response_model=DataTablesResponse[list[StudentSchema]])
async def get_students(
request: DataTablesRequest, db: AsyncSession = Depends(get_db)
):
stmt = select(Student)
datatable = DataTables(db, Student, stmt)
return await datatable.process(request)
⚡ Frontend Usage
You can use DataTables.js (or any DataTables-compatible frontend) to consume this API. Example DataTables setup (jQuery):
$('#studentsTable').DataTable({
serverSide: true,
processing: true,
ajax: {
url: "/students",
type: "POST",
contentType: "application/json",
data: function (d) {
return JSON.stringify(d);
}
},
columns: [
{ data: "id" },
{ data: "name" },
{ data: "age" }
]
});
✨ Features
- Async-first (built on FastAPI + SQLAlchemy 2.0 async)
- Pagination, sorting, searching out of the box
- Works with any frontend datatable library (DataTables.js, PrimeVue DataTable, etc.)
- Supports deep field search (
relation.field) - Easy integration with Pydantic models
🛠️ Roadmap
- Support for joins and relationships
- More advanced filters
- Examples for Vue/React/Angular integration
📜 License
MIT License © 2025 Rohit Kumar
👉 Would you like me to also add an "Advanced Usage" section (with filtering, deep search student.classroom.name, and custom column transformations) so your README looks more complete for real-world use cases?
Metadata
Release files for fp-datatables 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fp_datatables-0.1.4.tar.gz | 8.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fp_datatables-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.2 kB
Release files / fp_datatables-0.1.4.tar.gz
| Download URL | fp_datatables-0.1.4.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
082a5475d36a5b5eebbe2d84515f72f454ca73bfa0d43fa109747b4745c89e6f
|
|
BLAKE2b-256 checksum How to use checksums |
1307c66428fadd2fd9db2ac670f7d8d7ea6ef09f2ecca6c8011ae100f7c01145
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Release files / fp_datatables-0.1.4-py3-none-any.whl
| Download URL | fp_datatables-0.1.4-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e4e923f6887c0a0c44ab07d513fc15d4bababf2ae004d23d595911e5719277ce
|
|
BLAKE2b-256 checksum How to use checksums |
dd066b911c11a88b9945d7ac34f6faf48950100028ce305940d99db9890cdaf8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Security for fp-datatables 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.