python-pgbouncer is a programmatic control for setting up pgbouncer from Python.
python-pgbouncer provides a context manager which will run (and tear down afterwards) a pgbouncer instance. This can be very useful for testing without depending on the host having pgbouncer setup and running.
For discussion about this please use the Launchpad developers mailing list (https://launchpad.net/~launchpad-dev - join the team to subscribe to the list).
Create a PGBouncerFixture - a context manager with an extended protocol supporting access to logs etc. Customise it with database definitions, user credentials, and then when you enter the context it will create a transient pgbouncer setup in a temporary directory and run it for the duration that the context is open.
>>> from pgbouncer import PGBouncerFixture
>>> bouncer = PGBouncerFixture()
>>> bouncer.databases['mydb'] = 'host=hostname dbname=foo'
>>> bouncer.users['user1'] = 'credentials'
>>> with bouncer:
... # Can now connect to bouncer.host port=bouncer.port user=user1
Any settings required for pgbouncer to work will be given sane defaults.
Either run setup.py in an environment with all the dependencies available, or add the working directory to your PYTHONPATH.
Upstream development takes place at https://launchpad.net/python-pgbouncer. To setup a working area for development, if the dependencies are not immediately available, you can use ./bootstrap.py to create bin/buildout, then bin/py to get a python interpreter with the dependencies available.