Project Introduction
fastapi-sqlmodel-crud is a project based on FastAPI+SQLModel, which is used to quickly build Create, Read, Update, Delete common API interfaces.
Install
pip install fastapi-sqlmodel-crud
Simple example
main.py:
from typing import Optional
from fastapi import FastAPI
from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine
from sqlmodel import SQLModel, Field
from fastapi_amis_admin.crud import SQLModelCrud
# 1. Create SQLModel model
class Article(SQLModel, table=True):
id: int = Field(default=None, primary_key=True, nullable=False)
title: str = Field(title='ArticleTitle', max_length=200)
description: Optional[str] = Field(default='', title='ArticleDescription', max_length=400)
status: bool = Field(None, title='status')
content: str = Field(title='ArticleContent')
# 2. Create AsyncEngine
database_url = 'sqlite+aiosqlite:///amisadmin.db'
engine: AsyncEngine = create_async_engine(database_url, future=True)
# 3. Register crud route
article_crud = SQLModelCrud(model=Article, engine=engine).register_crud()
app = FastAPI(debug=True)
# 4. Include the router
app.include_router(article_crud.router)
# 5. Create model database table (first run)
@app.on_event("startup")
async def startup():
async with engine.begin() as conn:
await conn.run_sync(SQLModel.metadata.create_all)
Development documentation
Dependent projects
Licence
The project follows the Apache2.0 license agreement.
Metadata
Release files for fastapi-sqlmodel-crud 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastapi_sqlmodel_crud-0.3.0.tar.gz | 13.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_sqlmodel_crud-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.7 kB
Release files / fastapi_sqlmodel_crud-0.3.0.tar.gz
| Download URL | fastapi_sqlmodel_crud-0.3.0.tar.gz |
|---|---|
| Size | 13.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0938c0d4a31739e6bc7c3cfd9ff91cce29b0fa2a318a22d9e33ed5714382113b
|
|
BLAKE2b-256 checksum How to use checksums |
692bcac04f0c3352e169ca0df9703819d24dcb02bb4120ea19de4ce957face6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.4.1 CPython/3.11.0
|
Release files / fastapi_sqlmodel_crud-0.3.0-py3-none-any.whl
| Download URL | fastapi_sqlmodel_crud-0.3.0-py3-none-any.whl |
|---|---|
| Size | 15.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a34fa6bbdb6828f8979903dba5c08a7a7b11d3b07e8adc67be5317352f1eb0e
|
|
BLAKE2b-256 checksum How to use checksums |
3f1bd22ba1332a48630a8d5aaffc59a1d9a67f700893bce76aa812018d070c4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.4.1 CPython/3.11.0
|