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.
- Install virtualenv
pip3.8 install virtualenv
- Create the virtual environment
virtualenv venv --python=python3.8
- Activate the virtual environment
- 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
authenticateandidentityfunctions 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.",
"type": "",
"filePath": "",
"badges": []
}
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!