Documentation generated using DocuWriter.ai* - Full tree documentation *in 2 clicks.

Getting Started – Installation

Follow these steps to set up the rest-api project locally. Each step explains what it does and why it’s needed.

1. Create the Project Folder πŸ“

Start by making a dedicated directory for the REST API. This organizes your code and keeps dependencies contained.

mkdir rest-api
cd rest-api
  • mkdir rest-api: creates the project root.
  • cd rest-api: moves into the new folder.

2. Set Up a Python 3.8 Virtual Environment 🐍

A virtual environment isolates your project’s Python packages from the system, preventing version conflicts.

  1. Install virtualenv
   pip3.8 install virtualenv
  1. Create the virtual environment
   virtualenv venv --python=python3.8
  1. Activate the virtual environment
  2. macOS/Linux:
     source venv/bin/activate
  • Windows:
     venv\Scripts\activate.bat

Note: Your shell prompt will prefix with (venv), indicating activation.

3. Install Required Libraries βš™οΈ

These packages provide the web, REST, authentication, and database layers for the API.

pip install Flask
pip install Flask-JWT
pip install Flask-RESTful
pip install Flask-SQLAlchemy
Package Purpose
Flask Lightweight web framework
Flask-JWT JWT-based authentication
Flask-RESTful Simplifies building REST APIs
Flask-SQLAlchemy ORM layer over SQLite for model definitions and queries

4. Populate the Project Directory πŸ—‚οΈ

Copy the entire contents of the provided PYTHON folder into your rest-api directory. This includes:

  • app.py: Bootstraps the Flask app, configures JWT, and registers all routes
  • db.py: Initializes the SQLAlchemy instance
  • security.py: Defines authenticate and identity functions for JWT
  • models/:
  • book.py, store.py, user.py – define database tables and CRUD methods
  • resources/:
  • book.py, store.py, user.py – map HTTP methods to model actions
  • readme.md: Supplementary documentation
  • postman-collections/: Postman JSON to test all endpoints

Your rest-api folder should now look like:

rest-api/
β”œβ”€β”€ app.py
β”œβ”€β”€ db.py
β”œβ”€β”€ security.py
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ book.py
β”‚   β”œβ”€β”€ store.py
β”‚   └── user.py
β”œβ”€β”€ resources/
β”‚   β”œβ”€β”€ book.py
β”‚   β”œβ”€β”€ store.py
β”‚   └── user.py
β”œβ”€β”€ readme.md
└── postman-collections/
    └── Python Rest API.postman_collection.json
{
    "title": "Tip",
    "content": "Ensure you activate the virtual environment before running any commands."
}

5. Verify Installation βœ…

With everything in place and your virtual environment active, run:

python app.py
  • The server starts on http://localhost:5000.
  • You’re ready to explore the CRUD endpoints for books and stores, plus JWT-based authentication. Enjoy coding!