Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6206189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:24:29+00:00 2026-05-24T05:24:29+00:00

What is the best option to use sqlalchemy for performing complex queries in Django

  • 0

What is the best option to use sqlalchemy for performing complex queries in Django project? I have found tranquil , but it does not look like a project with many users… Any suggestions?

Reason: I have 30-40 RawQueries across project and maintaining these queries is painful… I think SQLAlchemy can provide much better experience in this case.

UPDATE.

The main goal to achieve is to write some big complex query once and be able to refine it later as I need:

q = get_big_complex_sqlalachemy_query()
mine = q.filter_by(table.c.created_by_id=1)
closed = q.filter_by(table.c.is_closed=True)

The biggest problem with Django and SQLAlchemy is transaction management. If you use big transactions (one transaction per request) SQLAlchemy does not see any changes until you commit them (happy debugging :). So I wrote custom connection pool for SQLAlchemy to use Django connection. This is not ideal too (now there are problems in tests, because SQLAlchemy likes to wrap every select in transaction and I still don’t know how to disable this), but it looks better.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:24:30+00:00Added an answer on May 24, 2026 at 5:24 am

    While I’m not familiar with tranquil, I can say the way to use sqlalchemy in django is to… use sqlalchemy… in django!

    When I’ve used sqlalchemy in django projects in the past, I’ve usually been reading in data from external data sources (stuff not managed by the django ORM). With that in mind, I tend to use the SqlSoup extension which doesn’t require you to explicitly declare the structure of your data. This might be good for you too, since I’m guessing you don’t want to write all your models twice in 2 different ORMs.

    One other tip: if you don’t need sqlalchemy for every view, don’t open the connection in your settings module. Put your sqlalchemy code (including the connection creation) in its own module or package — keep it as isolated as possible. Only import the module and create the connection when you really need it.

    All of this depends on what your goal is though. Are your queries mainly read, or are you wanting to write as well? I don’t really have a sense of what it is you’re trying to do.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting out with MVC but not sure it's the best option. I need
I'm starting a new project here (Windows Forms). What's the best option today for
I'm trying to figure out the best option to use anonymous event listeners that
When should I not use the ThreadPool in .Net? It looks like the best
after some research I found that the best option for my current proyect is
Currently, I think my best option is to use std::set_intersection, and then check if
Is Yahoo the best option? http://developer.yahoo.com/geo/placefinder/ It says 50,000 requests per day. Does this
What is the best option to use in sql? ISNULL(x, 0) = 0 or
I want to use Markdown for my website's commenting system but I have stumbled
What is the best option if I want to upgrade old C-code to newer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.