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

  • SEARCH
  • Home
  • 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 4625956
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:20:52+00:00 2026-05-22T03:20:52+00:00

As a Pylons user I’m trying to switch to Pyramid now trying to understand

  • 0

As a Pylons user I’m trying to switch to Pyramid now trying to understand differences.

In Pylons I was used to define Session in myproj.model.meta as:

Session = scoped_session(sessionmaker())

then import it in myproj.model to define model and so on then in app refer to:

root = Session.query(MyModel).filter(...)...

now using a default template in Pyramid (pyramid_routesalchemy) I define Session as before (except calling it DBSession and adding an extension):

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))

but in views.py I don’t use it directly but instantiate it:

dbsession = DBSession()
root = dbsession.query(MyModel).filter(...)...

Why? What are the differences?


Moreover, what are the differences from Pyramid

import transaction
...
model = MyModel(name=u'root', value=55)
session.add(model)
session.flush()
transaction.commit()

to Pylons

model = MyModel(name=u'root', value=55)
session.add(model)
session.commit()
  • 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-22T03:20:53+00:00Added an answer on May 22, 2026 at 3:20 am

    Actually the way you are looking up your sqlalchemy session instance for querying doesn’t really have anything to do with pylons and/or pyramid. Pylons may have suggested one of the ways as being the “standard” pylons way but that’s it. The only real difference between the ways you’re getting your session is in the example using ZopeTransactionExtension.

    ZopeTransactionExtension is a little piece that makes sure every session that opens joins an active transaction. So if you were to open 5 session’s, they will all join the same transaction. That way if you commit or rollback the transaction, all the work done by the either of the 5 sessions will follow suit. The transaction module (“transaction.commit()”) is key here.

    pyramid_tm tries to make setting up a transaction straightforward … it starts one upon request entry, all scoped database sessions join it… and then at the end of the request, if it discovered an error, it will rollback the transaction. Otherwise, the transaction will be committed. That way view-level code never has to create or close/commit/rollback the transaction manually.

    Mostly session.flush() is for making sure your database model instances get their primary keys filled in without committing the transaction.

    So inside a view all you gotta do is:

    def myview(request):
        session = DBsession()
        session.add(model)
    

    pyramid_tm will make sure session is committed or rolled back appropriately.

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

Sidebar

Related Questions

Is there a way to get the timezone of the connecting user using Pylons,
I'm trying to modify a header using Middleware in Pylons to make my application
Firstly, I should say I'm completely new to Pylons, trying to learn web development
reading pylons documentations I did understand that websetup:setup_app is only called when the application
I currently have a Pylons application running with a basic user system set-up. I
I am using selenium with pylons to test user interactions. Everything was fine until
I have a working repoze.who/what setup (on a Pylons app). I now want to
I'm trying to use SqlAlchemy to make Sqlite database tables inside of Pylons. I'm
Need to read Pylons session data (just read, not write to) in node.js Once
Colander is a Python Pylons tool used to: validate and deserialize data obtained via

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.