Mathieu Fenniak’s Weblog

viagra generic canada
viagra cheap generic
viagra softabs
real viagra woman
viagra cialis canadian pharmacy
generic viagra tab
sales online viagra
online medications viagra
viagra cost in canada
viagra 50 mg
order viagra or levitra
viagra argentina
viagra online pharamcy
viagra cheap sale
viagra 100mg dosage
viagra generic on line
order viagra cialis levitra pharmacy
order viagra without prescription
sale viagra
online perscriptions for viagra
viagra generic soft tabs 100mg
sales uk viagra
viagra cost
viagra cialis store
online viagra for sale
low cost viagra
where to buy viagra in london
viagra cheap online rx
get viagra now internet
online pharmacy prescription drug viagra
viagra price uk
viagra prescriptions uk
viagra buy general
viagra uk without prescription
where can i purchase viagra
viagra buy it
viagra to buy
viagra best prices
order cialis and viagra
viagra in usa
order prescription viagra without
viagra cheapest uk
where to purchase viagra
viagra on internet prescription online
viagra get prescription online
get viagra in canada
viagra price online
viagra online without prescription
order viagra prescription
viagra soft tabs low cialis
viagra buy australia
purchase viagra without prescription
online cheap viagra
purchasing viagra australia
viagra without perscription
lowest price on viagra
viagra cheapest price
no online pharmacy prescription required viagra
viagra canada prescription
viagra on line no prescripton
generic viagra solf tabs
purchase viagra soft tabs
purchasing viagra in venezuela
viagra by mail canada
online store viagra
no prescription order viagra online
viagra buying online
viagra generic discount
viagra on line sales
viagra genetic
us discount viagra
on line generic viagra for sale
online order viagra
viagra united states
viagra usa mastercard
online viagra prescription canada
viagra online
viagra cialis canada
viagra cialis online
viagra cialis online pharmacy satisfaction guaranteed
ordering generic viagra in canada
viagra online rx
generic viagra rx
viagra canada generic
non prescription viagra
where to get viagra
viagra in the uk
mail order viagra online
where to buy viagra uk
viagra in mexico
viagra online no rx
online pill viagra
get viagra drug online
viagra cheapest prices
viagra on line purchase
online uk viagra sales
uk viagra on line
viagra cheap prescription
online viagra canada
get viagra without prescription
viagra uk cheap
viagra prices in usa
viagra cost uk
viagra best buy
viagra 100mg
viagra on the internet
online ordering viagra
low price for viagra
order viagra here
generic viagra uk
viagra cialis buy no prescription
viagra prescription order
no prescription viagra
uk viagra sales online
viagra discount sales
order viagra without a prescription
purchase cheap viagra online
purchase viagra professional
viagra cheap
generic viagra pills
purchase viagra by check
viagra 100mg tablets
uk viagra online
online viagra pharmacy
viagra pharmacy sales london
on line pharmacy for viagra
viagra canadian price shipped
viagra on line order
generic viagra without visa
viagra in uk
order mexican viagra
online viagra no generic
mail order viagra in uk
viagra pharmacy online
viagra in britain
where can i buy viagra in
viagra to order
order viagra now viagra money order
order 50mg viagra
no rx viagra
viagra no presrciption
lowest viagra prices
viagra to buy in uk
viagra 50mg
viagra cheapest
viagra buy in uk online
lowest price generic viagra
viagra online no doctor prescription
order viagra online no rx prescription
viagra cost best price viagra
viagra purchase
viagra generico impotencia
purchasing viagra in mexico
viagra prescriptions online
order generic viagra online
viagra canada
where can i get viagra
sales of viagra
viagra cheap uk
viagra buy generic
getting viagra in the philippines
mail order viagra uk
viagra online ordering
order viagra overnight delivery
generic viagra softabs
online viagra
sale online viagra
viagra with out prescription
viagra in australia
order viagra online
real viagra online for americans
us drugs store cheap viagra
viagra without prescription new york
generic viagra with money order
viagra pills online
viagra no prior prescription
where to buy viagra
mail uk viagra
lowest priced viagra in britain
viagra cialis online pharmacy
viagra 100 50 25
non prescription viagra in uk
viagra online shop
viagra canida
viagra generic uk
online viagra order
uk viagra kamagra
get viagra without a prescription
order generic viagra
viagra by mail
generic viagra soft pharmacy online
pharmacy purchase viagra
viagra without prescription
viagra american express canada
lowest cost of viagra
viagra best price generic
viagra online canada
lowest cost viagra
viagra cost per pill
generic viagra sale
viagra uk retail price
viagra online pharmacies
generic viagra us licensed online pharmacy
generic viagra us pharmacy
on viagra
viagra 25mg
viagra prescriptions on line
viagra canada satisfaction guarantee
viagra without presciption online
uk viagra prices
viagra prescription uk
online shop viagra
sales viagra
get viagra
viagra online store
ordering viagra
get viagra now no doctor visit
where to buy viagra online
order viagra canada
uk viagra sales
viagra germany
viagra cost australia
viagra by the pill
get viagra online
where do i buy viagra online
purchase viagra in uk
viagra on prescription
generic viagra propecia
viagra to buy uk
viagra online discount
viagra best price
where to buy viagra from
generic viagra sales
non perscription viagra
no perscription viagra
on line pharmacy viagra
viagra without precription
online viagra sales
viagra cheap buy
viagra canada price
where can i buy viagra on
viagra by overnight delivery
viagra 50mg or 100mg
viagra 50mg uk
ordering viagra without prescription
get viagra prescription online
get viagra now
online viagra pills
viagra in the philippines
viagra online stores
tadalafil viagra
viagra soft tabs generic 100mg
purchasing viagra online
viagra 100
pharmacy viagra
viagra uk sales
viagra 50mg 100mg
viagra canada online
order viagra softtabs
on line generic viagra
viagra 25
no persription viagra
viagra generic cheap
where to buy viagra in nz
viagra soft tab
purchase viagra and cialis
online pharmacy viagra no prescription
viagra pill on line
online generic viagra sales
online parmacy viagra cheap
viagra on line
viagra best price sildenafil
order viagra on line
viagra cialis no prescription required
online sales viagra
no prescription cheap viagra
viagra in netherland
order discount viagra
uk cheapest viagra
viagra buy viagra
viagra purchase uk
nonprescription viagra
viagra buy oonline
viagra uk cheap purchase buy
viagra cheap no prescription
viagra best prices fda approved
viagra price australia
order viagra usa
no online order prescription viagra
viagra soft tab generic
viagra online pharmacy
viagra on line prescription
viagra discounts
viagra uk buy
viagra 50mg online
lowest price viagra online
pure theatrical viagra
where can i buy viagra online
online viagra australia
low price viagra
low priced viagra chain store
viagra purchase canada
online viagra levitra cialis
where can i purchase viagra online
ordering viagra online
viagra pills for sale
viagra buy online
purchasing viagra online for cheap
viagra cialis on line
viagra online cheap
online prescription for viagra
viagra no prescreption
lowest priced viagra in the uk
non perscription generic viagra
viagra on line canada
viagra canada online pharmacy
online pharmacy viagra
viagra generic buy
viagra canadian
viagra by money order
viagra generic buy online american express
viagra buy it online now
viagra prices uk
lowest price for viagra online
viagra generic cialis
where can i buy viagra uk
viagra non prescription
viagra online fda
viagra pills cheap
purchasing viagra
online free sample viagra canada
viagra without a prescription
viagra on lilne
low priced viagra
viagra cheap canada
purchase generic viagra uk
order viagra now money
viagra online purchase
non prescription viagra online
viagra pill uk
viagra pills uk
viagra price canada
viagra pills without a prescription
viagra to buy online
on line viagra american pharmacy
purchase viagra on line
viagra online shop uk
viagra online in canada
viagra pharmacy online sale
where buy viagra
online uk viagra
purchase viagra uk
generic viagra purchase
online buy viagra
viagra cheap mexico
sales online viagra sale
viagra uk online
lowest viagra price
viagra buy
viagra online without rx
viagra cialis generic
lowest cost generic viagra
viagra online prescriptions
viagra in ontario
online pharmacy uk viagra
viagra online shop online approval
online check payment viagra
viagra no prescription needed
viagra usa
viagra online prescription
order viagra overnight shipping
uk viagra
where can i order generic viagra
viagra generico mexico
lowest prices viagra
low cost viagra online
on line prescription viagra
online generic viagra
online viagra sale
real viagra
viagra without a perscription
mail order for viagra tablets
viagra 50
where can i buy viagra
no online prescription viagra
get viagra dont visit a doctor
generic viagra softtabs
order viagra viagra online
order viagra
viagra costs australia
generic viagra soft tabs
viagra to florida
online purchase viagra
viagra soft tablets
where to buy viagra on line
uk generic viagra
viagra on-line
online viagra uk
purchase viagra online
viagra best buy diet pills
viagra online uk no generic
online viagra prescriptions
tadalafil cialis vs viagra
lowest prices viagra uk
uk pharmacies cheap viagra
viagra generic cheap discounted cheapest online
viagra purchases
viagra online uk
low cost generic viagra
online viagra prescription
viagra no prescripsion
order viagra viagra
viagra online from us pharmacys
viagra best quality lowest prices
viagra cost per pill in mexico
generic viagra with american express
online order prescription viagra
on line viagra
generic viagra woman
viagra purchase online
viagra on line uk
viagra onlin
mail order viagra
where can i buy viagra from
viagra 50 mg or 100mg
online pharmacy prescription viagra
mail order viagra without prescription
lowest prices on generic viagra
viagra online no prescription
generic viagra usa
viagra amsterdam
viagra cialis online sales
order viagra cheap
viagra canadian prescriptions
tadalafil generic viagra
get discount viagra online
us viagra cheap
where do i buy viagra in
viagra u s pharmacies
viagra buy now pay later
viagra generic mastercard precription
viagra discount sale
order viagra licensed pharmacies online
viagra canadaian prices
viagra online in united states
uk viagra london
viagra no prescription canada
viagra in spain
non-prescription viagra
viagra prescription onlin
viagra online sales
online prescription viagra without
order viagra online uk
purchase generic viagra
viagra uk sale
viagra buying
viagra discount
viagra online canadiain
viagra 100 mg
get viagra on internet
lowest price viagra
low priced purchase viagra
viagra best prices fda approved online
online pharmacy viagra cialis
viagra discount online
purchase viagra in australia
order viagra on-line
order uk viagra
viagra purchase on line
viagra soft tablet
order viagra uk
viagra prescription online
viagra without prescription canada
viagra buy viagra online
viagra cheap usa
online viagra store
viagra 100mg 90 pills
where to get viagra samples
viagra in canada
where to buy viagra in uk
generic viagra sale on line
viagra softtabs
viagra generic buy american express
online pharmacy propecia viagra
viagra cialis cheap
online sale viagra
get online viagra
viagra cheap online
viagra no prescription
viagra onlines
viagra no presciption
pharmacy online viagra
mail order generic viagra
viagra 50mg soft tab generic
sale uk viagra
lowest price viagra in the uk
generic viagra online pharmacy
viagra american express
where can i get free viagra
viagra without a prescriotion
no perscription generic viagra
viagra online buy
on-line viagra
viagra cialis prescription online
viagra philippines
viagra on sale
viagra online shop in uk
order prescription viagra
viagra uk delivery
purchase generic viagra online
viagra by mail order
viagra buy uk
viagra generic drug
viagra uk purchase
purchase of viagra
viagra canada pharmacy
viagra online uk delivery
us viagra
viagra online order
generic viagra uk online pharmacy
viagra generic sildenafil
order cheap viagra
viagra purchase in united states
get viagra online guarantee
generic viagra tadalafil
order viagra onlines
nonperscription viagra
order viagra with mastercard
mail online order viagra
generic viagra pill
viagra discount store
generic viagra soft tab
viagra onliine
online phamacy viagra
viagra soft tabs
viagra on line pharmacy
online prescription viagra
purchase viagra
viagra uk
viagra generico
order viagra now

