GithubHelp home page GithubHelp logo

fastapi-template's Introduction

FastAPI-Template

  • Authored by Kyle Clark - kyleaclark.com
  • Python FastAPI production ready template with Poetry dependency management

App Environment

  • Python 3.10.7
  • Poetry dependency management
  • Setup instructions are specific to macOS. Steps may vary.

Setup Prerequisites

  1. Install pyenv for python version management - https://github.com/pyenv/pyenv
  2. Update pyenv if previously installed e.g. via brew brew upgrade pyenv
  3. Install poetry for python dependency management - https://python-poetry.org/docs/#installation
  4. Update poetry if necessary (optional): poetry self update
  5. Add pyenv path to profile e.g. add export PYENV_ROOT="$HOME/.pyenv + export PATH="$PYENV_ROOT/bin:$PATH"
  6. Add poetry path to profile e.g. add export PATH="$HOME/.poetry/bin/:PATH
  7. Install python version: pyenv install 3.10.7

Python Environment

  1. Set python version within the repo directory: pyenv local 3.10.7
  2. Set the poetry env version of python: poetry env use ~/.pyenv/versions/3.10.7/bin/python
  3. Install python application dependencies: poetry install

Python Execution

  1. Run text game via terminal: poetry run python main.py
  2. Run tests via terminal: poetry run python -m pytest -p no:cacheprovider tests

Optional: PyCharm Setup

  1. Open PyCharm Preferences
  2. Open Project Interpeter > Add existing Virtualenv Environment e.g. /Users/<username>/Library/Caches/pypoetry/virtualenvs/<poetry-name>/bin/python3
  3. Open Tools > Python Integrated Tools > Default test runner: pytest
  4. Run text game: Right-click on main.py and choose Run
  5. Run tests via pytest: Right-click on tests and choose Run
  • Note: Steps may vary for different PyCharm versions.

Docker

Build & Run App

docker build --target application -f Dockerfile -t fastapi-template .
docker run --user=appuser -p 8000:8000 --env APP_ENV=DEV fastapi-template

Build & Run Tests

docker build --target testing -f Dockerfile -t fastapi-template-testing .
docker run --user=appuser --env APP_ENV=DEV fastapi-template-testing

Docker Compose

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

Poetry Reference

fastapi-template's People

Contributors

kyleaclark avatar

Stargazers

Daniel Munoz avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.