- Authored by Kyle Clark - kyleaclark.com
- Python FastAPI production ready template with Poetry dependency management
- Python 3.10.7
- Poetry dependency management
- Setup instructions are specific to macOS. Steps may vary.
- Install pyenv for python version management - https://github.com/pyenv/pyenv
- Update pyenv if previously installed e.g. via brew
brew upgrade pyenv
- Install poetry for python dependency management - https://python-poetry.org/docs/#installation
- Update poetry if necessary (optional):
poetry self update
- Add pyenv path to profile e.g. add
export PYENV_ROOT="$HOME/.pyenv
+ export PATH="$PYENV_ROOT/bin:$PATH"
- Add poetry path to profile e.g. add
export PATH="$HOME/.poetry/bin/:PATH
- Install python version:
pyenv install 3.10.7
- Set python version within the repo directory:
pyenv local 3.10.7
- Set the poetry env version of python:
poetry env use ~/.pyenv/versions/3.10.7/bin/python
- Install python application dependencies:
poetry install
- Run text game via terminal:
poetry run python main.py
- Run tests via terminal:
poetry run python -m pytest -p no:cacheprovider tests
- Open PyCharm Preferences
- Open Project Interpeter > Add existing Virtualenv Environment e.g.
/Users/<username>/Library/Caches/pypoetry/virtualenvs/<poetry-name>/bin/python3
- Open Tools > Python Integrated Tools > Default test runner: pytest
- Run text game: Right-click on
main.py
and choose Run
- Run tests via pytest: Right-click on
tests
and choose Run
- Note: Steps may vary for different PyCharm versions.
docker build --target application -f Dockerfile -t fastapi-template .
docker run --user=appuser -p 8000:8000 --env APP_ENV=DEV fastapi-template
docker build --target testing -f Dockerfile -t fastapi-template-testing .
docker run --user=appuser --env APP_ENV=DEV fastapi-template-testing
Build & Run App (local dev)
docker-compose -f conf/docker/image.service.yaml build
docker-compose -f conf/docker/service.local.dev.yaml up
docker-compose -f conf/docker/service.local.dev.yaml down
Build & Run App (local dev)
docker-compose -f conf/docker/image.service.yaml build
docker-compose -f conf/docker/service.deployed.dev.yaml up
docker-compose -f conf/docker/service.deployed.dev.yaml down
Build & Run Tests (local dev)
docker-compose -f conf/docker/image.service.yaml build
docker-compose -f conf/docker/testing.local.dev.yaml up
docker-compose -f conf/docker/testing.local.dev.yaml down