<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Python Blog - All about python &#187; SqlAlchemy</title>
	<atom:link href="http://www.python-blog.com/tag/sqlalchemy/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.python-blog.com</link>
	<description>and technologies around</description>
	<lastBuildDate>Tue, 27 Jul 2010 19:58:17 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>SqlAlchemy 0.6 and SqlAlchemy model generator</title>
		<link>http://www.python-blog.com/2010/04/22/sqlalchemy-0-6-and-sqlalchemy-model-generator/</link>
		<comments>http://www.python-blog.com/2010/04/22/sqlalchemy-0-6-and-sqlalchemy-model-generator/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 22:32:19 +0000</pubDate>
		<dc:creator>Marcin Kuźmiński</dc:creator>
				<category><![CDATA[SqlAlchemy]]></category>
		<category><![CDATA[c-extensions]]></category>
		<category><![CDATA[sqlalchemy 0.6]]></category>
		<category><![CDATA[sqlalchemy model generator]]></category>

		<guid isPermaLink="false">http://www.python-blog.com/?p=289</guid>
		<description><![CDATA[Few days ago there&#8217;s been a mayor release of SqlAlchemy.
There are a lot of bugfixes new features in tis release, but four things
are worth mentioning in this major release. ]]></description>
			<content:encoded><![CDATA[<p>Few days ago there&#8217;s been a mayor release of SqlAlchemy.<br />
There are a lot of bugfixes new features in tis release, but four things<br />
are worth mentioning in this major release. <a href="http://www.sqlalchemy.org/trac/wiki/06Migration/>See here for all changes</a></p>
<p>- C Extensions for Result Fetching according to creators will give extra 20% performance to the 30% already gained due to in-python enhancements<br />
( but you have to compile it yourself)</p>
<pre>python setup.py --with-cextensions install</pre>
<p>- Implemented well known and proven <a href="http://beaker.groovie.org/">Beaker</a> caching for Query.<br />
- RETURNING Support on insert, update and delete &#8211; might come in very handy.<br />
- Pickable query result. Means sqlAlchemy objects could be kept in sessions (did not check that)</p>
<p>After some checks i decided to move my projects to the new version, since i did that i needed to<br />
update my <a href="http://bitbucket.org/marcinkuzminski/sqlalchemy_model_generator/">model generator for SqlAlchemy</a> it&#8217;s been rewritten for sqlalchemy 0.6<br />
and now works with 0.5 and 0.6 versions. Additionally i made some small fixes i found. Any feedback is welcomed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.python-blog.com/2010/04/22/sqlalchemy-0-6-and-sqlalchemy-model-generator/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sqlalchemy model generator on bitbucket</title>
		<link>http://www.python-blog.com/2010/02/09/sqlalchemy-model-generator-on-bitbucket/</link>
		<comments>http://www.python-blog.com/2010/02/09/sqlalchemy-model-generator-on-bitbucket/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 09:00:41 +0000</pubDate>
		<dc:creator>Marcin Kuźmiński</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[SqlAlchemy]]></category>
		<category><![CDATA[bitbucket]]></category>
		<category><![CDATA[model generator]]></category>

		<guid isPermaLink="false">http://www.python-blog.com/?p=244</guid>
		<description><![CDATA[I&#8217;m in a way of releasing few of my projects to bitbucket.
Starting now I&#8217;m releasing the Sqlalchemy model generator. A quick reminder, it&#8217;s a project that you
can generate models based on your database. So you don&#8217;t need to write models by yourself.
You can see the project here: http://bitbucket.org/marcinkuzminski/sqlalchemy_model_generator/
Any participants are welcomed.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m in a way of releasing few of my projects to bitbucket.<br />
Starting now I&#8217;m releasing the Sqlalchemy model generator. A quick reminder, it&#8217;s a project that you<br />
can generate models based on your database. So you don&#8217;t need to write models by yourself.<br />
You can see the project here: http://bitbucket.org/marcinkuzminski/sqlalchemy_model_generator/<br />
Any participants are welcomed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.python-blog.com/2010/02/09/sqlalchemy-model-generator-on-bitbucket/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLAlchemy: give me my Session object!</title>
		<link>http://www.python-blog.com/2009/10/21/sqlalchemy-give-me-my-session-object/</link>
		<comments>http://www.python-blog.com/2009/10/21/sqlalchemy-give-me-my-session-object/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 09:34:44 +0000</pubDate>
		<dc:creator>Łukasz Balcerzak</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[integer]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[python blog]]></category>
		<category><![CDATA[SqlAlchemy]]></category>

		<guid isPermaLink="false">http://www.python-blog.com/?p=197</guid>
		<description><![CDATA[While I love many things about SQLAlchemy this was something I just missed sooooo much &#8211; defining model&#8217;s methods without having to pass session object.
While using Django ORM for such action it is extra easy as there is no session objects at all (well, there is connection object but it&#8217;s much simpler and less sophisticated).
Assume [...]]]></description>
			<content:encoded><![CDATA[<p>While I love many things about SQLAlchemy this was something I just missed sooooo much &#8211; defining model&#8217;s methods without having to pass session object.<br />
While using Django ORM for such action it is extra easy as there is no session objects at all (well, there is connection object but it&#8217;s much simpler and less sophisticated).<br />
Assume you have BlogEntry and BlogComment mappers and you want to define function at entry model which returns related comments &#8211; I know, it is as simple as it could be, but it&#8217;s only an example.</p>
<pre class="brush:python">
class BlogEntry(Base):
    __tablename__ = 'blog_entry'

    title = Column(String)
    content = Column(Text)
    created_at = Column(DateTime, default=datetime.datetime.now)

    def __repr__(self):
        return self.title

class BlogComment(Base):
    __tablename__ = 'blog_comment'

    content = Column(Text)
    created_at = Column(DateTime, default=datetime.datetime.now)
    entry_id = Column(Integer, ForeignKey('blog_entry.id'))
    entry = relation('BlogEntry',
        primaryjoin='BlogEntry.id==BlogComment.entry_id',
        backref='comment_set')
</pre>
<p>You now can of course get comments using comment_set attribute on blog entry. But sometimes we want start querying for other objects, for some reasons.<br />
With Django ORM, no problem, just define method on the model and start querying &#8211; it just works. With SQLAlchemy on the other hand we need to create query<br />
using Session object. But how does mapper use proper session if you call &#8216;comment_set&#8217;? Well, I&#8217;ve found the answer here: http://www.sqlalchemy.org/docs/05/reference/orm/sessions.html . There is &#8216;Session.object_session&#8217; class method which returns session object binded to an model object.</p>
<p>So now we can simply define method for BlogComment:</p>
<pre class="brush:python">
    def get_related_comments(self):
        session = Session.object_session(self)
        comment_list = session.query(BlogComment)\
            .filter(BlogComment.entry_id==BlogEntry.id)\
            .all()
        return comment_list
</pre>
<p>Just remember that object which is passed to &#8216;Session.object_session&#8217; method has to be binded with some session first.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.python-blog.com/2009/10/21/sqlalchemy-give-me-my-session-object/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sql alchemy model generator</title>
		<link>http://www.python-blog.com/2009/09/26/sql-alchemy-model-generator/</link>
		<comments>http://www.python-blog.com/2009/09/26/sql-alchemy-model-generator/#comments</comments>
		<pubDate>Sat, 26 Sep 2009 10:53:28 +0000</pubDate>
		<dc:creator>Marcin Kuźmiński</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Pylons]]></category>
		<category><![CDATA[SqlAlchemy]]></category>
		<category><![CDATA[autoload]]></category>
		<category><![CDATA[django-alchemy]]></category>
		<category><![CDATA[generator]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[model]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[python blog]]></category>
		<category><![CDATA[sql alchemy]]></category>

		<guid isPermaLink="false">http://www.python-blog.com/?p=134</guid>
		<description><![CDATA[Recently i had to create a lot of models using declarative mode with sqlalchemy 0.5.5 It was very time consuming especially for large databases. I started to think about an automated solution.
Sqlalchemy have this auto load feature which fetches info about tables by itself. I wanted to use this somehow to generate a string which [...]]]></description>
			<content:encoded><![CDATA[<p>Recently i had to create a lot of models using declarative mode with sqlalchemy 0.5.5 It was very time consuming especially for large databases. I started to think about an automated solution.</p>
<p>Sqlalchemy have this auto load feature which fetches info about tables by itself. I wanted to use this somehow to generate a string which can be easily  copy/paste to database model definition script. So i started a little project to write auto  model generator for sql alchemy based on auto load feature in sqlalchemy.</p>
<p>The script  is not perfect but it works and save a huge amount of time just codding the models. In fact is was able to setup a 186 table database model in 15minutes with this script.</p>
<p>Well the script helped me a lot and now on when i have to load some new existing database or changes i use it all the time.</p>
<p>The documentation is inside the script i tried to write it so anybody could use it out of the box.</p>
<p>I tested it on 4 schema 200+ tables database and i worked quite good. This script still have to be polished but current functionality is enough for most users.</p>
<p>My script is going to be also a part of django-alchemy project started by my friend Lukasz Balcerzak. You can visit the project site @ <a href="http://code.google.com/p/django-alchemy/">http://code.google.com/p/django-alchemy/</a></p>
<p>I used it with Pylons application and Django with modded sqlalchemy. but it can be basically used in any app which uses sqlalchemy. I did not test it with mysql though,but it should work, just specify mysql as dialect.</p>
<p><span style="font-size:130%"><strong>You can download this script from <a href="http://www.python-blog.com/wp-content/uploads/2009/09/base_model_generator.py">sqlalchemy model generator</a></strong></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.python-blog.com/2009/09/26/sql-alchemy-model-generator/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>django and sqlachemy integration</title>
		<link>http://www.python-blog.com/2009/09/05/django-and-sqlachemy-integration/</link>
		<comments>http://www.python-blog.com/2009/09/05/django-and-sqlachemy-integration/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 16:45:44 +0000</pubDate>
		<dc:creator>Marcin Kuźmiński</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[SqlAlchemy]]></category>
		<category><![CDATA[django-alchemy]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[multiple database]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[python blog]]></category>

		<guid isPermaLink="false">http://www.python-blog.com/?p=158</guid>
		<description><![CDATA[One of my friends started an interesting project to integrate sqlalchemy into Django. Project name is django-alchemy.
You can visit it on Google code under http://code.google.com/p/django-alchemy/.
You may ask why to use sqlalchemy under Django if it already have an ORM ?
It&#8217;s very easy the django orm is not always the best choice. When using multiple schemas, [...]]]></description>
			<content:encoded><![CDATA[<p>One of my friends started an interesting project to integrate sqlalchemy into Django. Project name is django-alchemy.<br />
You can visit it on Google code under <a href="http://code.google.com/p/django-alchemy/">http://code.google.com/p/django-alchemy/</a>.</p>
<p>You may ask why to use sqlalchemy under Django if it already have an ORM ?<br />
It&#8217;s very easy the django orm is not always the best choice. When using multiple schemas, or multiple database connection the Django ORM just does not provide such functionality.<br />
SqlAlchemy have this built in so when you&#8217;re thinking of using multiple schemas or databases in your django project check out his project. Highly recommended</p>
]]></content:encoded>
			<wfw:commentRss>http://www.python-blog.com/2009/09/05/django-and-sqlachemy-integration/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Django 1.1 finally released!</title>
		<link>http://www.python-blog.com/2009/07/29/django-1-1-finally-released/</link>
		<comments>http://www.python-blog.com/2009/07/29/django-1-1-finally-released/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 19:53:51 +0000</pubDate>
		<dc:creator>Łukasz Balcerzak</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[python blog]]></category>
		<category><![CDATA[SqlAlchemy]]></category>

		<guid isPermaLink="false">http://www.python-blog.com/?p=131</guid>
		<description><![CDATA[With almost 4 months late here it comes, Django 1.1. I&#8217;ve been waiting to see this at the final stage, as we use Django in our company, and I was sometimes forced to code down things that are already boundled now, like sql aggregation functionality for instance (well, in fact I just wrote a little [...]]]></description>
			<content:encoded><![CDATA[<p>With almost 4 months late here it comes, Django 1.1. I&#8217;ve been waiting to see this at the final stage, as we use Django in our company, and I was sometimes forced to code down things that are already boundled now, like sql aggregation functionality for instance (well, in fact I just wrote a little django app using full force of SQLAlchemy instead of Django ORM). Additionally, some security patch was released yesterday, which is included with 1.1 too.</p>
<p>You may read more at <a href="http://docs.djangoproject.com/en/dev/releases/1.1/">release notes</a> page . Stay tuned with Django and minor swing ;-) </p>
]]></content:encoded>
			<wfw:commentRss>http://www.python-blog.com/2009/07/29/django-1-1-finally-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python threaded</title>
		<link>http://www.python-blog.com/2009/07/01/python-threaded/</link>
		<comments>http://www.python-blog.com/2009/07/01/python-threaded/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 21:37:19 +0000</pubDate>
		<dc:creator>Łukasz Balcerzak</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Threads]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[port scan]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[python blog]]></category>
		<category><![CDATA[socket]]></category>
		<category><![CDATA[SqlAlchemy]]></category>
		<category><![CDATA[thread queue]]></category>

		<guid isPermaLink="false">http://www.python-blog.com/?p=81</guid>
		<description><![CDATA[Recently I&#8217;ve run into some optimizations problem which I once hoped I wouldn&#8217;t had to face. After some research on the subject I decided to split some process using threads. I hadn&#8217;t have much experience in that area except some classes at PJIIT (Polish-Japanese Institute of Information Technology) so start was painful&#8230; but not for [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve run into some optimizations problem which I once hoped I wouldn&#8217;t had to face. After some research on the subject I decided to split some process using threads. I hadn&#8217;t have much experience in that area except some classes at PJIIT (Polish-Japanese Institute of Information Technology) so start was painful&#8230; but not for long (as with everything in Python).</p>
<p>So I decided to share my thoughts with everyone who would ever try to use threads in Python programming.</p>
<p>Let&#8217;s imagine simple case: you want to check some host if it has opened any port from range 1-1000. We create simple script (use whatever host you like)</p>
<pre class="brush:python">
import socket
import time

def is_port_open(host, port):
    """
    Takes host param as string and port param as int.
    Returns true if port is open and false otherwise.
    """
    #print "[DEBUG] Checking host %s:%s" % (host, port)
    s = socket.socket()
    is_open = True
    try:
        s.connect( (host, port) )
    except socket.error:
        is_open = False
    s.close()
    return is_open

def main():
    start = time.time()

    host = 'some.host'
    ports = range(1,1000) 

    print "[INFO] Will now check host %s for ports between %s and %s" % \
        (host, ports[0], ports[-1]) 

    for port in ports:
        if is_port_open(host, port):
            print "[INFO] Port %s on host %s is open." % (port, host)

    print "Elapsed Time: %s" % (time.time() - start)

if __name__ == '__main__':
    main()
</pre>
<p>How long was it? Well, try this then:</p>
<pre class="brush:python">
import threading
import socket
import time
import Queue

THREAD_NUMBER = 20

def is_port_open(host, port):
    """
    Takes host param as string and port param as int.
    Returns true if port is open and false otherwise.
    """
    #print "[DEBUG] Checking host %s:%s" % (host, port)
    s = socket.socket()
    is_open = True
    try:
        s.connect( (host, port) )
    except socket.error:
        is_open = False
    s.close()
    return is_open

class PortChecker(threading.Thread):
    def __init__(self, queue):
        threading.Thread.__init__(self)
        self.queue = queue

    def run(self):
        while True:
            host, port = self.queue.get()
            if is_port_open(host, port):
                print "[INFO] Port %s on host %s is open." % (port, host)
            self.queue.task_done()

def main():
    start = time.time()

    host = 'some.host'
    ports = range(1,1000)
    queue = Queue.Queue()

    for i in xrange(THREAD_NUMBER):
        pc = PortChecker(queue)
        pc.setDaemon(True)
        pc.start()

    print "[INFO] Will now check host %s for ports between %s and %s" % \
        (host, ports[0], ports[-1]) 

    for port in ports:
        queue.put( (host, port) )

    queue.join()
    print "Elapsed Time: %s" % (time.time() - start)

if __name__ == '__main__':
    main()
</pre>
<p>Try with different port range/thread number. Ok, this is just an example. But it should give you an idea how to handle with some process that is done inside a loop. You have to define your &#8220;handler&#8221; (thread that will process on some object(s)), create empy queue and fill it with objects. Try to use only 1 thread (set THREAD_NUMBER to 1) and look at the time it took to finish whole process.</p>
<p>I know that programmer&#8217;s time is much more expensive than processor&#8217;s time and I try not to break this rule. But sometimes (i.e. when your script runs for over 12 hours) it is very nice if you can cut the time you can generate results. Just remember to catch exceptions inside threads &#8211; it is very important as if exception is risen by thread, it will just die without any notification.</p>
<p>Well, thats it. I will proceed tomorrow with some example with SQLAlchemy. Good night folks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.python-blog.com/2009/07/01/python-threaded/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
