Skip to main content

A small utility to upload CSVs to Postgres without needing to specify the table schema

Project description

Postgres CSV Uploader

This package provides a simple utility to upload CSV files to a Postgres DB without explicitly specifying the table schema in advance by inferring the column types from the corresponding Pandas dtypes.

Libraries such as SQLAlchemy provide systems to do this -- however, the SQLAlchemy ORM is substantially slower than interacting with the database driver directly (which is done by libraries like psycopg2). As a result, there was a (very small, very specific) need to create a smoother interface for uploading CSVs to Postgres quickly and with some kind of type inference.

Note that this is a very limited library. It requires being able to load the dataset into memory, and currently doesn't do any kind of partitioning or support parallelism. It also requires superadmin privileges within the DB. However, it does work decently well on small datasets.

As a word of caution, uploading is a destructive operation, meaning that it will overwrite the the existing table specified by the table_name parameter if it exists.

Example Usage:

from postgres_csv_uploader.uploader import PostgresCSVUploader
import psycopg2 as ps

conn = ps.connect(
    host="hostname",
    user="username",
    password="password",
    port=5432
)
uploader = PostgresCSVUploader(conn)
uploader.upload(
    "my_file.csv",
    "my_table_name",
    index_col="uid",
    datetime_cols=["first_date", "second_date"]
)

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

postgres_csv_uploader-0.2.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

postgres_csv_uploader-0.2.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file postgres_csv_uploader-0.2.0.tar.gz.

File metadata

  • Download URL: postgres_csv_uploader-0.2.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.6

File hashes

Hashes for postgres_csv_uploader-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bd4784d8acdadfabc0e3cdcfe0770e321be4f48ff10de333457ba1ceb2c920d5
MD5 087ef9feaa8d388bcde18668f17f19f1
BLAKE2b-256 88382fc2a61f716729203a35e71d6c664eb0f58e97450f5f1dc12f2c28acb6b4

See more details on using hashes here.

File details

Details for the file postgres_csv_uploader-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for postgres_csv_uploader-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5cd8849fc2ff94b6a2593955efbf0880e74f7353d94d929995a7eea88c95f3b0
MD5 93c471928fc23352bc5ddc22e4dd46fe
BLAKE2b-256 e64133120021b75ed3d7d42e2d6018c1a1c2695906e13e92964e49aacad949ce

See more details on using hashes here.

Supported by

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