-
Create virtual env
python3 -m venv "env_name"
1.1 Set to use venv interpreter for VSCode Python:Select Interpreter >> Select venv bin/python 1.2 Set terminal to use venv python interpreter `source env_name/bin/activate`
-
Install FastAPI (make sure you use venv interpreter)
pip install fastapi
pip freeze
#to see all packages installedpip install "uvicorn[standard]"
-
start the server
uvicorn _main_script_loc_:_fastAPI_instance_name_ --reload
Ex:uvicorn app.main:app --reload
-
API docs
/doc
or/redoc
routes of the host server URL will give Swagger or Redoc API documentation automatically -
Create modules Adding
__init__.py
inside a folder will make it a module -
Database constraints
NOT NULL
UNIQUE
-
Packages
-
-
Python PostgreSQL database adapter
pip install psycopg2-binary
-
-
-
it is an ORM(Object Relation Mapper) - it let us use Python to interact with DB, and abstract away SQL - under the hood uses psycopg
pip install SQLAlchemy==1.4.49
-
-
-
If you update any tables, you have to drop current tables and replace it with the new old. While dropping you could loose the data that already exist. This is coz, sqlAlchemy don't push the table schema changes if the table is already present in the DB.
-
it can keep track of changes to DB and tables
alembic init __dir__
alembic revision -m "__message__"
alembic upgrade __revision_number__
-
show current revision applied
alembic current
-
show latest revision
alembic heads
-
this will auto-generate the alembic version based on the current model metadata state
alembic revision --autogenerate -m "__message__"
-
-
-
-
- Composite key
- primary keys that span more than one column
- there might be duplicate in a column, but the row-wise combination of entries will be unique
- Composite key
-
- fixtures
- they are like the code that run before or after each test
- parameterize
- used to pass different parameters to the tests
-x # stop when a test fail --disable-warnings # silence warnings
- fixtures
-
Notifications
You must be signed in to change notification settings - Fork 0
shihabus/learn-fastapi
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Learn FastAPI
Topics
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published