This project is a REST API for storing and retrieving data documents. It allows users to create new data documents by sending a POST request to the API endpoint.
The API supports the creation of multiple data documents at once, each identified by a unique ID. The created documents are stored in a MongoDB database.
The API also supports retrieving data documents by their ID, using a GET request to the appropriate endpoint. The project uses Python and the FastAPI web framework, with asynchronous programming using the asyncio library. It also uses the PyMongo library for interfacing with MongoDB.
The API includes error handling and input validation to ensure data integrity and prevent unexpected errors.
-
Create a new Python environment and activate.
Conda (from scratch)
export PYTHON_VERSION=3.10.10 conda create --name fastapi python=PYTHON_VERSION conda activate fastapi
Conda environment.yml file
conda env create -f conda-environment.yml
Virtual environment
python -m venv ENV source ENV/bin/activate
-
Install dependencies in your environments
pip install -r requirements.txt pip install -r requirements-dev.txt
- You need have you own MongoDB Atlas Cluster
- Get the connection details including the URI, username and password
- Create a new environment file named
.env
- Copy the environment variables from
example.env
file from the root directory and paste it into the.env
file created above - Add the MongoDB Atlas URI with username and password next to the
MONGODB_URI
environment variable - To generate a the secret key, run the following command:
openssl rand -hex 32
Run the command below in the terminal
-
Linux
scripts/server.sh
-
Windows
uvicorn app.main:app --reload
-
Run with Uvicorn multiple workers
uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 4
-
Run with Gunicorn & Uvicorn
gunicorn app.main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:8000
-
Build the docker image with the following tag
docker build . -t {DOCKERHUB_USERNAME}/firebase-realtime-db-emulator:latest
-
Create and run the container
docker compose up
okteto login
okteto deploy --build
The theme of this semester’s project was emulation where the goal was to develop a prototype system that emulates the interface and working of a big data system.
Project Developed for DSCI 551: Foundations of Data Management
| Spring 2023
Developed By Kayvan Shah
| M.S. in Applied Data Science
|
University of Southern California