Skip to content

varunsinghal/flask-template-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flask template project


Code style: black


description

The Flask template project is a comprehensive starter template showcasing best practices for building RESTful APIs with Flask. It covers API development, serialization, database interaction, caching, unit testing, and includes Docker for project configuration.


features


API Development: The template provides a solid foundation for developing APIs using Flask. It demonstrates best practices for designing and implementing API endpoints, and handling request/response formats.


Serialization: The template showcases the use of serialization library Marshmallow to transform complex data models into JSON representations. It includes capabilities to define serializers, validate input data, and handle serialization errors.


Database Interaction: The template guides you on integrating Flask with a database using SQLAlchemy. It demonstrates how to define models, and perform CRUD operations.


Docker-based Setup: The template includes Docker configuration files, enabling you to set up the project using Docker containers. This approach simplifies the setup process by encapsulating the application, its dependencies, and the database into isolated and reproducible environments.


Unit Testing with Data Factories: The template incorporates the use of data factories to facilitate unit testing. These factories make it easy to generate test data objects with predefined attributes, enabling you to set up test scenarios and verify the functionality of the services.


Caching with Cachelib: The template demonstrates how to implement caching using the cachelib library. By caching API results, you can efficiently retrieve previously computed data without making repeated database queries. This improves performance by reducing the workload on the database and improving response times.


Query Control during Unit Testing: The template also validates query during unit testing by initializing a separate session for the database. This approach ensures that unit tests do not interfere with the production database and provides a clean and controlled environment for testing.




installation

  • docker
  • docker-compose
  • bash (optional)

setup

build the project

$ make start

load the database with dummy data provided using

$ make load_db

run server locally

$ make serve

testing

run the test cases

$ make test

print the test coverage report

$ make test_coverage

developer notes

  • PEP 8 compliance can be validated using make lint_check
  • apply PEP 8 rules while making changes using make lint
  • cache used is SimpleCache which is in memory cache store.
  • database has the functions to manage session like initialize, get and close.
  • serializer is used to translate the WEB request model to SQLAlchemy Model and vice versa.
  • models have the definition of tables in database
  • factories is used to create the model with random data

authors

Varun Singhal

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published