Skip to content

stventek/python-api-no-framework

Repository files navigation

python-api-no-framework

Simple python recipe REST API built with no framework using:

  • Python as Programming Language.
  • Werkzeug for WSGI utilities.
  • Marshmallow and Marshmallow-SQLAlchemy for serialization and deserialization.
  • SQLAlchemy as an ORM.
  • PostgreSQL as a database.
  • Alembic 2.0 as database migrations tool.

This is a WSGI application that utilizes wsgiref.simple_server for development purposes. Additionally, it includes a wsgi.py file for deploying the application with Gunicorn.

Models

Model: Ingredient

Attribute Type
id int (primary key)
name str (30)
measurement_unit str (30)
Relationship Type
recipes (viewonly) List[Recipe]
recipe_associations List[AssociationIngredientRecipe]

Model: Recipe

Attribute Type
id int (primary key)
name str (30)
description Optional[str]
instructions Optional[str]
Relationship Type
ingredients (viewonly) List[Ingredient]
ingredient_associations List[AssociationIngredientRecipe]

Model: AssociationIngredientRecipe

Attribute Type
ingredient_id int (primary key)
recipe_id int (primary key)
quantity Optional[str]
Relationship Type
recipe Recipe
ingredient Ingredient

Endpoints

The app supports the following endpoints:

  • /recipes - Gets all recipes
  • /recipe/<int:id> - Gets a recipe by ID
  • /ingredients - Gets all recipes
  • /ingredient/<int:id> - Gets a recipe by ID

Database

The application uses PostgreSQL as its database. To set up the database, create a PostgreSQL instance and set the DATABASE_URL environment variable to the connection string.

Setup

  1. Clone the repository:
git clone [email protected]:xenizs/python-api-no-framework.git
cd 
python-api-no-framework
  1. Create Virtual env:

python -m venv venv

  1. activate virtual env:

source venv/bin/activate

  1. install dependencies

pip install -r requirements.txt

  1. set the DATABASE_URL environment variable for the connection to a postgreSQL database.

  2. run the migrations

alembic upgrade head

  1. Start the application

python main.py

  1. (optional, run with gunicorn)

gunicorn wsgi:app

Running tests

Run all tests:

python -m unittest discover -s tests -p "*.py"

Migration commands:

  • Initialize migrations:

alembic init migrations

  • Make migrations

alembic revision --autogenerate -m "Initial migration"

  • apply migrations:

alembic upgrade head

Seeding the database

python seeders/recipe_seeder.py

python seeders/ingridient_seeder.py

About

Simple python recipe REST API built with no framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published