A FastAPI admin SDK for building admin interfaces with resource management, permissions, and CRUD operations
Project description
FastAPI Admin SDK
A FastAPI admin SDK for building admin interfaces with resource management, permissions, and CRUD operations.
Installation
Install the package using pip:
pip install fastapi-admin-sdk
Or using uv:
uv add fastapi-admin-sdk
Quick Start
1. Configure Settings
Set up your environment variables:
export ADMIN_DB_URL="postgresql+asyncpg://user:password@localhost/dbname"
export ORM_TYPE="sqlalchemy"
Or create a .env file:
ADMIN_DB_URL=postgresql+asyncpg://user:password@localhost/dbname
ORM_TYPE=sqlalchemy
2. Define Your Model
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
class Base(DeclarativeBase):
pass
class User(Base):
__tablename__ = "users"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
email: Mapped[str]
3. Create a Resource
from fastapi_admin_sdk import Resource, SQLAlchemyResource
from fastapi_admin_sdk.db import get_session_factory
session_factory = get_session_factory()
user_resource = SQLAlchemyResource(
model=User,
session_factory=session_factory,
lookup_field="id"
)
4. Create an Admin Class
from fastapi import Request
from pydantic import BaseModel
from fastapi_admin_sdk import BaseAdmin, register
class UserCreateSchema(BaseModel):
name: str
email: str
class UserUpdateSchema(BaseModel):
name: str | None = None
email: str | None = None
@register(user_resource)
class UserAdmin(BaseAdmin):
list_display = ["id", "name", "email"]
list_filter = ["name"]
search_fields = ["name", "email"]
ordering = ["id"]
create_form_schema = UserCreateSchema
update_form_schema = UserUpdateSchema
lookup_field = "id"
async def has_create_permission(self, request: Request):
# Add your permission logic here
return True
5. Add Routes to Your FastAPI App
from fastapi import FastAPI
from fastapi_admin_sdk import router
app = FastAPI()
app.include_router(router, prefix="/admin")
Features
- Resource Management: Define resources with CRUD operations
- Permission System: Customizable permission checks for create, read, update, delete, and list operations
- Filtering & Pagination: Built-in support for filtering and pagination
- SQLAlchemy Support: First-class support for SQLAlchemy async models
- Type Safety: Built with Pydantic for data validation
API Endpoints
Once you've registered your admin classes and included the router, the following endpoints will be available:
POST /admin/{resource_name}/create- Create a new resource instanceGET /admin/{resource_name}/list- List resource instances with filtering and paginationGET /admin/{resource_name}/{lookup}/retrieve- Retrieve a specific resource instancePATCH /admin/{resource_name}/{lookup}/update- Update an existing resource instanceDELETE /admin/{resource_name}/{lookup}/delete- Delete a resource instance
Development
Running Tests
# Install dev dependencies
uv sync --all-groups --all-extras
# Run tests
uv run pytest
# Run tests with coverage
uv run pytest --cov=fastapi_admin_sdk --cov-report=term
Building the Package
python -m build
Publishing to PyPI
The package is automatically published to PyPI when a git tag is pushed. Make sure to set up the PYPI_API_TOKEN secret in your GitHub repository.
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_admin_sdk-0.1.1.tar.gz.
File metadata
- Download URL: fastapi_admin_sdk-0.1.1.tar.gz
- Upload date:
- Size: 114.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
630d7d39ff7f66e7551474f628e8eb71caabb9fc0d8018a4c59eb2db321d3c02
|
|
| MD5 |
3e9a92e7ffc813833bef9b16257b819a
|
|
| BLAKE2b-256 |
9afd09c0dda177a6085a735fabe6a068f22ec620aa24c84c1bec0c1102814bf7
|
File details
Details for the file fastapi_admin_sdk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: fastapi_admin_sdk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c606db3b7cf85f1ca7097035fa89d3bcc89718c3790d46e4339608816d64b67
|
|
| MD5 |
2b532eaf1fe19470c791cb127e628955
|
|
| BLAKE2b-256 |
628ec736b20cc15df481448c84819f7260f6242e7f83ac6a19215926bacd1863
|