SQLAlchemy (4)


Flask + SQLAlchemy tips

First and foremost: this : https://flask-sqlalchemy.palletsprojects.com/en/2.x/ This is the old Flask website built in flask. Some patterns are outdated. But still pretty nice to gloss over with a cup of tea and some buiscuits. 🙂 https://github.com/pallets/flask-website/tree/master/flask_website scoped_session(sessionmaker()) or plain sessionmaker() ? Well, the recommended pattern is to use scoped_session as it is considered thread safe. […]




Install psycopg2 on Ubuntu 18.04+

I was trying to install psycopg2 database adapter for PostgreSQL on Ubuntu 18.04. And was always getting an error when doing “pipenv install psycopg2”, complaining about “Python.h” missing. After much head-scratching, I found the issue. Multiple Python distributions confuse psycopg2 installation. Its like this. psycopg2 has two main dependencies libpq-dev python3-dev. On Ubuntu, you install […]




SQL Alchemy tutorial

This describes the basic overview of SQL Alchemy. Notice the color theme. It will be related to the next onion-ring overview of SQL Alchemy. SQL Alchemy is divided into Core and ORM. You can use Core and not use ORM. ORM is more geared towards mapping model objects to Python data types. Core on the […]




Basic Rest API in Flask and SqlAlchemy

Step 1: pipenv install –python 3.8 Step 2: pipenv shell Step 3: pipenv install flask flask-sqlalchemy flask-marshmallow marshmallow-sqlalchemy flask-migrate psycopg2 flask-sqlalchemy is the sql-alchemy with flask bindings. flask-marshmallow is like the Serializer in Django Rest Framework, marshmallow-sqlalchemy is common binding between marshmallow and sqlalchemy (for things like ModelSerializer in Django Rest Framework).flask-migrate is migration tool […]