Skip to main content

FastAPI based Microservice Architecture Development Kit

Project description

MSA SDK image


msaSDK - 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.
Package version Supported Python versions


Documentation: MSA SDK 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.
  • Integrated Scheduler: Define Scheduler Tasks with natural language timings and dependencies.
  • Integrated Dashboard UI: Admin and Optional Auth enabled Dashboard with CRUD Forms.
  • Integrated CRUD: Generates CRUD Router and Admin Dashboard Forms based on SQLModel and SQLAlchemy.
  • Integrated Abstract Filesystem: Agnostic Abstract Filesystem API which allows to use S3, GCS, Azure Datalake, your local FS, Youtube etc.
  • Integrated justpy WEB UI: Integrated justpy UI Web Framework to MSAAPI, which allows simple adding of routes to justpy webpages functions.
  • Integrated Dict with Storage Backend: Use Dict's with backend storage like redis.
  • Integrated Signals: Use and handle Signals and Tasks.
  • Integrated Feature Management: Feature switch management with conditions.

Main Dependencies

  • FastAPI
  • SQLModel combined with SQLAlchemy and Pydantic, with all their features .
  • msaUtils: General utils for Microservices based on FastAPI like Profiler, Scheduler, Sysinfo, Healtcheck, Error Handling etc.
  • msaJustPyUI: FastAPI adapted JustPy version for Integration of justpy UI Web Framework to msaAppService, which allows simple adding of routes to justpy webpages functions.
  • msaCRUD: SQLModel/SQLAlchemy/FastAPI - DB Object CRUD/API Automation
  • msaFeature: Feature switch management with conditions
  • msaServer: Helper & Wrapper around Uvicorn/Gunicorn for FastAPI based apps
  • msaSignal: Signals/Events for Starlette/FastAPI.
  • msaDocModels: # MSA Document Pydantic Models and Schemas, used to store Parser, NLP, NLU and AI results for processed documents
  • msaStorageDict: Dict with a Storage Backend like redis or Zookeeper

Usage example is in the app module __init__.py

# -*- encoding: utf-8 -*-
"""
Copyright (c) 2022 - U2D.ai / S.Welcker
"""
from typing import Optional, List

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


async def test_timer_min():
    app.logger.info("msaSDK Test Timer Async Every Minute")


def test_timer_five_sec():
    app.logger.info("msaSDK Test Timer Sync 5 Second")


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')


get_msa_app_settings.cache_clear()
settings = get_msa_app_settings()
settings.title = "u2d.ai - MSA/SDK MVP"
settings.version = "0.0.1"
settings.debug = True

app = MSAApp(settings=settings, auto_mount_site=True,
             sql_models=[TestArticle, TestCategory],
             contact={"name": "msaSDK", "url": "http://u2d.ai", "email": "stefan@u2d.ai"},
             license_info={"name": "MIT", "url": "https://opensource.org/licenses/MIT", })

app.scheduler.task("every 1 min", func=test_timer_min )
app.scheduler.task("every 5 sec", func=test_timer_five_sec )

app.logger.info("Initialized " + settings.title + " " + settings.version)


@app.on_event("startup")
async def startup():
    app.logger.info("msaSDK Own Startup MSAUIEvent")
    #app.mount_site()


@app.on_event("shutdown")
async def shutdown():
    app.logger.info("msaSDK Own Shutdown MSAUIEvent")


if __name__ == '__main__':
    pass

Typical Run Log

Typical Log Run

Interface Preview

Home Screen with System Info

  • Open http://127.0.0.1:8090/admin/ in your browser:

Home

CRUD of SQLModels Screen

CRUD

Login Screen

  • Open http://127.0.0.1:8090/admin/auth/form/login in your browser:

Login

OpenAPI Interactive Documentation (Swagger) Screen

  • Open http://127.0.0.1:8090/#/admin/docs in your browser:

OpenAPI

Profiler Screen

  • Open http://127.0.0.1:8090/#/admin/profiler in your browser:

Profiler

License Agreement

  • msaSDKBased on MIT open source and free to use, it is free for commercial use, but please show/list the copyright information about msaSDK 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 msaSDK, 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/*

Download files

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

Source Distribution

msaSDK-0.2.5.tar.gz (83.4 kB view details)

Uploaded Source

File details

Details for the file msaSDK-0.2.5.tar.gz.

File metadata

  • Download URL: msaSDK-0.2.5.tar.gz
  • Upload date:
  • Size: 83.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for msaSDK-0.2.5.tar.gz
Algorithm Hash digest
SHA256 5bcff5b5891f52d7b3a5a08be95b894661a593473bb331115efbe48d2a7de9a0
MD5 b853c4c8833941881d4753ad2c20d30e
BLAKE2b-256 d4f2b253b0e1d42f54f1782ad56a0761913ea2e792291dc38f2dc7dca700f53f

See more details on using hashes here.

Provenance

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