Best Flask open-source libraries and packages

Flask rest api barebones with authentication

Flask Rest-API boilerplate with JWT authentication
Updated 3 months ago

Contributors Forks Stargazers Issues MIT License LinkedIn


Flask + Mongodb + REST API + JWT Authentication

Boilerplate code for quick implimentation of REST API with JWT Authentication.

Report Bug

Table of Contents

About The Project

https://reddimohan.github.io

Normal Deployment

Built With

Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

This is an example of how to list things you need to use the software and how to install them.

  • Python - I am using Anaconda distribution for easy installation of Python and pip

  • Click here to Install Anaconda

        OR
    
  • You can download python from https://www.python.org/downloads/ and install

Installation

  1. Clone the repo
git clone https://github.com/reddimohan/flask-rest-api-barebones-with-authentication.git
  1. Create python environment so that we dont disturb other project versions
conda create --name rest_37 python=3.7
  1. Activate the rest_37 environment
conda activate rest_37
  1. Install required python libs
pip install -r requirements.txt
  1. Install Mongodb in local machine OR You can create the database in the MongoCloud for free, click here to get free account Note: If you have installed MongoDB locally you can follow 6th step otherwise ignore
  2. Setup password for mongo
    • Go to mongo console by using mongo
    • Execute below queries
    use library
    db.createUser(
        {
            user: "username",
            pwd: "password",
            roles: [ { role: "readWrite", db: "library" } ]
        }
    )
    • Enable authentication in /etc/mongodb.conf
    • Restart mongodb service
    • To connect to mongodb from console, use mongo library -u admin -p and then enter password when prompted
  3. Configure database.yml by following steps
    • rename main/database.yml_sample to main/database.yml
    • update DB_NAME, MONGO_USER, MONGO_PASS, HOST (You should have aquired this information from 5th or 6th step)
  4. export FLASK_ENV=development in Linux and use set in windows
  5. execute flask run to run the application
  6. Start the application
# python app.p
gunicorn app:app
# To see the no. of connections opened in MongoDB useful command
db.serverStatus().connections

Docker Deployment & CI/CD

  1. Clone the project
  2. copy .env_template to .env file and update all your configuration in the route directory
  3. Build the docker images using below command
docker-compose build
  1. Bring up the API server
docker-compose up -d # To run the service in Detach mode
OR
docker-compose up # to see the logs
  1. If everything works you can access the API docs on ```http://0.0.0.0:91/docs

Login to mongodb container

# connect to to interactive terminal <mongodb> is the container name
docker exec -it mongodb bash
  1. You can login to mogodb CLI using below command
mongo -u username -p 

You can find the crdentials from the .env file which you have created.

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Mohan - LinkedIn - Twitter

Project Link: https://github.com/reddimohan/flask-rest-api-barebones-with-authentication