API to serve AtA prescriptions.
In production, this is deployed via CD on AWS.
To run it locally from the ata_api directory, run: uvicorn main:app --reload. This will run the API on
localhost:8000. You can confirm it is up by pinging the root: curl localhost:8000/ should return a simple message.
To run it while pointing at a database, from the ata_api directory run:
HOST=fakehost PASSWORD=fakepw DB_NAME=fakedb USERNAME=fakeuser PORT=fakeport uvicorn main:app --reload
This project uses Poetry to manage dependencies. It also helps with pinning dependency and python versions. We also use pre-commit with hooks for isort, black, and flake8 for consistent code style and readability. Note that this means code that doesn't meet the rules will fail to commit until it is fixed.
We use mypy for static type checking. This can be run manually,
and the CI runs it on PRs to the main branch. We also use pytest to run our tests.
This can be run manually and the CI runs it on PRs to the main branch.
- Install Poetry.
- Install pyenv
- Install the correct Python version for this project, here Python 3.9:
pyenv install 3.9 - Activate the installed Python version in the current shell:
pyenv shell 3.9 - Create a virtual environment from this Python version using Poetry:
poetry env use 3.9 - Activate the virtual environment:
source $(poetry env list --full-path)/bin/activate - Run
poetry install --no-root - Run
pre-commit installto set uppre-commit
You're all set up! Your local environment should include all dependencies, including dev dependencies like black.
This is done with Poetry via the poetry.lock file.
The next times you open this directory on your IDE, make sure the virtual environment is activated (i.e., Step 6).
To manually run isort, black, and flake8 all in one go, simply run pre-commit run --all-files. Explore the pre-commit docs (linked above)
to see more options.
To manually run mypy, simply run mypy from the root directory of the project. It will use the default configuration
specified in pyproject.toml.
To update dependencies in your local environment, make changes to the pyproject.toml file then run poetry update from the root directory of the project.
To manually run rests, simply run pytest tests from the root directory of the project. Explore the pytest docs (linked above)
to see more options.
Integration tests (run via pytest -m integration or pytest tests, which runs all tests) require a mock database to be set up locally. Provided you've already installed Docker, in a separate terminal:
docker pull postgres
docker run --rm --name postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_HOST_AUTH_METHOD=trust -p 127.0.0.1:5432:5432/tcp postgres