Giter Club home page Giter Club logo

template-api-flask's Introduction

Template for API in Flask

Overview

This base project contains a scaffold for building a Flask API with the following features:

  • Logging
  • Testing
  • Caching
  • Containerization
  • Linting verification
  • CI/CD Integration

Features

  • Logging: Configured to output logs to both the terminal and a log file.
  • Testing: Uses pytest for testing, with fixtures and examples.
  • Caching: Configured with Flask-Caching for efficient data handling.
  • Containerization: Ready to be containerized with Docker.
  • Linting: Integrated with flake8 for code style checking.
  • CI/CD: Setup for continuous integration and deployment on AWS.

Setup Environment

  1. Set the local Python version:

    pyenv local 3.12
  2. Create a virtual environment:

    python -m venv venv
  3. Activate the virtual environment:

    source ./venv/bin/activate
  4. Install the required dependencies:

    pip install -r requirements.txt
  5. Run the application:

    gunicorn --bind 0.0.0.0:8080 app:app

Running Tests

If pytest does not recognize the src folder as a module, use the following command to set the PYTHONPATH:

export PYTHONPATH=$(pwd)

Run the tests with:

pytest

Lint Check

Check the code style with flake8:

flake8 .

Running with Gunicorn

To run the application using Gunicorn:

gunicorn --bind 0.0.0.0:8000 app:app

To build and run the Docker container:

docker build -t template-api:v1 .
docker run -p 8000:8000 --env-file .env template-api:v1

CI/CD Integration

For continuous integration and deployment, we utilize GitHub Actions. Our setup includes refreshing the AWS ECR image and triggering AWS App Runner to refresh its service source.

Variables that need to be set in GitHub Secrets:

  • AWS_ACCESS_KEY_ID
  • AWS_ACCOUNT_ID
  • AWS_REGION
  • AWS_SECRET_ACCESS_KEY

If you update or install some library

To update the libraries requirements, run:

pip freeze > requirements.txt

template-api-flask's People

Contributors

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