A simple REST API for performing CRUD operations on person records using Flask-smorest and SQLAlchemy.
Before you begin, ensure you have met the following requirements:
- Python 3.7 or higher installed.
virtualenv
installed (optional but recommended for isolating project dependencies).- Git installed.
- Access to a PostgreSQL, MySQL, or SQLite database (SQLite is used by default).
-
Clone this repository:
git clone https://github.com/your-username/person-crud-api.git cd person-crud-api
-
Create and activate a virtual environment:
python -m venv venv
For macOS / Linux:
source venv/bin/activate
For Windows:
venv\Scripts\activate
-
Install project dependencies:
pip install -r requirements.txt
-
Create a
.flaskenv
file in the root directory for basic environmental variables:DATABASE_URL=sqlite:///data.db # Use your database URL (e.g., PostgreSQL or MySQL) FLASK_ENV=development FLASK_APP=app.py
P.S.: Not recommended for production.
Create the initial database tables:
flask db init flask db migrate -m "Initial migration" flask db upgrade
Start the development server using the command:
flask run
The API will be running locally at http://localhost:5000
.
Before running the tests, ensure you have the following dependencies installed:
- pytest (You can install this using
pip install pytest
) or - unittest (You can install this using
pip install unittest
)
You can run the tests for this project using the following command:
pytest
or
python3 -m unittest -v