Skip to content

nad2000/pg8000

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PG8000

PG8000 is a pure-Python PostgreSQL driver that complies with DB-API 2.0. The driver communicates with the database using the PostgreSQL Backend / Frontend Protocol. The supported Python versions are:

  • CPython 2.5
  • CPython 2.6
  • CPython 2.7
  • CPython 3.2
  • CPython 3.3
  • PyPy
  • Jython 2.5

Usage

>>> import pg8000
>>> conn = pg8000.DBAPI.connect(user='postgres', password='password')

The connect function takes the following parameters:

parameter default
user
host localhost
unix_sock
port 5432
database
password
socket_timeout60
ssl False
>>> pg8000.DBAPI.paramstyle = 'numeric'
>>> cur = conn.cursor()
>>> cur.execute("create temporary table example (id int, name varchar)")
>>> cur.execute("insert into example values (1, 'hello')")
>>> conn.commit()
>>> cur.execute("select * from example where id = :1", (1,))
>>> for row in cur:
...     print(row)
[1, 'hello']
>>> cur.close()
>>> conn.commit()

Following the DB-API specification, autocommit is off by default. It can be turned on by using the autocommit property of the connection.

>>> conn.autocommit = True
>>> cur = conn.cursor()
>>> cur.execute("vacuum")
>>> conn.autocommit = False

Regression Tests

To run the regression tests, install tox:

pip install tox

then add install all the supported Python versions, and add a line to pg_hba.conf requiring md5 for the database pg8000_md5, eg.

host    pg8000_md5      all             127.0.0.1/32            md5

and run tox from the pg8000 directory:

tox

Performance Tests

To run the performance tests from the pg8000 directory:

python -m pg8000.tests.performance

About

A Pure-Python PostgreSQL Driver

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%