Coder Social home page Coder Social logo

lu1slima / flask-hintful Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gabrielcappelli/flask-hintful

0.0 1.0 0.0 69 KB

Flask-Hintful helps you write Restful APIs using Flask by taking advantage of Python's type hints.

License: MIT License

Python 100.00%

flask-hintful's Introduction

Build Status codecov Documentation Status

Flask-Hintful

Flask-Hintful helps you write Restful APIs using Flask by taking advantage of Python's type hints.

Includes support for serializing/deserializing parameters according to type hints and automatically generating OpenApi documentation for your registered routes.

Requirements

  • Python 3.7+
  • Flask
  • Marshmallow < 3

Installation

Install using pip

pip install flask-hintful

Quick Start

Construct a FlaskHintful object by passing the Flask application as a parameter, then use the FlaskHintful object @route and .register_blueprint to register routes.

Create your view functions with type hints and FlaskHintful will serialize pass path args, query args and even the request body for you.

from dataclasses import dataclass
from datetime import date, datetime

from flask import Flask

from flask_hintful import FlaskHintful

app = Flask('My API')
api = FlaskHintful(app)


@dataclass
class NestedModel():
    str_field: str


@dataclass
class DataclassModel():
    str_field: str
    int_field: int
    float_field: float
    boolean_field: bool
    list_field: list
    date_field: date
    datetime_field: datetime
    nested_field: NestedModel


@api.route('/<id>/dataclass_test', methods=['POST'])
def dataclass_route(id: str, query_arg: int, model: DataclassModel) -> DataclassModel:
    '''my dataclass route'''
    return model


app.run()

You will be able to access the generated OpenApi on /swagger.

Preview1

Documentation

https://flask-hintful.readthedocs.io/

License

This project is licensed under the MIT License - see the LICENSE file for details

flask-hintful's People

Contributors

gabrielcappelli avatar lu1slima avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.