Skip to main content

Tool to build postgres databases for development and testing.

Project description


A small, self contained python library for building postgres database locally that, on first run will:

  • Downloads and compiles a specified version of postgres.

  • Builds a database from a series of SQL commands and by restoring a database dump file.

  • Takes a snapshot of the newly built database files by taking a copy of the folder.

On subsequent builds, it will skip the long, expensive steps of downloading, compiling postgres and restoring a database from a .sql file and just overwrite the data files.

import hitchbuildpg

postgres_version = "10.10"
pgapp_dir = "{}/postgres-{}".format(share, postgres_version)

pgapp = hitchbuildpg.PostgresApp(pgapp_dir, postgres_version)

class DataBuild(hitchbuildpg.DataBuild):
    def run(self):
        self.run_sql_as_root("create user myuser with password 'mypassword';")
        self.run_sql_as_root("create database mydb with owner myuser;")

pgdata = hitchbuildpg.PostgresDatafiles(


db_service = pgdata.server()

psql = db_service.psql(
    "-U", "myuser", "-p", "15432", "-d", "mydb",

psql("-c", "select name from cities where location = 'GB';").run()

# Prints output of SQL statement
psql("-c", "delete from cities where location = 'GB';").run()

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 hitchbuildpg, version 0.4.1
Filename, size File type Python version Upload date Hashes
Filename, size hitchbuildpg-0.4.1.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page