Skip to content
/ msaCRUD Public

msaCRUD - SQLModel/SQLAlchemy/FastAPI - DB Object CRUD/API Automation Optimized for use with FastAPI/Pydantic. Generates CRUD Router based on SQLModel and SQLAlchemy.

License

Notifications You must be signed in to change notification settings

u2d-ai/msaCRUD

Repository files navigation

msaCRUD Logo


msaCRUD - SQLModel/SQLAlchemy/FastAPI - DB Object CRUD/API Automation
Optimized for use with FastAPI/Pydantic. Generates CRUD Router based on SQLModel and SQLAlchemy.
Package version Supported Python versions


Documentation: msaCRUD Documentation (https://msaCRUD.u2d.ai/)


Main Dependencies

  • fastapi[all]~=0.85.0 # FastAPI framework, high performance, easy to learn, fast to code, ready for production
  • starlette~=0.20.4 # Starlette is a lightweight ASGI framework/toolkit, which is ideal for building async web services in Python.
  • sqlmodel~=0.0.8 # SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.
  • sqlalchemy[asyncio]~=1.4.41 # Database Abstraction Library
  • sqlalchemy_database~=0.0.7 # SQLAlchemy-Database provides shortcut functions to common database operations for SQLAlchemy ORM

Usage

from typing import Optional, List
from sqlmodel import SQLModel, Field
from fastapi import FastAPI
from msaCRUD import MSASQLModelCrud


class TestArticle(SQLModel, table=True):
    __table_args__ = {'extend_existing': True}
    id: Optional[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')


class TestCategory(SQLModel, table=True):
    __table_args__ = {'extend_existing': True}
    id: Optional[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')


app = FastAPI()

# create your preferred DB Engine, create the schemas and then you can create the CRUD API models and add the router
# if you like 

new_crud: MSASQLModelCrud = MSASQLModelCrud(model=TestArticle, engine=YOUR_DB_ENGINE).register_crud()
app.include_router(new_crud.router)

new_crud_second: MSASQLModelCrud = MSASQLModelCrud(model=TestCategory, engine=YOUR_DB_ENGINE).register_crud()
app.include_router(new_crud_second.router)

if __name__ == '__main__':
    pass

License Agreement

  • msaCRUDBased on MIT open source and free to use, it is free for commercial use, but please show/list the copyright information about msaCRUD somewhere.

How to create the documentation

We use mkdocs and mkdocsstring. The code reference and nav entry get's created virtually by the triggered python script /docs/gen_ref_pages.py while mkdocs serve or build is executed.

Requirements Install for the PDF creation option:

PDF Export is using mainly weasyprint, if you get some errors here pls. check there documentation. Installation is part of the msaCRUD, so this should be fine.

We can now test and view our documentation using:

mkdocs serve

Build static Site:

mkdocs build

Build and Publish

Build:

python setup.py sdist

Publish to pypi:

twine upload dist/*

About

msaCRUD - SQLModel/SQLAlchemy/FastAPI - DB Object CRUD/API Automation Optimized for use with FastAPI/Pydantic. Generates CRUD Router based on SQLModel and SQLAlchemy.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published