This is a simple Python FastAPI test application that works with an Oracle database.
The goal of this project was to learn a bit more about FastAPI, SQLAlchemy, Oracle Database and Docker. Once 'HelloWorld' started working, I wanted to experiment with something a bit more complex. Specifically, CRUD API which handles Foreign Keys, One-To-One and One-To-Many cascading relationships using SQLAlchemy and Oracle database behind it. Finally, I wanted to run the whole thing in a Docker.
The app will automatically create all 3 tables with sample data in the database on startup and will automatically drop them on shutdown
Tested on OS X 12.2
- Python 3.8 or higher is installed
- Docker is installed
After checking out the repo, in terminal, cd to the project root directory
Build Docker image using the Dockerfile.oracle
file
You will need to provide db_username, db_password, db_host, db_port and db_database as arguments when building the Docker
docker build -f ./Dockerfile.oracle -t fastapi-oracle-image . \
--build-arg DB_USERNAME="<db_username>" \
--build-arg DB_PASSWORD="<db_password>" \
--build-arg DB_HOST="<db_host>" \
--build-arg DB_PORT="<db_port>" \
--build-arg DB_DATABASE="<db_database>"
Run the newly created Docker image in a fastapi-oracle-container
container
docker run -d --name fastapi-oracle-container -p 80:80 fastapi-oracle-image
To stop the container
docker stop fastapi-oracle-container
Tested on OS X 12.2
- Python 3.8 or higher is installed
- Oracle client libraries are installed. These can be downloaded from: https://www.oracle.com/database/technologies/instant-client.html
After checking out the repo, in terminal, cd to the project root directory
Create virtual environment for the app
python3 -m venv .venv
Activate the virtual environment
source .venv/bin/activate
Install required packages from properties.txt
pip install --no-cache-dir --upgrade -r ./requirements.txt
Rename the template.env
file to .env
mv template.env .env
Edit the .env
file in the project folder
emacs .env
By filling in the following variables:
DB_USERNAME=""
DB_PASSWORD=""
DB_HOST=""
DB_PORT=
DB_DATABASE=""
Start the app
uvicorn main:app --reload