Skip to main content

fastapi-sqlmodel-crud is a program which is based on fastapi+sqlmodel and used to quickly build the Create, Read, Update, Delete generic API interface.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_sqlmodel_crud-0.3.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

fastapi_sqlmodel_crud-0.3.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_sqlmodel_crud-0.3.0.tar.gz.

File metadata

  • Download URL: fastapi_sqlmodel_crud-0.3.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.4.1 CPython/3.11.0

File hashes

Hashes for fastapi_sqlmodel_crud-0.3.0.tar.gz
Algorithm Hash digest
SHA256 0938c0d4a31739e6bc7c3cfd9ff91cce29b0fa2a318a22d9e33ed5714382113b
MD5 5a0cdca17481e228c927f75176ddaac9
BLAKE2b-256 692bcac04f0c3352e169ca0df9703819d24dcb02bb4120ea19de4ce957face6e

See more details on using hashes here.

File details

Details for the file fastapi_sqlmodel_crud-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_sqlmodel_crud-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a34fa6bbdb6828f8979903dba5c08a7a7b11d3b07e8adc67be5317352f1eb0e
MD5 b3e67dfbe4586079b1c016ad5080bab3
BLAKE2b-256 3f1bd22ba1332a48630a8d5aaffc59a1d9a67f700893bce76aa812018d070c4a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page