FastAPI based Microservice Architecture Development Kit
Project description
MSA SDK - FastAPI based Microservice Architecture Development Kit
To build PoC's, MVP's, API's with CRUD and Dashboards fast and consistent.
Build on top of FastAPI, SQLModel, SQLAlchemy, Amis and many other bullet proofed libraries.
Documentation: http://msa.u2d.ai/
Features
- Build connected distributed applications faster: Ready for Dapr..
- Consistency: With sometimes 10s or 100s of Micro Services, the SDK helps to easy version control and provides a stable Dapr Basis.
- High performance: Based on FastAPI. Enjoy all the benefits.
- High efficiency: Perfect code type hints. Higher code reusability.
- Support asynchronous and synchronous hybrid writing:
ORM
is based onSQLModel
&Sqlalchemy
. Freely customize database type. Asynchronous mode. Strong scalability. - Front-end separation: The front-end is rendered by
Amis
, the back-end interface is automatically generated byMSA SDK - Admin
. The interface is reusable. - Strong scalability: The background page supports
Amis
pages and ordinaryhtml
pages. Easily customize the interface freely. - Automatic api documentation: Automatically generate Interface documentation by
FastAPI
. Easily debug and share interfaces.
Dependencies
- FastAPI
- SQLModel combined with SQLAlchemy and Pydantic, with all their features .
- Amis: Vue Frontend
Usage example is in the app module __init__.py
# -*- encoding: utf-8 -*-
"""
Copyright (c) 2022 - U2D.ai / S.Welcker
"""
__version__ = "0.0.1"
from typing import Optional
from sqlmodel import SQLModel
from msaSDK.admin.utils.fields import Field
from msaSDK.models.service import get_msa_app_settings
from msaSDK.service import MSAApp
from msaSDK.utils.scheduler import MSATimers, MSATimerEnum
# example async function to be executed by a timer
async def test_timer_min():
app.logger.info("MSA SDK Test Timer Async Every Minute")
# example sync/blocking function to be executed by a timer
def test_timer_five_sec():
app.logger.info("MSA SDK Test Timer Sync 5 Second")
# SQLModel class to be used for auto API CRUD and/or Admin Site Web UI
class TestArticle(SQLModel, table=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')
# SQLModel class to be used for auto API CRUD and/or Admin Site Web UI
class TestCategory(SQLModel, table=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')
# get the MSA app setting, clear the cache, set some settings
get_msa_app_settings.cache_clear()
settings = get_msa_app_settings()
settings.title = "SPK.ai - MSA/SDK MVP"
settings.version = "SPK.0.0.1"
settings.debug = True
# Create some timers with a MSATimer instance, define the interval and set the handler
my_timers: MSATimers = MSATimers()
my_timers.create_timer(MSATimerEnum.every_minute, test_timer_min)
my_timers.create_timer(MSATimerEnum.on_the_5_second, test_timer_five_sec)
# Create the main app instance, like the FastAPI but provide a Setting Definition Instance
# Optional the Classes of your SQLModels
# Define if the optional Admin Site gets mounted automatically, if False you need to Mount in your own Startup MSAUIEvent Handler
# Optional the MSATimers instance
app = MSAApp(settings=settings, timers=my_timers, auto_mount_site=True,
sql_models=[TestArticle, TestCategory],
contact={"name": "MSA SDK", "url": "http://u2d.ai", "email": "stefan@u2d.ai"},
license_info={"name": "MIT", "url": "https://opensource.org/licenses/MIT", })
# use the internal logger of app
app.logger.info("Initialized " + settings.title + " " + settings.version)
# Optional use startup event
# Mount the Admin Site here if enabled and the auto mount option was False
@app.on_event("startup")
async def startup():
app.logger.info("MSA SDK Own Startup MSAUIEvent")
# app.mount_site()
# Optional use shutdown event
@app.on_event("shutdown")
async def shutdown():
app.logger.info("MSA SDK Own Shutdown MSAUIEvent")
Typical Run Log
Interface Preview
Home Screen with System Info
- Open
http://127.0.0.1:8090/admin/
in your browser:
CRUD of SQLModels Screen
Login Screen
- Open
http://127.0.0.1:8090/admin/auth/form/login
in your browser:
OpenAPI Interactive Documentation (Swagger) Screen
- Open
http://127.0.0.1:8090/#/admin/docs
in your browser:
Profiler Screen
- Open
http://127.0.0.1:8090/#/admin/profiler
in your browser:
License Agreement
MSA SDK
Based onMIT
open source and free to use, it is free for commercial use, but please clearly show the copyright information about MSA SDK - Auth Admin in the display interface.
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 MSA SDK, so this should be fine.
We can now test and view our documentation using:
mkdocs serve
Build static Site:
mkdocs build
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
File details
Details for the file msaSDK-0.1.1.tar.gz
.
File metadata
- Download URL: msaSDK-0.1.1.tar.gz
- Upload date:
- Size: 120.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1c709dd55970ac1e3e1ee901d0efacd96f6575422aa6e695411897838ef3112 |
|
MD5 | cf7c774e23a4179c9a568bc2231244e4 |
|
BLAKE2b-256 | bba48e59be62bd024a93dd6056f45e91d0c8ee6e35e3449b036be3f6fb051968 |