Skip to main content
Warning: You are using the test version of PyPI. This is a pre-production deployment of Warehouse. Changes made here affect the production instance of TestPyPI (
Help us improve Python packaging - Donate today!

Thin wrapper around psycopg2 to provide helpers for Postgresql

Project Description

Psychopath is a thin wrapper around psycopg2 to provide helpers for Postgresql.


  • Parse automatically the environment variable DATABASE_URL
  • Helpers to simplify SQL statement writing
  • SQL statement builders
  • Basic schema migration tool


  • Python >= 3.4
  • psycopg2 >= 2.7
  • Postgresql 9.x


pip install psychopath

Running tests

pip install tox


Initialize a new connection pool:

from psychopath import db

db.init('postgres://postgres:postgres@localhost/psychopath_tests', maximum_connections=10)

You could also use an environment variable DATABASE_URL to configure automatically the connection.


Execute a SQL statement:

from psychopath import db'CREATE TABLE foobar (id serial PRIMARY KEY, value text)')

Get table records as namedtuple:

from psychopath import db

records = db.find_all('SELECT * FROM foobar ORDER BY id DESC')

for record in records:

Get only one record:

from psychopath import db

record = db.find_one('SELECT * FROM foobar')

Get first column value:

from psychopath import db

print(db.first('SELECT value FROM foobar'))

Get numeric value:

from psychopath import db

print(db.count('SELECT count(*) FROM foobar'))

Insert a new record:

from psychopath import db'INSERT INTO integration_test (value) VALUES (%s)', ['something']) is a wrapper around psycopg2 cursors.


from psychopath import db

with db.transaction() as t:
    t.execute('CREATE TABLE test_create_table (value text)')
    t.execute('DROP TABLE test_create_table')


Frédéric Guillot


Psychopath is distributed under Apache 2.0 LICENSE.

Release History

Release History

This version
History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
psychopath-0.0.1.dev2.tar.gz (5.3 kB) Copy SHA256 Checksum SHA256 Source May 14, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting