- 🛠 Project Setup (Local Development)
- 🚀 Running The Server
- 🧪 Testing
- 👾 Troubleshooting
- 🤝 Contributing
- 📝 Resources
For first time setup of the project, follow the steps below:
- python 3.12+
- pip (please upgrade to the latest version)
python -m pip install --upgrade pip
-
Clone the repo
-
Create a virtual environment
python -m venv venv
-
Activate the virtual environment
source venv/bin/activate -
Install the libraries
pip install -r requirements.txt
For any libraries updates, please run the following command
pip freeze > requirements.txt -
Create a
.envfile in the root directory and add the environment variables (please ask for the variables from the team) -
If you are working with scheduler, currently we are using terraform to deploy the scheduler to google cloud scheduler
- Please make sure you have the following installed
- Terraform
- login to gcloud with the permitted account
- Please make sure you have the following installed
You're all set! 🚀 To start the development server, follow the next section.
-
Activate the virtual environment
source venv/bin/activate -
Run the server
uvicorn app.main:app --port 8000 --reload
or run with the main file (no real-time reload)
python -m app.main
-
To access the API documentation, visit
- 📜 Swagger UI (interactive) → http://127industry_code.0.0.1:8000/docs
- API KEY are needed in order to call any endpoints
- This server's API KEY allows access to every endpoint
- 🔥 ReDoc UI (read-only) → http://127.0.0.1:8000/redoc
- 📜 Swagger UI (interactive) → http://127industry_code.0.0.1:8000/docs
-
To terminate the server, press
Ctrl + Cin the terminal -
To deactivate the virtual environment, run
deactivate
- To run the tests, run the following command
pytest
For this repo, mostly you will want to compose up the docker only when you want to test the scheduler or job config
- Prerequisite: Make sure you have Docker/Orb stack installed and running
-
Pull the img
-
Compose up docker dev if you have never built the image or no changes are made to the Dockerfile (no need to run in python venv).
If you have already built the docker image, and no changes are made to the Dockerfile, you can skip the build step
docker-compose -f docker-compose.dev.yml up --build
simulate prod env
docker-compose -f docker-compose.prod.yml up --build
-
Compose up docker dev if you have already built the image and no changes are made to the Dockerfile
docker-compose -f docker-compose.dev.yml up
simulate prod env
docker-compose -f docker-compose.prod.yml up
-
compose down
docker-compose -f docker-compose.dev.yml down
- [macOS] If you encounter the following error:
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000), please install the python certificates by running the following commandReplace/Applications/Python\ 3.x/Install\ Certificates.command
3.xwith the version of python you are using.
- please format the code by running the pre-commit hook before committing
or
pre-commit run --all-files
or shortcutblack app/ isort app/ flake8 app/
option + shift + ffor mac - For any pre-commit hook updates, please run the following command
pre-commit autoupdate
This project uses Alembic to handle database schema migrations
- Please ensure that the Alembic database URL is set in the
.envfile - To create a new migration, run the following command
alembic revision --autogenerate -m "migration message" - To apply the migrations, run
alembic upgrade head
- To schedule a job, please go to
/infraand add the job to thescheduler.tffile - To deploy the scheduler, run the following command
terraform init # Only once per setup or if providers/backend changes terraform fmt # (Optional) Format files nicely terraform validate # (Optional) Check for syntax issues terraform plan # See what changes will happen terraform apply # Actually apply the changes
- SQLalchemy →
- Neon async → https://neon.tech/docs/guides/python#create-a-python-project
- colorlog → https://pypi.org/project/colorlog/
- Constructor Injection : complex dependencies or manage more state and logic (like services).
- Static Methods with DI : simple logic that just need to delegate to another layer without managing any state themselves.
-
top-prediction endpoints
- route layer : Static Methods with DI for db session and auth (not for controllers)
- controller layer : Static Methods with DI for services
- service layer : Constructor Injection for repositories
-
ml-ops endpoints
- route layer : Static Methods with DI for db session and auth (not for controllers)
- controller layer : Static Methods with DI for services
- service layer : Constructor Injection for repositories and ml client