Skip to main content

PostgreSQL database schema design and maintenance tools

Project description

Design, create, maintain and document a PostgreSQL databases using a yaml based descriptions.

Read the documentation on


Install from PyPi:

$ pip3 install pg-db-tools

Install from GitHub:

$ git clone
$ sudo pip3 install pg-db-tools


Command usage:

db-schema <command> [options]

    compile       compile output from schema definition
    extract       extract schema definition from source
    doc           documentation generation command
    --help,-h     display help information


Sub-command compile:

db-schema compile <output-type> <schema-filename>

    dot   Generate Graphviz DOT
    sql   Generate SQL
    md    Generate Markdown documentation
    rst   Generate reStructuresText documentation


Sub-command extract:

db-schema extract <source>

    from-db   Extract from postgres database

Sub-sub-command from-db:

db-schema extract from-db --format {yaml.json} [--owner OWNER] [schemas]

schemas: * Multiple schemas can be supplied * If no schema is supplied, all schemas are returned


PGHOST=localhost \
PGPORT=5432 \
PGUSER=postgres \
PGDATABASE=postgres \
db-schema extract from-db --format yaml



Create sql from the example webshop.yaml:

$ db-schema compile sql example/webshop.yaml

Create rst documentation from the example webshop.yaml:

$ db-schema compile rst example/webshop.yaml


Schema ``shop``



Contains all orders

| Column  | Type                     | Nullable | Description |
| id      | integer                  | ✔        | Primary key |
| created | timestamp with time zone | ✔        |             |


Contains all order lines for all orders

| Column     | Type    | Nullable | Description |
| id         | integer | ✔        | Primary key |
| order_id   | integer | ✔        |             |
| line_nr    | integer | ✔        |             |
| product_id | integer | ✔        |             |
| amount     | integer | ✔        |             |

Schema ``public``

Description Format

One of the main components of the toolset is a database schema description format. The description format is based on YAML, because it is easy to read and write for humans.

See an example [here](

See the schema file [here](


This tool is specifically not meant as a cross database toolset, because that usually causes compatibility headaches and multiple partially supported database engines.

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 pg-db-tools, version 1.0.5
Filename, size File type Python version Upload date Hashes
Filename, size pg-db-tools-1.0.5.tar.gz (31.3 kB) File type Source Python version None Upload date Hashes View

Supported by

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