Monthly Archives August 2015

SQLAlchemy: Connecting to pre-existing databases & table joins!

SqlAlchemy is an object-relational mapper (ORM), which means that it takes SQL constructs and makes them Python objects which can be manipulated natively. Most of the time the same code can be recycled to use multiple database back-ends (unless you use back-end specific features).

I will be using Microsoft SQL Server for this particular example and show you how to use a technique called database reflection to get table information from a database schema when the database and tables already exist. For this you will need SQLAlchemy and pymssql installed.

#!C:\python27\python.exe
# -*- coding: utf-8 -*-

__author__ = "Jamie Ivanov"

from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine, MetaData, Table

def main():
engine = create_engine('mssql+pymssql://server/Databa...

Read More