LuSyringe is a documentation injection tool for your classes when using Fast API

Overview
drawing

LuSyringe

LuSyringe is a documentation injection tool for your classes when using Fast API

 

Benefits

The main benefit is being able to separate your business code (classes) from the logic of the documentation and pydantic validation. For example, a class that serves as a response for an endpoint may look like this without LuSyringe:

class HealthResponse(BaseModel):
  ping: str = Field(..., example="pong")
  version: str = Field(..., example="1.0.0")

And that's not bad at first look, but the response class is tightly coupled of the logic of the validation + documentation offered by Pydantic and FastAPI. When dealing with inheritance, you may run into cases that the search for where the documentation is being defined is a bit harsh.

Well, with LuSyringe that's how the HealthReponse class would look.

from lusyringe import lusyringe

class HealthResponse(metaclass=lusyringe(health_response_docs)):
  ping: str
  version: str

Nice, isn't it? 🤩 . But hey, what about inheritance, what if I'm inheriting these fields from a base class, or what if this base class is inheriting these fields?

Hey, calm down. I solved all these things for you here, no need to worries 😝 , ah! I do type checking for you too, (but I also have a non-strict mode if you are adventurous) .

How it works

The usage is pretty simple 🥰 . You can define your docs object in the following manner:

from lusyringe import Prescription

health_response_docs = [
    Prescription(
        field='ping',
        type=str,
        doc=Field(..., example='Pong')
    ),
    Prescription(
        field='version',
        type=str,
        doc=Field(..., example='0.0.1')
    ),
]

Then you can pass your docs object to lusyringe, like this:

from lusyringe import lusyringe

# import your file
from ... import health_response_docs

class HealthResponse(metaclass=lusyringe(health_response_docs)):
  ping: str
  version: str

Cool, huh? I can throw some errors if you forget to define your fields in the class, or in a base class being inherited from 👮

NotImplementedError: f"Documentation for {field} with type {type_} was found,"
                     f"but field was not implemented in {class_name}"

So be a good developer and do not forget to declare your things. But hey! Remember when I called you adventurous? Yeah, I have a little surprise for you:

class HealthResponse(metaclass=lusyringe(health_response_docs, strict=False)):
  pass

What!? What does the strict mean? Well, basically I'll allow your recklessness in don't defining the fields, so I'll do it for you 🙄 . But I'll get mad if you declare something with the wrong type! So be in line.

ValueError: f"Tried to apply type {applied_type} to already defined {field}"
            f"of type {existent_type}"

Installing

Initially this will only be available for the folks at Luizalabs 😇 . But if you are from here, you can just:

pip install lusyringe

If you have our pypi

Owner
Enzo Ferrari
Hey! I'm a Computer Engineering student @ SENAI CIMATEC. Also, I'm currently a Jr. Software Engineer @ Luizalabs
Enzo Ferrari
This project shows how to serve an ONNX-optimized image classification model as a web service with FastAPI, Docker, and Kubernetes.

Deploying ML models with FastAPI, Docker, and Kubernetes By: Sayak Paul and Chansung Park This project shows how to serve an ONNX-optimized image clas

Sayak Paul 104 Dec 23, 2022
Flask + marshmallow for beautiful APIs

Flask-Marshmallow Flask + marshmallow for beautiful APIs Flask-Marshmallow is a thin integration layer for Flask (a Python web framework) and marshmal

marshmallow-code 768 Dec 22, 2022
fastapi-mqtt is extension for MQTT protocol

fastapi-mqtt MQTT is a lightweight publish/subscribe messaging protocol designed for M2M (machine to machine) telemetry in low bandwidth environments.

Sabuhi 144 Dec 28, 2022
A web application using [FastAPI + streamlit + Docker] Neural Style Transfer (NST) refers to a class of software algorithms that manipulate digital images

Neural Style Transfer Web App - [FastAPI + streamlit + Docker] NST - application based on the Perceptual Losses for Real-Time Style Transfer and Super

Roman Spiridonov 3 Dec 05, 2022
Deploy/View images to database sqlite with fastapi

