TG’s Killer Features: SQLAlchemy. Obvious, no?

So, as I stated in a previous entry, I’ve been using SQLAlchemy for more than three years now.  If you know anything about me, you’d find it amazing that I have contributed little more than a patch here or there.  Why is that?  I think that’s because every time I try to find something that I need SQLAlchemy to do, it already does it.  I have spent so little time trying to make SQLAlchemy do what I want it to do, and so _much_ time getting work done with it.

Here is a good example.  One ohttp://www.flickr.com/photos/27342383@N07/3430321620/f my clients is a

company developing sports management software by the name of MVP.  Although I work on their next-gen stuff, I was called on by them to promote the students on the older system to the next grade over in the summer time.  Their database system had well over 40 tables, requiring no less then 10 of them to have modification.  I fired up sa, reflected the changes, wrote the changes in python, with simple loops around what records I needed to change, an it was done.  In one hour’s time I had a happy client, and a school system with a functioning system.  Two things about this are amazing.  1.  At the time, I had practically zilch in the Postgres experience department.  2. I only needed to learn the schema of the tables I was modifying, and I could do this with introspection.  The fact that I was able to do this task in less than an hour was only made possible by my knowledge of SQLAlchemy’s table-based architecture.  I did not need to know the nuances of Postgres’ SQL language (I was more familiar with MySQL at the time), or a in-depth knowledge of the database schema.  I was able to pick and prod until the job was done, and it was painless.

I really like the fact that SQLAlchemy’s approach to making an ORM is layered.  I can drop to whatever layer I need to to meet the requirements of my project.  SQL, table objects, and mapped objects all have their place in the grand scheme of things, and I have used them all to varying degrees. What SQLAlchemy achieves with this layering is the ability to adapt to existing projects, schemas, etc, and make considerably useful software, in a short amount of time.  By figuring out the nuances of different SQL dialects, it frees me up to focus on the task at hand, and provide products to my clients that work in a broad range of situations.

But this post is supposed to be about TurboGears, right?  For me, SQLAlchemy is more than a tool I use for TurboGears projects, or even web applications, it’s something I can use any time I have to access a relational database.  It is the ultimate base for writing tools that help me get my job done.  That job might be providing a system to allow schools to schedule matches against each other, or enabling scientists to access their data directly using objects at a python prompt, instead of assembling arcane sql strings to gather data.  SQLAlchemy is such a good basis in fact, that it makes building tools to help do my job even easier.

http://www.flickr.com/photos/giantrebus/2864731590/

I have had the opportunity to contribute to sqlalchemy-migrate.  If you don’t know anything about the project, consider this:  You have a production database you cannot break.  You have 5 minutes downtime to modify the schema, update records, etc.  You need to be able to back out the changes and bring the system back up if everything breaks.  Migrate lets you do all of this, and provides a versioning system to ensure that such a process moves smoothly.  I have used migrate with postgres, found some rough edges and fixed them.  SA’s table mapping makes this possible, migrate just adds a layer to make versioning and some table creation processes easier.  I only hope that someday some of the migrate code makes it’s way back into the SA codebase.

I do lots of testing.  I made numerous schema changes today to one of my databases at www.nrel.gov in fact.  I test the database schema for

http://www.flickr.com/photos/6x7/322551650/

matching against my definitions with some yet-to-be-released software.  There are about 3000 tests.  With tables numbering in the fifty-semod, I needed something to make data entry easier for my tests.  I wrote bootalchemy to do this.  You pass it some YAML, and the models module, and it performs all the entries for you.  It does a bit of introspection to determine dates, and it has reference pointing so you can inter-connect your objects within your yaml (using & and * like my old friend C).  This has vastly decreased the amount of time it takes me to create new test data for new tests.  Again, this is possible only with the framework that SA provides me.

Lately I have been interested in providing a broader base of scientists at NREL access to their data using python as a medium.  Scientists (especially physicists) are really good at conceptualizing data.  They use crazy tools like Matlab, and R and all sorts of proprietary tools to manipulate their data.  They aren’t afraid of a command prompt.  My idea is to give them something like Sage, but with direct access to their data as mapped objects.  I also want to be able to show up at a scientist’s desk with laptop in tow, connect to one of their existing databases, and spit out a admin-style web interface based on TG in a few minutes.  These notions have driven me to contribute sqlautocode.  At this point sqlautocode will spew out a page (or 7) of python code that provides you with Declarative Objects and an interactive prompt.  sqlautocde works as a library, so you can use saautocode’s output to directly in memory without generating any code at all.  All this is possible with SA, and I don’t know of anything else that can do all of this.

