Blog FastAPI
March 31, 2022 ยท View on GitHub
This project uses: Python, PostgreSQL, FastAPI, SQLAlchemy, Alembic and pytest.
PostgreSQL Install Steps
You can install PostgreSQL 14.2 on your computer following the steps from this link.
Or you can install PostgreSQL with Docker using:
docker pull postgres:14.2
Installing application
To install the application use following commands:
python -m pip install --upgrade pip
pip install -r requirements.txt
Environment configuration
Following environment variables need to be set in your OS or added in a new .env file from root of this directory.
DATABASE_HOSTNAME = localhost
DATABASE_PORT = 5432
DATABASE_NAME = ADD_HERE_YOUR_DB_NAME
DATABASE_USERNAME = ADD_HERE_YOUR_DB_USERNAME
DATABASE_PASSWORD = ADD_HERE_YOUR_DB_PASSWORD
JWT_SECRET_KEY = ADD_HERE_A_JWT_SECRET_KEY
JWT_ALGORITHM = HSA256
JWT_ACCESS_TOKEN_EXPIRE_MINUTES = 60
You can generate a JWT secret key using following command:
openssl rand -hex 32
Install pytest
You can install pytest using:
pip install -U pytest
Run tests
You can run your tests using:
pytest -s -v
Running the application in dev mode
You can run your application in dev mode that enables live coding using:
uvicorn app.main:app --host 0.0.0.0 --port 8000
Related Guides
- Python (guide): Python is a programming language that lets you work quickly and integrate systems more effectively.
- PostgreSQL (guide): The World's Most Advanced Open Source Relational Database
- FastAPI (guide): FastAPI framework, high performance, easy to learn, fast to code, ready for production
- SQLAlchemy (guide): SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL.
- Alembic (guide): Alembic is a lightweight database migration tool for usage with the SQLAlchemy Database Toolkit for Python.
- pytest (guide): Creating and executing Python tests.