Having just spent about 20 minutes trying to get started with PyGreSQL I thought I’d share a quick tutorial at least so I’ll be able to reference this later. Their documentation is wildly lacking, mostly only composed of a tutorial for a different database and class/function references. Open source project contributors, make sure you have a nice and easy getting started tutorial! Anyway, here we go. PyGreSQL comes with two APIs: pg and pgdb. The former is a “traditional” API, and the latter is DB-API, a standard for database APIs. Below is a tutorial for pg:
c = pg.connect("database_name", "host", 5432, "opt", "tty", "user", "password") r = c.query("select * from foo") print r.dictresult()
Note that opt, tty, and password can be None depending on your postgres authentication scheme. See the complete pg documentation for more info. I’ll update this further as I explore more.