Giter VIP home page Giter VIP logo

fast_demo's Introduction

Fast Demo Project

Continuous Integration and Delivery

This project describes full project of FastAPI with RestAPI, Tortoise ORM, Testing, Deployment and CI/CD.

Tech stack used:

  • Python 3.12
  • Fastapi
  • Tortoise ORM
  • Postgresql 16
  • Pytest
  • Docker
  • Test coverage

Getting Started:

  1. Create Virtual Environment.
    python -m venv venv
  2. Install Dependencies
    pip install -r requirements.txt
  3. Export environment variables
    export ENVIRONMENT=prod
    export TESTING=1
    export DATABASE_URL=postgres://postgres:postgres@web-db:5432/web_dev
  4. Run the project
    uvicorn fast_app.main:app --reload

Docker Setup

  1. Build docker compose
    docker-compose up -d --build
  2. Create Database Migrations
    docker-compose exec web aerich init -t fast_app.db.TORTOISE_ORM
    docker-compose exec web aerich init-db
    docker-compose exec web aerich upgrade # To update migrations files if there are any changes
  3. Test with pytest
    # normal run
    docker-compose exec web python -m pytest
    
    # disable warnings
    docker-compose exec web python -m pytest -p no:warnings
    
    # run only the last failed tests
    docker-compose exec web python -m pytest --lf
    
    # run only the tests with names that match the string expression
    docker-compose exec web python -m pytest -k "summary and not test_read_summary"
    
    # stop the test session after the first failure
    docker-compose exec web python -m pytest -x
    
    # enter PDB after first failure then end the test session
    docker-compose exec web python -m pytest -x --pdb
    
    # stop the test run after two failures
    docker-compose exec web python -m pytest --maxfail=2
    
    # show local variables in tracebacks
    docker-compose exec web python -m pytest -l
    
    # list the 2 slowest tests
     docker-compose exec web python -m pytest --durations=2
  4. Run coverage
    docker-compose exec web python -m pytest --cov="."
  5. Run flake8
    docker-compose exec web flake8 .
  6. Run Black
    docker-compose exec web black . --check
  7. Run isort
    docker-compose exec web isort .

fast_demo's People

Contributors

mugdhakolte avatar

Stargazers

Mustafa COSKUNCELEBI avatar jist avatar  avatar

Watchers

 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.