Skip to main content

Postgresql shortcuts

Project description

# pgdata

Python PostgreSQL-PostGIS-SQLAlchemy shortcuts.

[![Build Status](]( [![Coverage Status](](

pgdata is a collection of convenience functions for working with PostgreSQL:

  • provides an dictionary/JSON-like shortcut interface to database objects without dealing directly with an ORM or cursor (see [dataset](

    >>> import pgdata
    >>> db = pgdata.connect()
    >>> db.tables
    >>> db["inventory"].columns
    ['type', 'supplier', 'cost']
  • provides a shortcut to ogr2ogr for quickly getting geographic data in and out of your database with sensible defaults and without resorting to shell scripting

    >>> import pgdata
    >>> db = pgdata.connect()
    >>> db.ogr2pg('airports.shp',
    >>> db.execute('do stuff')
    >>> db.pg2ogr('SELECT * FROM airports_project.result','GPKG', 'output.gpkg')

Much is copied directly from [dataset]( and further inspiration was taken from [pgwrap]( See also [records]( and many others.

## Requirements

## Installation

` pip install pgdata `

## Configuration

Create an environment variable DATABASE_URL and set it to the [SQLAlchemy db url]( for your database:

MacOS/Linux etc:

export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/mydb


SET DATABASE_URL=”postgresql://postgres:postgres@localhost:5432/mydb”

## Usage

` >>> import pgdata >>> db = pgdata.connect(schema='myschema') >>> db.tables ['inventory'] >>> db["inventory"].columns ['type', 'supplier', 'cost'] >>> data = db.query("SELECT * FROM inventory WHERE type = %s", ('spam',)).fetchall() >>> for row in data: >>>     print (row['type'], row['supplier'], row['cost']) ('spam', 'spamcorp', 100) >>> for row in db["inventory"].find(type='spam'): >>>     print (row['type'], row['supplier'], row['cost']) ('spam', 'spamcorp', 100) `

Project details

Download files

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

Files for pgdata, version 0.0.12
Filename, size File type Python version Upload date Hashes
Filename, size pgdata-0.0.12-py3-none-any.whl (14.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size pgdata-0.0.12.tar.gz (57.1 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page