pg8000 v1.00 — a new PostgreSQL/Python interface

Filed under: programming, python, postgresql — Mathieu Fenniak @ March 9, 2007 10:24 am

pg8000 is a Pure-Python interface to the PostgreSQL database engine. Yesterday, it was released to the public for the first time.

pg8000’s name comes from the belief that it is probably about the 8000th PostgreSQL interface for Python. However, pg8000 is somewhat distinctive in that it is written entirely in Python and does not rely on any external libraries (such as a compiled python module, or PostgreSQL’s libpq library). As such, it is quite small and easy to deploy. It is suitable for distribution where one might not have a compiled libpq available, and it is a great alternative to supplying one with your package.

Why use pg8000?

  • No external dependencies other than Python’s standard library.
  • Pretty cool to hack on, since it is 100% Python with no C involved.
  • Being entirely written in Python means it should work with Jython, PyPy, or IronPython without too much difficulty.
  • libpq reads the entire result set into memory immediately following a query. pg8000 uses cursors to read chunks of rows into memory, attempting to find a balance between speed and memory usage for large datasets. You could accomplish this yourself using libpq by declaring cursors and then executing them to read rows, but this has two disadvantages:
    • You have to do it yourself.
    • You have to know when your query returns rows, because you can’t DECLARE CURSOR on an INSERT, UPDATE, DELETE, CREATE, ALTER, ect.
  • pg8000 offers objects to represent prepared statements. This makes them easy to use, which should increase their usage and improve your application’s performance.
  • It has some pretty nice documentation, I think.

