Giter Club home page Giter Club logo

flask-sqlalchemy-hello-world's Introduction

flask-sqlalchemy-hello-world

Hello World REST API deployed with Python Flask and SQLAlchemy as ORM over SQLite database.

Dependencies

Installation

Local installation

Run an instance of PostgreSQL

Use your PostgreSQL instance or simply use Docker locally (specific internal network for the database instance):

docker network create db_net;
docker container run --name pg \
-e POSTGRES_PASSWORD=pass \
-d -p 5432:5432 \
--network db_net \
-v ${PWD}/data:/var/lib/postgresql/data \
postgres:12.2

Create app database using Docker psql, connecting to PostgreSQL previous instance:

docker container run \
--network db_net \
-it postgres:12.2 \
psql -h pg -U postgres -d postgres -c 'CREATE DATABASE fshw;'

Create virtual environment and install the app

Create virtual env:

python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip wheel setuptools

Install fshw:

deactivate; source .venv/bin/activate
pip install .

Run it!

  1. With premade script:
deactivate; source .venv/bin/activate
DATABASE_URL='postgresql+psycopg2://postgres:pass@localhost/fshw' run_fshw
  1. With gunicorn binary:
deactivate; source .venv/bin/activate
DATABASE_URL='postgresql+psycopg2://postgres:pass@localhost/fshw' \
gunicorn fshw.fshw:app
  1. With flask binary:
deactivate; source .venv/bin/activate
DATABASE_URL='postgresql+psycopg2://postgres:pass@localhost/fshw' \ 
FLASK_APP=fshw.fshw \
flask run
  1. With flask module:
deactivate; source .venv/bin/activate
DATABASE_URL='postgresql+psycopg2://postgres:pass@localhost/fshw' \ 
FLASK_APP=fshw.fshw \
python -m flask run

This will create a local server listening on default port (8000 for gunicorn, 5000 for Flask). Test it with:

  1. For gunicorn (previous options 1 and 2)
curl -i -X GET http://localhost:8000/hello
  1. For Flask (previous options 3 and 4)
curl -i -X GET http://localhost:5000/hello

flask-sqlalchemy-hello-world's People

Contributors

logoff avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.