Share connection between Django and SqlAlchemy

40 views
Skip to first unread message

Vladimir Mihailenco

unread,
Jun 22, 2011, 2:38:54 PM6/22/11
to Django users
I am trying to share connection between Django and SqlAlchemy. I tried
following code:

from django.db import connection
from sqlalchemy import create_engine

def get_connection():
if connection.connection is None:
connection._cursor() # TODO: better way to open new
connection?
return connection.connection

engine = create_engine('postgresql+psycopg2://',
creator=get_connection)
engine.execute(s) # s - SqlAlchemy query

But this results in various fails in SqlAchemy (like connection is
already closed, can't execute some queries). More details are
available here: http://stackoverflow.com/questions/6439119/django-and-sqlalchemy-share-connection

So I have following question:

- does anyone know working solution?
- how big will be performance impact if I use separate connection for
Django and SqlAlchemy?
- any explanations why current code is not working :)

Thanks.

Tomasz G.

unread,
Aug 28, 2013, 3:23:23 AM8/28/13
to django...@googlegroups.com
Hi, I am also going share Django ORM and SQLAlchemy connections.
Do you know the solution?

Thomas
Reply all
Reply to author
Forward
0 new messages