Code Monkey home page Code Monkey logo

Comments (17)

amitness avatar amitness commented on May 31, 2024 1

@deb17 There are extensions such as fastapi-sqlalchemy. But it's still new and not as feature rich as flask-sqlachemy.

from blog-comments.

cjakuc avatar cjakuc commented on May 31, 2024

Very clear and concise intro to FastAPI for Flask users! FastAPI has some great documentation but I'd love if you included an example of the FastAPI documentation generation. Then you could show how to use the example key of schema_extra in class Config as well as tags to customize the generated documentation. It would fit very nicely with how you have introduced FastAPI's implementation of Pydantic schema. I really enjoyed using these features recently if you want some examples.

That would make this an even more perfect intro to FastAPI for friends and colleagues who use Flask!

from blog-comments.

amitness avatar amitness commented on May 31, 2024

@cjakuc That sounds like a good idea. I'll add sections on those to the post.

If you've some interesting examples to share from your experience, I would love to hear them.

from blog-comments.

cjakuc avatar cjakuc commented on May 31, 2024

I like the updates to the post! I had no idea about /redoc. I've only used FastAPI once now but really loved it and there's obviously still so much for me to learn, I'll share my example below.

Here is the deployed API with customized schema_extra and tags.

Here is a .py file in the GitHub repo that shows the definition of a customized schema_extra.

The list of tags/descriptions are created in main.py, passed into the app when it is instantiated (also in main.py), and called when creating the corresponding endpoints within the routers folder.

My work could definitely use some refactoring to better utilize the Pydantic BaseModel like you did in your nested objects example. That would make the schema_extra tweaks a little redundant but you could still do this to show an example when defining the UserGroup class:

class UserGroup(BaseModel):
    users: List[User]
    group: str

    class Config:
        schema_extra = {
            "example": {
                "users": [
                    {
                    "name": "xyz",
                    "age": 25
                    },
                    {
                    "name": "abc",
                    "age": 30
                    }
                ],
                "group": "Group A"
            }
        }

from blog-comments.

alexmojaki avatar alexmojaki commented on May 31, 2024

Check out instant_api, for a FastAPI-like experience but within Flask.

from blog-comments.

amitness avatar amitness commented on May 31, 2024

@alexmojaki Looks interesting. Thanks for sharing your project.

from blog-comments.

 avatar commented on May 31, 2024

I like fastAPI. I use it in one of my projects
FastAPI is good if you need just backend like API or something
I use it in my chatbot project that has no frontend part

but in another project I still prefer to use Flask
because if I make a web app I have to cope with logins or jwt, webforms, databases (orm) and some sort of admin panels

from blog-comments.

amitness avatar amitness commented on May 31, 2024

@IDQDD Agree with you. It's important to choose the right tool for the right job. If a project has frontend templating needs, Flask/Django is a more suitable choice.

from blog-comments.

kstrz avatar kstrz commented on May 31, 2024

Hi! It's really nice introduction to FastApi. In general FastApi looks like a good alternative for Flask. I wonder I you came across any limitations, shortcomings when working on production with FastApi?

from blog-comments.

amitness avatar amitness commented on May 31, 2024

@kstrz For my usecase there were no limitations since my project involves only REST APIs and I was on "Python 3.7".

If your project involves a lot of jinja templating and server-side rendering of HTML templates, then FastAPI is not a good choice.

Also, FastAPI only supports python 3.6+, so if your project is written in older version of Python or has some legacy dependency, you might have to rewrite few portions. Making sure all dependencies work could be a trouble.

from blog-comments.

alexmojaki avatar alexmojaki commented on May 31, 2024

Another similar library: https://github.com/zero-shubham/flask-ease

from blog-comments.

ihfazhillah avatar ihfazhillah commented on May 31, 2024

Thank you for your overview about fastAPI

from blog-comments.

deb17 avatar deb17 commented on May 31, 2024

Nice introduction to fastapi. I am thinking of using it as the backend for my vuejs projects. But what about database access? Does it have extensions like flask-sqlalchemy and flask-migrate? Or do we have to fall back on sqlalchemy and alembic?

from blog-comments.

quantotto avatar quantotto commented on May 31, 2024

Great article, Amit!
Did you have any experience with streaming responses? In Flask, this is achieved by having your route method returning a generator that will be yielding response chunks. This is useful when the response data is being generated on the fly and large in size (e.g., my Flask REST API is building a video or audio clip and sending to client who asked to download it).
Thanks!

from blog-comments.

amitness avatar amitness commented on May 31, 2024

@quantotto Look into: https://fastapi.tiangolo.com/advanced/custom-response/#streamingresponse

from blog-comments.

mfrey777 avatar mfrey777 commented on May 31, 2024

Great post and very helpful to have the side by side examplse.
My understanding is that you need to defined all the FastApi function as "async" to really get performance benefits compared to Flask. If the functions are run on the main thread, then there is not really any peformance benefits.

from blog-comments.

zirismetov avatar zirismetov commented on May 31, 2024

thx! Very usefull

from blog-comments.

Related Issues (20)

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.