At @telestoAI, we have built the entire backend of our competition platform in FastAPI.
Why did we choose this instead of Flask or Django?
π This is a thread about why.
1οΈβ£ Defining schemas for endpoints is brilliantly simple with Pydantic.
You only have to create a Pydantic class and use type annotations in the path operation function.
2οΈβ£ Dependency injections. This is such a powerful and versatile feature!
Essentially, these are functions that are automatically called during path operations, handing the return value as an argument o the path operation.
One common usage is to get database connections.
But they can do much more! For instance, in our app app.telesto.ai, we use a dependency injection to get the user based on their session cookie.
If an endpoint requires special permissions, the dependency takes care of that.
Dependencies also simplify testing.
3οΈβ£ Working with databases is simple and fluent.
FastAPI doesn't force any ORM framework on you like Django and you don't have to go out of your way with extensions like Flask.
What you use and how you use it is completely up to you!
4οΈβ£ Autogenerated Swagger UI.
This is provided by default. Really useful for our one-man frontend team, composed by @nandurr.
5οΈβ£ Healthy ecosystem.
If you want to build fast, you shouldn't have to spend time pushing the boundaries of the framework or pioneering new features. When most things you need have been already built by others and there are several extensions, you are set. FastAPI is like this.
π Our team absolutely loves FastAPI, and it enables fast backend development for us, which is absolutely essential for a bootstrapping startup.
Our team agrees that it was the best choice.
In the next few days, I will create a thread where I talk more about our backend challenges in detail.
If you are about to start a new project, stay tuned! It is better to learn from the mistakes of others, than from your own :)
β’ β’ β’
Missing some Tweet in this thread? You can try to
force a refresh
Often, the problem is not important enough to justify the existence of a solution. This is the most basic trap to fall for: there is no market need for the product.
Take a look at the top 20 reasons why startups fail by @CBinsights. The number 1 is no market need, causing around 43% percent of failures.
Have you ever implemented a dynamic function dispatcher in Python, where you can register functions at runtime using the decorator syntax? (Like the routers for FastAPI.)
I did this recently, and I am going to teach you how to do it! I'll walk you through it in the thread below.
We will build an event handler to catch arbitrary events and dynamically execute a function to handle the event.
(A good example is catching events in a webhook listener.)
Time to use some decorator magic!
The usage is straightforward: 1) instantiate the EventHandler, 2) register handler functions for specific events, 3) pass the event to the EventHandler instance when caught.
Neural networks are getting HUGE. In their @stateofaireport 2020, @NathanBenaich and @soundboy visualized how the number of parameters grew for breakthrough architectures. The result below is staggering.
What can you do to compress neural networks?
πA thread.
1β£ Neural network pruning: iteratively removing connections after training. Turns out that in some cases, 90%+ of the weights can be removed without noticeable performance loss.
A few selected milestone papers:
π°Optimal Brain Damage by @ylecun, John S. Denker, and @SaraASolla. As far as I know, this was the one where the idea was introduced.