🪛 A simple pydantic to Form FastAPI model converter.

Overview

pyfa-converter

Makes it pretty easy to create a model based on Field [pydantic] and use the model for www-form-data.

How to simplify your life?

image


What do I need to do with the model?

  • We put the decorator @PydanticConverter.body for the model and enjoy.
  • data: YourPydanticModel = FormBody()

If you want to accept a file on an endpoint, then the content-type for that endpoint changes from application/json to www-form-data.

FastAPI does not know how to override the pydantic schema so that parameters are passed as form. Even if you do

foo: CustomPydanticModel = Depends() all model attributes will be passed as query, but we want them to become body, that's what this library exists for.

Usually you use something along the lines of:

image

But, if we accept a lot of fields, then the function becomes very large (the number of attributes for the endpoint increases and it does not look very good).

Thanks to this library, it is possible to force the conversion of Field fields into fields of FastAPI Form with full preservation of all attributes (alias, gt, te, description, title, example and more...)

You might also like...

Generator of python HTTP-clients from OpenAPI specification based on httpx and pydantic

Generator of python HTTP-clients from OpenAPI specification based on httpx and pydantic

Pythogen Generator of python HTTP-clients from OpenApi specification based on httpx and pydantic. Features Discriminator Sync and async clients Tracin

Sep 9, 2022

Asynchronous ORM that uses pydantic models to represent database tables ✨

Asynchronous ORM that uses pydantic models to represent database tables ✨

Asynchronous ORM that uses pydantic models to represent database tables ✨ Ormdantic is a library for interacting with Asynchronous SQL databases from

Sep 26, 2022

A Simple Ecoflow JSON REST API - prometheus metrics converter

A Simple Ecoflow JSON REST API -> prometheus metrics converter

ecoflow-prometheus-exporter A Simple Ecoflow JSON REST API - prometheus metrics converter Disclaimers Disclaimer: This project is in no way connected

Sep 21, 2022

A Simple Python Text To Speech Converter Which Supports Voice Types .

from github import readme def project(self): self.name = 'Text To Speech' self.description = 'A Simple Python Text To Speech Converator With

Aug 15, 2022

This is a very simple temperature converter tool.

Temperature Converter Most countries around the world use the Celcius scale to indicate temperatures, but the United Stated still use the Fahrenheit s

Aug 22, 2022

This repository presents a full process of training a pedestrian tracking model using `deep-person-reid` repository. Further, a complete web-application service based on FastAPI is provided that extracts features using YoloV5 and trained model.

This repository presents a full process of training a pedestrian tracking model using `deep-person-reid` repository. Further, a complete web-application service based on FastAPI is provided that extracts features using YoloV5 and trained model.

Person Tracking DeepSORT Yolov5 Person tracking/re-identification is one of the major deep learning problems that is very popular in surveillance appl

Jun 30, 2022

About Python scripts form performing stereo depth estimation using the ACVNet model in ONNX.

About Python scripts form performing stereo depth estimation using the ACVNet model in ONNX.

ONNX-ACVNet-Stereo-Depth-Estimation About Python scripts form performing stereo depth estimation using the ACVNet model in ONNX. Requirements Check th

Jul 20, 2022

∞-AE model's implementation in JAX. Kernel-only method outperforms complicated SoTA models with a closed-form solution and a single hyper-parameter.

Infinite Recommendation Networks (∞-AE) This repository contains the implementation of ∞-AE from the paper "Infinite Recommendation Networks: A Data-C

Sep 25, 2022

This text identification model takes three different texts (.txt form) and shows the similarities two the comparisons by word count, length, stems, sentence lengths, and punctuation.

This text identification model takes three different texts (.txt form) (a sample text and two comparisons) and shows the similarities two the comparisons by word count, length, stems, sentence lengths, and punctuation. Other contributions and credit on this project: Anya Raghuvanshi and Haven Qin