Now, that being said, reality kicks in. Here’s why not to use pg8000:

  • It’s pretty new. This means there are likely bugs that haven’t been found yet. It will mature over the next couple weeks with some community feedback and some internal testing.
  • It doesn’t support the DB-API interface. I didn’t want to limit myself to DB-API, so I created just a slightly different interface that made more sense to me. I intend to include a DB-API wrapper in the next release, v1.01.
  • It isn’t thread-safe. When a sequence of messages needs to be sent to the PG backend, it often needs to occur in a given order. The next release, v1.01, will address this by protecting critical areas of the code.
  • It doesn’t support every PostgreSQL type, or even the majority of them. Notably lacking are: parameter send for float, datetime, decimal, interval; data receive for interval. This will just be a matter of time as well, and hopefully some user patches to add more functions. For the case of interval, I expect to optionally link in mxDateTime, but have a reasonable fallback if it is not available.
  • It doesn’t support UNIX sockets for connection to the PostgreSQL backend. I just don’t quite know how to reliably find the socket location. It seems that information is compiled into libpq. Support could be added very easily if it was just assumed that the socket location was provided by the user.
  • It only supports authentication to the PG backend via trust, ident, or md5 hashed password.

pg8000’s website is http://pybrary.net/pg8000/. The source code is directly accessible through SVN at http://svn.pybrary.net/pg8000/.