Deploy/View images to database sqlite with fastapi cd realistic Dependencies dat

Fredh Macau 1 Jan 04, 2022
Prometheus exporter for metrics from the MyAudi API

Prometheus Audi Exporter This Prometheus exporter exports metrics that it fetches from the MyAudi API. Usage Checkout submodules Install dependencies

Dieter Maes 7 Dec 19, 2022
flask extension for integration with the awesome pydantic package

flask extension for integration with the awesome pydantic package

249 Jan 06, 2023
FastAPI with async for generating QR codes and bolt11 for Lightning Addresses

sendsats An API for getting QR codes and Bolt11 Invoices from Lightning Addresses. Share anywhere; as a link for tips on a twitter profile, or via mes

Bitkarrot 12 Jan 07, 2023
Socket.IO integration for Flask applications.

Flask-SocketIO Socket.IO integration for Flask applications. Installation You can install this package as usual with pip: pip install flask-socketio

Miguel Grinberg 4.9k Jan 03, 2023
Ready-to-use and customizable users management for FastAPI

FastAPI Users Ready-to-use and customizable users management for FastAPI Documentation: https://fastapi-users.github.io/fastapi-users/ Source Code: ht

FastAPI Users 2.3k Dec 30, 2022
CURSO PROMETHEUS E GRAFANA: Observability in a real world

Curso de monitoração com o Prometheus Esse curso ensina como usar o Prometheus como uma ferramenta integrada de monitoração, entender seus conceitos,

Rafael Cirolini 318 Dec 23, 2022
Complete Fundamental to Expert Codes of FastAPI for creating API's

FastAPI FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3 based on standard Python type hints. The key featu

Pranav Anand 1 Nov 28, 2021
An alternative implement of Imjad API | Imjad API 的开源替代

HibiAPI An alternative implement of Imjad API. Imjad API 的开源替代. 前言 由于Imjad API这是什么?使用人数过多, 致使调用超出限制, 所以本人希望提供一个开源替代来供社区进行自由的部署和使用, 从而减轻一部分该API的使用压力 优势

Mix Technology 450 Dec 29, 2022
Toolkit for developing and maintaining ML models

modelkit Python framework for production ML systems. modelkit is a minimalist yet powerful MLOps library for Python, built for people who want to depl

140 Dec 27, 2022
Opentracing support for Starlette and FastApi

Starlette-OpenTracing OpenTracing support for Starlette and FastApi. Inspired by: Flask-OpenTracing OpenTracing implementations exist for major distri

Rene Dohmen 63 Dec 30, 2022
FastAPI-Amis-Admin is a high-performance, efficient and easily extensible FastAPI admin framework. Inspired by django-admin, and has as many powerful functions as django-admin.

简体中文 | English 项目介绍 FastAPI-Amis-Admin fastapi-amis-admin是一个拥有高性能,高效率,易拓展的fastapi管理后台框架. 启发自Django-Admin,并且拥有不逊色于Django-Admin的强大功能. 源码 · 在线演示 · 文档 · 文

AmisAdmin 318 Dec 31, 2022
A FastAPI Middleware of joerick/pyinstrument to check your service performance.

fastapi_profiler A FastAPI Middleware of joerick/pyinstrument to check your service performance. 📣 Info A FastAPI Middleware of pyinstrument to check

LeoSun 107 Jan 05, 2023
Asynchronous event dispatching/handling library for FastAPI and Starlette

fastapi-events An event dispatching/handling library for FastAPI, and Starlette. Features: straightforward API to emit events anywhere in your code ev

Melvin 238 Jan 07, 2023
Generate Class & Decorators for your FastAPI project ✨🚀

Classes and Decorators to use FastAPI with class based routing. In particular this allows you to construct an instance of a class and have methods of that instance be route handlers for FastAPI & Pyt

Yasser Tahiri 34 Oct 27, 2022
FastAPI + Postgres + Docker Compose + Heroku Deploy Template

FastAPI + Postgres + Docker Compose + Heroku Deploy ⚠️ For educational purpose only. Not ready for production use YET Features FastAPI with Postgres s

DP 12 Dec 27, 2022