Developing Python backends has changed overtime.
If 4-5 years ago, my choice for a backend framework would have been Django or Flask depending on the task at hand, today I can clearly say that in 90% of my use cases, FastAPI covers all my backend needs in a fast and easy to implement manner.
So what is FastAPI?
- it provides a quick and simple way to create backend api`s that run fast.
Citing the framework`s author:
"FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.
The key features are:
Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). One of the fastest Python frameworks available.
Fast to code: Increase the speed to develop features by about 200% to 300%. *
- Fewer bugs: Reduce about 40% of human (developer) induced errors. *
- Intuitive: Great editor support. Completion everywhere. Less time debugging.
- Easy: Designed to be easy to use and learn. Less time reading docs.
- Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.
- Robust: Get production-ready code. With automatic interactive documentation.
- Standards-based: Based on (and fully compatible with) the open standards for APIs: OpenAPI (previously known as Swagger) and JSON Schema."
Q: Well, thats nice! But how much does it take to learn it from scratch?
A: With some previous experience (let`s say with Flask) it should not take more than 1-4 days (thats if you want to keep it simple and develop a microservice that does an isolated task). However if you want to go deeper, and delve into security and routers (to plan for bigger app architectures) it might take a bit longer than that.
Q: Ok, so using my past experience (other language, or framework) I can get on with it in under a week, right?
Q: How about if my backend needs to comunicate with a database, can FastAPI do that too?
A: Not quite. However if you plan to learn FastAPI, its documentation also provides some basic examples on how to use SQLAlchemy to interact with a database. SQLAlchemy is an ORM which can give you the full power and flexibility of SQL.Companies like: "Yelp!", "reddit", "dropbox" and others uses SQLAlchemy and I used it myself too.
From my experience with SQLAlchemy I can say I really liked it because it enabled me to work with relational databases in a simple and python way, writing python rather than sql. Also for the backend of our webshops platform I took advantage of SQLAlchemy and I acomplised complex functionalities with just a few lines of code.
Q: Ok, enough talking, where can I find the documentation?