Before running the APEx Dispatch API locally, ensure the following prerequisites are met:
- A working Python environment to install and run the API dependencies.
- A PostgreSQL database to store job-related information.
Follow these steps to set up and run the API in your local development environment:
Use pip to install the required Python packages:
pip install -r requirements.txtTo set up a PostgreSQL database locally, you can use Docker for convenience and persistence.
This step ensures your PostgreSQL data is stored persistently:
docker volume create local-postgres-dataTo view the physical location of the volume on your host machine:
docker volume inspect local-postgres-dataRun the following command to start a PostgreSQL instance linked to your volume:
docker run -d --name postgres -p 5432:5432 \
-e POSTGRES_USER=testuser \
-e POSTGRES_PASSWORD=secret \
-e POSTGRES_DB=testdb \
-v local-postgres-data:/var/lib/docker/volumes/local-postgres-data \
postgres:latestCreate a .env file in the root directory of the project and set the necessary environment variables as described in the Environment Configuration documentation.
Ensure your database schema is up-to-date by running:
alembic upgrade headTo start the API, open a new terminal and execute the following:
uvicorn app.main:app --reloadThe API will be available at:
- Swagger UI: http://127.0.0.1:8000/docs
Testing is essential to ensure stability and prevent regression issues from affecting the functionality of the API. This project includes a comprehensive suite of tests to validate its core features and maintain code quality.
The repository contains an extensive collection of unit tests that cover the main components and functionalities of the codebase. To execute the test suite, run:
pytestThis will automatically discover and run all tests located in the designated test directories.
To maintain consistent code quality and enforce best practices, the project uses flake8 for linting and mypy for static type checking. You can run these tools manually with the following commands:
flake8 app tests
mypy appThese checks help identify potential issues early, such as syntax errors, unused imports, and type mismatches, contributing to a more robust and maintainable codebase.