20 Comments

  1. How much of a speed hit is pg8000 over, say, psycopg2? Did you consider using ctypes + libpq? (Installing the many psycopg2 dependencies can be a pita but installing just libpq has never been an obstacle in my experience.)

    Comment by Jonathan Ellis — March 9, 2007 @ 10:39 am

  2. That’s an excellent question, Jonathan. I haven’t done any benchmarking yet, but I am very interested in doing some in the next day or so. I wouldn’t be surprised if the performance was slightly slower, but I don’t think it will be significant.

    ctypes/libpq would work pretty well, but I thought there would be value in building the library using nothing but the documented network protocol for PG. I feel there are some advantages to this approach.

    Comment by Mathieu Fenniak — March 9, 2007 @ 10:51 am

  3. Initial benchmark results for some basic queries returning around 15,000 rows of data show that pg8000 is between 6% and 9% slower than psycopg2. I’m pretty happy with this. I’m sure that with some optimizations this result could be improved slightly, but without any work on “speed” it is fast enough to be competitive with other PG interfaces.

    Comment by Mathieu Fenniak — March 9, 2007 @ 12:40 pm

  4. For Unix domain sockets, requiring the user to specify the socket location is both acceptable and IMO, desirable. Also, Unix domain socket support is absolutely critical for many people (myself being one).

    Sounds like an interesting project.

    Comment by Cliff Wells — March 9, 2007 @ 4:19 pm

  5. Wow, this would be nice to have bundled with Zope.

    Comment by Dictionary Boya — March 9, 2007 @ 8:30 pm

  6. It would be cool if your DB-API layer were drop-in compatible with psycopg2 (as long as you don’t use whacky psycopg2 extensions) — e.g. using %s for bind variables and detecting the types automatically.

    (I only care because SQLAlchemy uses psycopg2, and it would be cool to have an easier-to-install driver. But not cool enough to give up SA. :)

    Comment by Jonathan Ellis — March 9, 2007 @ 9:25 pm

  7. I’m an Mono/.Net dev just learning Python, and this sounds exciting! In the .Net world I used Npgsql which was a pure .Net PostgreSQL client implementation, and it worked beautifully!

    The only problem I see is the lack of SSL support. I connect via SSL to remote PostrgeSQL servers throughout my development process.

    Once you add SSL and a DB-API wrapper, I would hope this would replace the other 7999 implementations! Its nice to have options, but I would hope projects like SQLAlchemy would choose a pure Python solution by default.

    Thanks!

    Comment by michael schurter — March 9, 2007 @ 10:14 pm

  8. You might want to run pg_config to get the socket path; this provides a user-replaceable default, because I don’t need to change pg’s default socket path. Those who do need might just change the compile-time default, which is picked up by pg_config and then by your code.

    What d’ya think?

    Comment by Luis Bruno — March 10, 2007 @ 9:05 am

  9. Cliff — UNIX domain socket support was added in a new pg8000 release, version 1.01, by providing the ‘unix_sock’ parameter to the Connection object.

    Jonathan — I’m not sure how compatible with psycopg2 it will be. It does automatically detect types (coming and going, excluding for prepared statements which are optional anyways). The %s bind variable format is not my favourite, but if I’m going to write code to rewrite a statement into PG’s variable format, I might as well include all the DB-API standard formats. It may be simpler to write a new engine for SQLAlchemy, but I’m not sure what that involves.

    Michael — Npgsql is an excellent project, and one I am happy to say I’ve used in the past as well. The Python standard library supplies enough functionality for basic SSL support, but it will not include client certificate support nor check the validity of the server certificate. So basic SSL support is very easy, but I will aim for the best SSL support eventually.

    Luis — It sounds like a good idea, but I couldn’t find the socket path in the output of my pg_config. Also, I am concerned about the DB wrapper exec’ing “pg_config” blindly and hoping it is found on the PATH. This might be a security concern if the wrong executable is run, especially if the program using pg8000 wasn’t aware it was taking this action.

    Thanks to everyone for your interest in this project! A new pg8000 release was cut last night that fixed some bugs, added some new types (woo, floats — let the good times begin), added UNIX socket support, and made the library thread-safe.

    Comment by Mathieu Fenniak — March 10, 2007 @ 10:10 am

  10. I would also like pg8000 to be a drop-in replacement for psycopg2 so it can be used with SQLalchemy. This looks like a cool project. Thanks for opening it up.

    Comment by Roberto Mello — March 10, 2007 @ 10:54 am

  11. May I suggest a more standard layout (trunk, tags, branches)?

    Anyway, congratulations for your pure python approach. To my
    understanding, in this field the java people is far far away from
    us, because they *believe* in their language. Just in the DB case,
    they have all those type 4 drivers for all mayor db vendors.
    That’s pure java!. No clients, no deployment nightmare. And this
    is even worst in the python world because creating C extensions
    for windows can be a headache (because compiler dependences).

    So I hope the best for this project (if you open the development
    or try to join the psycopg people, there will be more possibilities
    of success, but it’s your call).

    Comment by Kye — March 10, 2007 @ 12:06 pm

  12. How does this compare to bpgsql, another pure Python PostgreSQL client?
    http://barryp.org/software/bpgsql/

    Comment by Seo Sanghyeon — March 10, 2007 @ 11:34 pm

  13. Seo — I wasn’t aware of bpgsql when I began this project. A quick review shows quite a few similarities between the modules, but I prefer the approach I have taken.

    For example, bpgsql escapes strings on the client side and builds a complete command to upload to the server, whereas pg8000 uses PG bind variables to avoid having to escape the string. If both are implemented right, I don’t think there’s a practical difference between the two. I believe my approach is more conservative in letting the database server handle what has traditionally been a source of security problems in databases (SQL injection possibilities). On the other hand, creating a DB-API compliant interface that supports another parameter quoting style means that I need to rewrite the query into a new parameter style, which could be a source of obscure bugs too.

    pg8000 uses the PostgreSQL “extended query” protocol for queries, which means that prepared statements and cursors come for free. I’ve built the API to represent that, and it has allowed me to reduce memory consumption by caching a limited number of rows from the server response. I think that’s a valuable feature in the library. But it could be done with some clever middleware around any PostgreSQL library.

    There are lots of differences between the two libraries. My opinion about them is bound to be biased, as I am proud of my work. Maybe once pg8000 supports DB-API 2.0 we’ll be on even ground to compare the two.

    Comment by Mathieu Fenniak — March 11, 2007 @ 12:24 am

  14. How about using various techniques employed by pyPgSQL to get cursors working properly? I’ve been using psycopg2 and have had to patch it to have “server-side” cursors, mostly because my client balloons like an overfed python with the amounts of data I’m working with if it all gets transferred back to the client.

    Comment by Paul Boddie — March 12, 2007 @ 5:24 am

  15. Paul — pyPgSQL has always been my favourite PostgreSQL wrapper library. So, to anyone reading this, I’m not criticizing. I like the approach taken in pg8000 because it is simpler, and requires less code.

    For example, pyPgSQL compares queries against regular expressions to determine whether “DECLARE CURSOR” can use the query. This obviously works, but I believe it is inflexible. An SQL command “EXECUTE”, to run a prepared statement, would not use the cursor functionality because it doesn’t match the “SELECT” regular expression. Assuming that the regular expressions in the library are perfect, they wouldn’t be future-proof — what if new versions of PostgreSQL add some new statement that returns a result set? pg8000 would work the same as usual with the new statement.

    One of my favourite facts about pg8000 is that it uses the binary data transfer format selectively for some types. For example, floats are transmitted in binary format, which actually has impact on their value as compared to text formats. The bytea type, which isn’t implemented yet in pg8000, will not require escaping the text being sent across the wire. The timestamp type does not work well with the binary transfer format since it can sometimes be a float8, and sometimes not, so the text format is used again. Very flexible type implementation that I am happy with.

    Comment by Mathieu Fenniak — March 12, 2007 @ 8:21 am

  16. I think the PostgreSQL people really need to provide some kind of API which can say whether a statement can use cursors. It took a while for bind parameters/variables to be supported properly via the client APIs, as far as I recall, but anything of this nature is really important for anyone doing stuff outside the database. One suggestion with psycopg2 was to use “named cursors” explicitly, but that’s really inconvenient if you’re keeping an eye on portability with other database modules - I’d have to employ another layer just to hide such incompatibilities.

    I’ll keep an eye on your project, however, and hope that I can use it in preference to the other modules in the future. It’s true that pyPgSQL does some tests on statements to see if they’re likely to work with cursors, and my patch to psycopg2 does similar things. The big problem with PostgreSQL, in my opinion, is that it’s often very good technically in so many areas, only to be let down by one or two minor details which can “sour the deal”.

    Comment by Paul Boddie — March 12, 2007 @ 8:37 am

  17. Mathieu,

    This is great. Pure Python libraries are way underrated. Python’s ability to interface with C libraries is great but it’s nice to have pure Python alternatives with no dependencies.

    Comment by Joel Lawhead — March 12, 2007 @ 8:57 am

  18. I meant: use pg_config during “setup.py install”, not in “runtime”; then “hardcode” the value you find.

    I was *so* sure that pg_config provides the socket path. My experience with pg_config comes from psycopg2, which is a different use case.

    I guess I’ll have a look around.

    Comment by Luis Bruno — March 12, 2007 @ 11:32 am

  19. Speaking for myself, I don’t think binary client libraries are a “bad” dependency. OTOH, I strongly dislike having to *compile* something to access a database.

    I actually like the Windows model: Next -> Next -> Next -> Install. .oO(OT: except that now I use .msi files and a silent installation)

    Comment by Luis Bruno — March 12, 2007 @ 11:35 am

  20. […] I haven’t tried it yet, but assuming that I can make easy use ofpg8000, a PostgreSQL that throws out c-based bindings and speaking postgresql-ish in native python, then it’s an example of the anti-thesis of “dragon tea”. It doesn’t appear to require hunting down obscure dependencies, it doesn’t require that you build ten other equally obscure things before you can use it, and if it delivers what it promises it will make developer’s lives much easier. […]

    Pingback by Strictly Business » Blog Archive » Antithesis — August 3, 2007 @ 8:54 pm

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by WordPress