开发者

New project Python 3x PostgreSQL 9x and pg8000 1x DBAPI?

I'm starting some new projects and want to know if pg8000 is considered a good choice for a production project?

Obviously Python and PostgreSQL are mature products, but I'm concerned about pg8000 both when it comes to maturity and performance. Will my DB acc开发者_运维问答ess suffer or will it be acceptable?

So, please take some latitude in responding to my question. Is pg8000 ready? Will I have problems using the Python DBAPI 2.0 spec for complete access when writing a db centric program?

I know questions like this get asked all the time, but I did look and could not find anything current relating to pg8000. And obviously any answer beyond a few months would not be current considering the releases that have been committed on the related technologies.


I think your should try to make your program driver "independent". It should work with any PostgreSQL DBAPI 2.0 driver. The only difference will be at import section and at establishing a db connection. This can look like:

use_pgdb = 0
try:
    import pgdb
    use_pgdb = 1
except:
    try:
        import psycopg2
    except:
        raise exceptions.ImportError('No PostgreSQL library, install psycopg2 or PyGres!')
if use_pgdb:
    _CONN = pgdb.connect(connect_string)
else:
    _CONN = psycopg2.connect(dsn)

Add to this "chain" of drivers pg8000 and simply try it. If all drivers will work and performance will be good then leave those drivers. If one of the drivers will not work, or will have poor performance then comment it in your code and disable it. For more than 2 drivers I would change code from example and create some kind of dictionary with driver and connect function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