Import/export CSV files efficiently to/from a Postgresql database.
Project description
csv_pg
A Python module to import/export CSV files efficiently to/from a Postgresql database.
Key features:
- Detect CSV file dialect automatically
- Create target database table automatically
- Handle localized date/time and decimal formats
- Filter CSV file rows during import
Usage examples
Installation:
pip install csv_pg
Import CSV file tests/samples/misc.csv
to table misc
(recreate table if already exists):
python -m csv_pg from_csv tests/samples/misc.csv --recreate
Export table misc
to CSV file misc.local.csv
(recreate file if already exists):
python -m csv_pg to_csv misc.local.csv misc --recreate
Contributors guidelines
Prepare environment:
# Debian: sudo apt install libpq-dev
python -m venv .venv # Debian: python3 -m venv .venv
.\.venv\Scripts\activate # Linux: source .venv/bin/activate
pip install .[dev]
Create test database:
sudo -u postgres createdb -E UTF8 -l fr_FR.UTF8 -T template0 test_csv_pg
Run tests:
python -m unittest
Alternatives / inspirations
-
- Have to manually call Postgresql COPY command?
-
- Depends on Django, and force import to a Django model (cannot simply load to a temporary table)
- No filter during import?
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
csv_pg-0.1.0-py3-none-any.whl
(13.4 kB
view details)
File details
Details for the file csv_pg-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: csv_pg-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78cd622ce39cc4d0b40f3de367288c69e253102270cda738ce343d5af735edc8 |
|
MD5 | 18cd1d25c0657b247126077afa46c4ef |
|
BLAKE2b-256 | a9ded05cbe9e1d48eab67dc50a9bccc5690212e686dd4349e7137efe2b17ddae |