Aug 4, 2022
Comments
  • Error: TypeError: unsupported operand type(s) for |: 'ModelMetaclass' and 'type'

    Error: TypeError: unsupported operand type(s) for |: 'ModelMetaclass' and 'type'

    Using the

    from pyfa_converter import FormDepends
    

    and get the error

    TypeError: unsupported operand type(s) for |: 'ModelMetaclass' and 'type'
    

    python: 3.9

    opened by Terryhung 4
  • Add License

    Add License

    Hi! The code in this repo seems super useful for us working with pydantic + fastapi, but we can't use it without a LICENSE. Could you add LICENSE file to the repo? MIT is a permissive one if you don't have an opinion otherwise

    opened by dzcode 3
  • Big update 1.0.0.0!

    Big update 1.0.0.0!

    • The decorator above the model is no longer required and will be removed in the next version!
    • New syntax:
    data: MyCustomModel = PyFaDepends(MyCustomModel, _type=Header)
    data: MyCustomModel = PyFaDepends(MyCustomModel, _type=Form)
    
    data: MyCustomModel = FormDepends(MyCustomModel)
    data: MyCustomModel = QueryDepends(MyCustomModel)
    
    • Added support for parameters specific only to FastAPI types in Pydantic Field. Example - Field(None, convert_underscores=True)
    opened by dotX12 0
Releases(1.0.3.0)
Owner
null
msaServer - Helper & Wrapper around Uvicorn/Gunicorn for FastAPI based apps Optimized for use with FastAPI/Pydantic.

msaServer - Helper & Wrapper around Uvicorn/Gunicorn for FastAPI based apps Optimized for use with FastAPI/Pydantic. Documentation: msaServer Document

Stefan Welcker 1 Sep 28, 2022
FastAPI-User-Auth is a simple and powerful FastAPI user RBAC authentication and authorization library. Based on FastAPI-Amis-Admin and provides a freely extensible visual management interface.

项目介绍 FastAPI-User-Auth FastAPI-User-Auth是一个简单而强大的FastAPI用户RBAC认证与授权库. 基于FastAPI-Amis-Admin并提供可自由拓展的可视化管理界面. 源码 · 在线演示 · 文档 · 文档打不开? FastAPI-User-Auth是

AmisAdmin 138 Sep 22, 2022
A Django based contact form, which has a simple form which is connected to a SQL-Lite database and has features to be added .

This is a Django based contact form, which has a simple form which is connected to a SQL-Lite database and has features to be added . It has an admin Interface to view the entires in the DB. Now, we can update the message board through the admin panel. NOTE: Not a production grade!

Nalin Rajendran 1 Sep 9, 2022
msaFilesystem - Agnostic Abstract Filesystem API which allows to use S3, GCS, Azure Datalake, your local FS, Youtube etc Optimized for use with FastAPI/Pydantic.

msaFilesystem - Agnostic Abstract Filesystem API which allows to use S3, GCS, Azure Datalake, your local FS, Youtube etc Optimized for use with FastAP

Stefan Welcker 1 Sep 28, 2022
FastAPI-Scheduler is a simple scheduled task management FastAPI extension based on APScheduler.

FastAPI-Scheduler 项目介绍 FastAPI-Scheduler是一个基于APScheduler的简单定时任务管理FastAPI拓展库. 安装 pip install fastapi-scheduler 简单示例 main.py: from fastapi import FastAP

AmisAdmin 5 Jun 1, 2022
ODM (Object Document Mapper) for Elasticsearch based on Elasticsearch_dsl and Pydantic

es_odm ODM (Object Document Mapper) for Elasticsearch based on Elasticsearch_dsl and Pydantic. It's also a bridge connecting Mysql and Elasticsearch w

null 37 Sep 1, 2022
An addon package to transform/map dictionaries to Pydantic Models.

Pydantic Model Parser A simple package to transform/map dictionaries, before parsing it into Pydantic. Requirements The models/entities should conform

Goh Chun Teck 1 May 29, 2022
Use pydantic schemas to define your query parameters, with extra sugar in them ✨

FastAPI Query Parameters Empower your query parameters setup on FastAPI through Pydantic Installation poetry add fastapi-qp Usage You can just define

Clicampo 36 Sep 9, 2022
Pydastic is an elasticsearch python ORM based on Pydantic

Pydastic is an elasticsearch python ORM based on Pydantic. ?? Installation Pip: pip install pydastic Poetry: poetry add pydastic ?? Core Feat

Rami Awar 82 Sep 25, 2022
A project template where PyTorch Lightning, Pydantic, and more! being used for training MNIST as an example.

Deep Learning Project Template This template of a deep learning project where we are using the following PyTorch Lightning, Pydantic and much more! Se

Mazen 11 Sep 12, 2022