Skip to main content

Auto-generate Redshift schemas

Project description

Redshift Auto Schema

Redshift Auto Schema is a Python library that takes a delimited flat file or parquet file as input, parses it, and provides a variety of functions that allow for the creation and validation of tables within Amazon Redshift. For each field, the appropriate Redshift data type is inferred from the contents of the file.

Installation

Use the package manager pip to install Redshift Auto Schema.

pip install redshift-auto-schema

Usage

from redshift_auto_schema import RedshiftAutoSchema
import psycopg2 as pg

redshift_conn = pg.connect()

new_table = RedshiftAutoSchema(file='sample_file.parquet',
                               schema='test_schema',
                               table='test_table',
                               conn=redshift_conn)

if not new_table.check_table_existence():
    ddl = new_table.generate_table_ddl()

    with redshift_conn as conn:
    	with conn.cursor() as cur:
        	cur.execute(ddl)

Methods

NAME DESCRIPTION
get_column_list Returns column list based on header of file.
check_schema_existence Checks Redshift for the existence of a schema.
check_table_existence Checks Redshift for the existence of a table.
generate_schema_ddl Returns a SQL statement that creates a Redshift schema.
generate_schema_permissions Returns a SQL statement that grants schema usage to the default group.
generate_table_ddl Returns a SQL statement that creates a Redshift table.
generate_column_ddl Returns SQL statement(s) that adds missing column(s) a Redshift table.
generate_table_permissions Returns a SQL statement that grants table read access to the default group.
evaluate_table_ddl_diffs Returns a dataframe containing differences between generated and existing table DDL.

Contributing

Pull requests are welcome.

License

Apache License 2.0

Project details


Download files

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

Source Distribution

redshift-auto-schema-0.1.14.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

redshift_auto_schema-0.1.14-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file redshift-auto-schema-0.1.14.tar.gz.

File metadata

  • Download URL: redshift-auto-schema-0.1.14.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for redshift-auto-schema-0.1.14.tar.gz
Algorithm Hash digest
SHA256 eb1ebf91e1f72e0f277b0aadcf365d6c6beea91d4c9a2395dbe672cd97efe83c
MD5 0b8ce4fcbe6851ce0814a962ae847c8c
BLAKE2b-256 d4329464e8938ef18e36b3fdc590285872415a83b11c6f0965c4c8dd3299b44f

See more details on using hashes here.

File details

Details for the file redshift_auto_schema-0.1.14-py3-none-any.whl.

File metadata

  • Download URL: redshift_auto_schema-0.1.14-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for redshift_auto_schema-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 be9388d595a40f5e2281133af1980a1186e7aeb1953ed39c5236cadf7bd6db8b
MD5 5cc5e2555dd25b1e99903344f8044fad
BLAKE2b-256 105271d622eccac3e27bfbe7b6771f71ece6634efd7fddf7fc32524c23d02604

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page