This sample application is inspired by the Django Rest Framework tutorial. I made it to learn usage of FastAPI with Tortoise ORM.
To test it, you must install the project with poetry.
$ poetry install
You also need to initialize the database with aerich.
$ aerich init-db
$ aerich upgrade
If you want pygments languages and styles to play with, there is a simple CLI to populate the related tables.
$ pastebin add-lang-to-db
$ pastebin add-styles-to-db
And if you want to create administrator users to play with authentication, there is also a CLI command for that purpose.
$ pastebin add-admin-user
# fill the information requested
Some thoughts about this project:
-
FastAPI has a steep learning curve (the doc is fill of information) but once mastered, you code really fast. It's a real pleasure that I haven't experienced since Django :)
-
Tortoise ORM was what I have wanted since the awareness of async when dealing with databases. Once again, I find the joy of using an ORM since Django and for good reason, it's almost a copy of the latter with just the async keyword to place before the method names.
-
The default test client provided by Starlette is not sufficient for async testing. I have to use httpx for that purpose, but I was not aware of this issue which makes it impossible to run startup and close events (callbacks) like initializing a database. This was such a pain! I should probably have use async-asig-testclient from the beginning. This is a lesson for the future.