Of course there is more of them, but I focused on the most popular ones.
I chose SQLAlchemy, because it is free, has a huge set of features, supports many dialects (such as PostgreSQL, MySQL…), and the project is quite mature.
How do we use SQLAlchemy with Django?
Installation
First, setup Aldjemy from your virtual environment (this will install SQLAlchemy as well):
pip install aldjemy
(for Python 3 and PostgreSQL’s HSTORE support, install the package manually from this repository)
In your Django application’s settings script, add the following item to the INSTALLED_APPS tuple:
'aldjemy',
Usage
Now let’s imagine we have a module called myapp.models, in which we defined three Django models (namely Blog, Author and Entry). The following declaration will make those entities available as SQLAlchemy models:
import myapp.models
Blog = myapp.models.Blog.sa
Author = myapp.models.Author.sa
Entry = myapp.models.Entry.sa
To access SQLAlchemy’s session object, define this little function:
def Session():
from aldjemy.core import get_engine
engine = get_engine()
_Session = sessionmaker(bind=engine)
return _Session()
Then simply call:
session = Session()
You can now perform SQLAlchemy queries within the Django ORM. Congratulations!