Skip to main content

Postgresql shortcuts

Project description

# pgdata

Python PostgreSQL-PostGIS-SQLAlchemy shortcuts.

[![Build Status](https://travis-ci.org/smnorris/pgdata.svg?branch=master)](https://travis-ci.org/smnorris/pgdata) [![Coverage Status](https://coveralls.io/repos/github/smnorris/pgdata/badge.svg?branch=master)](https://coveralls.io/github/smnorris/pgdata?branch=master)

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](https://dataset.readthedocs.io/en/latest/))

    >>> import pgdata
    >>> db = pgdata.connect()
    >>> db.tables
    ['inventory']
    >>> 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',
                  out_layer='airports_a',
                  schema='airport_project')
    >>> db.execute('do stuff')
    >>> db.pg2ogr('SELECT * FROM airports_project.result','GPKG', 'output.gpkg')
    

Much is copied directly from [dataset](https://dataset.readthedocs.org/) and further inspiration was taken from [pgwrap](https://github.com/paulchakravarti/pgwrap). See also [records](https://github.com/kennethreitz/records) and many others.

## Requirements

## Installation

` pip install pgdata `

## Configuration

Create an environment variable DATABASE_URL and set it to the [SQLAlchemy db url](http://docs.sqlalchemy.org/en/latest/core/engines.html) for your database:

MacOS/Linux etc:

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

Windows:

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