Skip site navigation (1) Skip section navigation (2)

Re: RFC: Extend psycopg2.connect to accept all valid parameters?

From: Jan Urbański <wulczer(at)wulczer(dot)org>
To: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
Cc: Fabian Knittel <fabian(dot)knittel(at)avona(dot)com>, psycopg(at)postgresql(dot)org
Subject: Re: RFC: Extend psycopg2.connect to accept all valid parameters?
Date: 2011-11-17 07:48:16
Message-ID: 4EC4BC40.3050903@wulczer.org (view raw or flat)
Thread:
Lists: psycopg
On 17/11/11 03:02, Daniele Varrazzo wrote:
> On Wed, Nov 16, 2011 at 10:23 PM, Daniele Varrazzo
> <daniele(dot)varrazzo(at)gmail(dot)com>  wrote:
> I've implemented what discussed here and pushed in a separate branch:
> https://github.com/dvarrazzo/psycopg/commit/d2b67364fd2b0b192342281d24a7e3d0a4909980
>
> It's open for discussion. It is not as tested as the rest of the
> library, as there aren't many tests covering connect() in all the
> possible ways (as there should be as many databases on the other side
> to reply).

I think the correct solution would be to document the 'dsn' parameter to 
psycopg2.connect and perhaps even encourage people using it.

This pushes the trouble of parsing out and interpreting parameters to 
libpq, which is good, for in the end the important thing is that libpq 
sees what you want it to see.

For instance, this patch (and AFAICS vanilla psycopg2 too) does not 
handle usernames with spaces in them. Instead of implementing quoting as 
expected by libpq, why not just let the user use a DSN that will work 
equally with psql as with any other libpq app out there?

As for SQLAlchemy, you can use the connect_args argument to pass a DSN 
to create_engine thusly:

e = create_engine('postgresql://', connect_args={'dsn': 'user=foo 
sslrootcert=root.crt'})

Cheers,
Jan

In response to

Responses

psycopg by date

Next:From: Federico Di GregorioDate: 2011-11-17 08:31:46
Subject: Re: RFC: Extend psycopg2.connect to accept all valid parameters?
Previous:From: Daniele VarrazzoDate: 2011-11-17 02:02:14
Subject: Re: RFC: Extend psycopg2.connect to accept all valid parameters?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group