I have focused on the technical here, but beyone that is a great team of individuals like Mike Bayer and Jason Kirtland who put in long hours and answer questions promptly on the mailing list.  I often wonder how these guys get any sleep.  The thing that excites me most about SA is that it will soon release version 0.6, which to me means that these guys have 4 more versions of increased functionality before they consider it “done.”  So, as you can see, there is more to SA than just the ORM it provides.  It’s framework gives you freedom to expand your horizons and get your job done, by focusing it’s task on the challenges that relational databases all have, so you don’t have to.  This is what makes SA a killer feature of TG.

The third segment in this series is: TG’s Killer Feature: The Admin (Yes, We do, and it rocks)

47 Responses to “TG’s Killer Features: SQLAlchemy. Obvious, no?”

  1. lorg says:

    Hey
    Excellent post, I have to agree that sqlalchemy is excellent. So far I’ve been using sqlobject in my TG project, and one of my targets is moving to sqlalchemy.

    On other projects I also worked with sqlalchemy’s sqlsoup, and it’s been very helpful.

  2. Ben says:

    Have you tried fixture for loading data? http://farmdev.com/projects/fixture/

  3. rgz says:

    It would be interesting to read a step by step description of how you fixed that database schema!!

  4. Jorge Vargas says:

    @Ben, actually yesterday I was discussing that with percious. The killer feature of BootAlchemy is yalm, and even though we could make a Yalm loader for fixture, it’s not done yet, with yaml you can have non-python people. write your data and the pointer arithmetic are really nice.

  5. Christoph says:

    Good write-up, I could not agree more. Thanks for making me aware of bootalchemy and sqlautocode, they look quite useful.

  6. percious says:

    @ben

    I have played with fixture in the past. It really does not solve the class of problems that I am trying to solve. I want an imput format that has references, does introspection of my database data, and is serializable. It think fixture handles the first two, but the last one is a sticking point. If I wanted to write python code to create my object, well, i’d just write python code. Using a serialized format i can do things more modularly, opening the door for creating packages that enhance a database by upgrading/downgrating/augmenting. This is the ultimate goal I am working towards.

    cheers.
    -chris

  7. i applied for data entry jobs over the internet and it is also a good part time job.’~.

  8. Donny Felker says:

    I am really amazed. Today I spent a lot of my time trying to find something interesting on this topic. Finally I found your site. Thanks for that!

  9. {Animation,3D Studio Max, Adobe Flash,Art Galleries,Body Art,Classics,Crafts,Jewelry,Creativity,Dance,Ballet, Ballroom Dancing,Design,

  10. Heroblast says:

    Can I just say what a relief to search out someone who truly knows what theyre talking about on the internet. You undoubtedly know learn how to convey a problem to light and make it important. More individuals have to read this and understand this facet of the story. I cant consider youre not more in style because you undoubtedly have the gift.

  11. Be careful whenever drinking way too much beer since it can easily end up in alcoholism. Ofcourse if you’re an enjoyer of life just like i am then you might not care!

  12. I am a beginner along with your good results is very significantly an inspiration for me”

  13. Liebe SMS says:

    excellente bilhadiar de onteg y sinjexa con resir aeriameg. magandul a covinfeis y panarg nciasismo con cuzat cosontos!

  14. This website is typically a walk-through its the data you wished concerning this and didn’t know who ought to. Glimpse here, and you will definitely discover it.

  15. I’d have to check with you here. Which is not something I generally do! I enjoy reading a post that will make folks feel. Also, thanks for allowing me to comment!

  16. Hello! This post could not be written any better! Reading through this post reminds me of my previous room mate! He always kept talking about this. I will forward this post to him. Pretty sure he will have a good read. Thank you for sharing!

  17. BRE U Value says:

    I won’t state There isnothing to suggest that mothering cannot be shared by several people. or even Beware of too much laughter for it deadens the mind and produces oblivion.

  18. Merely wanna state that this is very helpful , Thanks for taking your time to write this. “I’ve had a perfectly wonderful evening. But this wasn’t it.” by Groucho Marx.

  19. Substantially, the post is actually the sweetest on this worthw hile topic. I fit in with your conclusions and will thirstily look forward to your next updates. Just saying thanks will not just be adequate, for the phenomenal lucidity in your writing. I will directly grab your rss feed to stay privy of any updates. Authentic work and much success in your business dealings!

  20. Failure is the condiment that gives success its flavor.

  21. You are NOTHING! Greatness builds futures for all, as in the concept of statesmen, prasites canibalize the past without new effort work, because they cannot concieve original ideas.

  22. Pretty section of content. I just stumbled upon your web site and in accession capital to assert that I get actually enjoyed account your blog posts. Any way I’ll be subscribing to your augment and even I achievement you access consistently rapidly.

  23. Howdy great website! Does running a blog similar to this take a lot of work? I have absolutely no knowledge of computer programming but I was hoping to start my own blog in the near future. Anyway, if you have any recommendations or tips for new blog owners please share. I know this is off topic but I just wanted to ask. Many thanks!

  24. Thanks for your article. I have continually seen that the majority of people are eager to lose weight simply because they wish to show up slim and attractive. Even so, they do not always realize that there are more benefits for you to losing weight also. Doctors say that over weight people suffer from a variety of disorders that can be perfectely attributed to their particular excess weight. The great news is that people who definitely are overweight in addition to suffering from numerous diseases are able to reduce the severity of their particular illnesses by simply losing weight. It is possible to see a constant but noticeable improvement in health when even a bit of a amount of weight reduction is reached.

  25. Retha Vieira says:

    I think this website has some very wonderful information for everyone :D . “This is an age in which one cannot find common sense without a search warrant.” by George Will.

  26. Here says:

    I like the valuable information you supply in your articles. I’ll bookmark your blog and check again here regularly. I’m moderately certain I’ll be told a lot of new stuff right right here! Best of luck for the following!

  27. Tesha Hanan says:

    I genuinely enjoy studying on this website, it contains wonderful posts. “The living is a species of the dead and not a very attractive one.” by Friedrich Wilhelm Nietzsche.

  28. If you are going to get serious about higher SERPs, like you talk about here, then you better look at using some type of service that builds backlinks to quality sources like .EDU or pyramids those links. I used this one, for example: http://bit.ly/Jvnrtp

  29. Hello, Neat post. There’s an issue with your site in internet explorer, could test this? IE nonetheless is the market leader and a big element of other folks will pass over your wonderful writing due to this problem.Read in detail about gold ira rollover.

  30. 3d Rendering|3d modeling|3d rendering company…

    [...]percious.com – TG’s Killer Features: SQLAlchemy. Obvious, no?[...]…

  31. I believe this is one of the so much significant info for me. And i am satisfied reading your article. But wanna observation on few common issues, The website style is ideal, the articles is actually nice :D . Good job, cheers.

  32. Pre order games says:

    Get 50% off from Pre-order games from EA ,see it to beleive it \

  33. click here says:

    I’d like to thank you for the efforts you’ve put in penning this blog. I really hope to view the same high-grade content by you in the future as well. In truth, your creative writing abilities has motivated me to get my very own blog now ;)

  34. Any child would look much more than lovable carrying a pair of handmade pet themed baby booties, so consider of these unique booties as a gift concept.

  35. Thanks for the auspicious writeup. It in truth used to be a leisure account it. Glance complex to more brought agreeable from you! However, how can we be in contact?

  36. dziwka says:

    looking for the best seo services http://www.seobizpro.com

  37. I like what you guys are up also. Such intelligent work and reporting! Keep up the excellent works guys I’ve incorporated you guys to my blogroll. I think it will improve the value of my web site :)

  38. Does your website have a contact page? I’m having problems locating it but, I’d like to shoot you an email. I’ve got some creative ideas for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it grow over time.

  39. Myra says:

    I am amazed how well they describe step by step abs trainig workouts http://www.weight-loss-success-stories.net/view/fatloss/

  40. Syble Dyment says:

    Well, unless you add another category to your browse list, for Christian/religious movies, it’s unlikely I will watch any movies from your site. As a Christian, I only desire to watch wholesome, family oriented, clean entertainment. For this reason, I do not even own nor desire to own a television. I pick and choose the programming I watch, via streaming movies and dvd’s that I can watch directly on my computer monitor, without filling my mind with the filth/garbage that plays on television these days.

  41. Glad to be one of the visitants on this awful web site D kalibugan.xlogzwp-includesimagessmiliesicon_biggrin .

  42. Some really howling work on behalf of the owner of this web site , dead outstanding written content .

  43. soraglono says:

    Привет Всем!Хотите заказать одежду на выгодных условиях? Тогда читайте новость – женские пижамы трусики женские и 7 км платья рубашки приталенные мужские … Удачи Всем!
    ::::::::::::
    Kamagra 100mg us – kamagra stockholm leverans or Kamagra bristol – order Kamagra without a prescription , Kamagra Oral Jelly 100mg offers – Kamagra Online France !!!!

  44. When My spouse and i originally mentioned We clicked on the actual -Notify me while brand-new comments are added- checkbox and now when a comment can be additional I get a number of messages with similar comment. Will there be any way you can remove us via which service? Cheers!

  45. Thank you a bunch for sharing this with all people you really understand what you’re talking about! Bookmarked. Please also seek advice from my website =). We could have a link alternate agreement between us

  46. I think that similar internet business owners should certainly have a look at this kind of web site as an example. Especially clean and easy to use approach, and in many cases good material! You are an authority in this particular subject matter :)

Leave a Reply