Coder Social home page Coder Social logo

matinone / quiz-app Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 168 KB

Quiz app using Python best practices for backend development.

License: MIT License

Python 97.78% Dockerfile 1.14% Mako 0.98% Shell 0.10%
fastapi alembic async-sqlalchemy factory-boy mypy poetry pydantic pytest ruff

quiz-app's Introduction

Quiz App

Quiz app using FastAPI.

Setup

This project uses Poetry for dependency management.

$ curl -sSL https://install.python-poetry.org | python3 -   # install Poetry
$ poetry install                                            # install project dependencies using Poetry

Poetry is also used to run different commands to start the server or run tests, which requires installing the Poe the Poet task runner. Poe the Poet is already added as a dependency in the pyproject.toml file, so it should have been installed with the poetry install command, but the separate Poetry plugin must also be added.

$ poetry self add 'poethepoet[poetry_plugin]'

At this point, the following commands can be run:

$ poetry poe start      # run Uvicorn server
$ poetry poe test       # run testcases
$ poetry poe lint       # run Ruff linter
$ poetry poe format     # format code with Ruff
$ poetry poe precommit  # run pre-commit hooks

More arguments can be added to the base commands, for example poetry poe start --reload.

There are also pre-commit hooks configured to run the Ruff linter and code formatter. To install them, run pre-commit install.

Run with Docker (SQLite)

  1. Set USE_SQLITE=true in the .env file.
  2. Build the image (-t to tag the image).
$ docker build -t fastapi_quiz .
  1. Run the container (-d for detached mode to run the container in the background, -p HOST:CONTAINER to map the ports).
$ docker run -d -p 8000:8000 --name fastapi_cont fastapi_quiz
  1. The app can now be accessed from http://0.0.0.0:8000 (docs at http://0.0.0.0:8000/docs).
  2. Access app logs (-f to follow the logs).
$ docker logs fastapi_cont -f
  1. Stop and remove the containers.
$ docker stop fastapi_cont
$ docker rm fastapi_cont

Run with Docker Compose (PostgreSQL)

  1. Run docker compose (optional --build to rebuild the images).
$ docker compose up -d
  1. The app can now be accessed from http://0.0.0.0:8000 (docs at http://0.0.0.0:8000/docs). The pgAdmin platform can be accessed from http://0.0.0.0:5050, using [email protected] and password=admin to login (they are defined in the docker-compose.yml file).
  2. Access app logs (-f to follow the logs).
$ docker logs fastapi_app -f # FastAPI app logs
$ docker logs postgres_db -f # PostgreSQL logs
  1. Stop and remove the containers (-v to also delete the volume used for PostgreSQL data).
$ docker compose down -v

quiz-app's People

Contributors

matinone avatar

Stargazers

 avatar  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.