csv-ingestor
Load data from CSV files into PostgreSQL tables.
Installation
pip install csv-ingestor
Examples
In the simplest case, load data from a CSV file into a table:
from csv_ingestor import Ingestor, ingest_file
class MyIngestor(Ingestor):
filename_pattern = r'simple\.\d{8}_\d{4}\.csv(\.gz)?'
tables = [
{
'table': 'my_table',
'csv_columns': ('id', 'value'),
}
]
ingest_file('simple.20240910_1430.csv.gz')
But maybe you have multiple tables to load from different CSV files, or from different fields in each file, and the column names don't match what's in the CSV files, and the data isn't quite the right shape either, and you'd like to skip some CSV records, and you'd like to update existing DB records:
from csv_ingestor import CSVPicker, Ingestor, SkipRecord, ingest_file
class MyPicker(CSVPicker):
def check_skip(self, record):
if record['value'].startswith('SKIP!'):
raise SkipRecord
def modify_record(self, record):
record['value'] = record['value'].replace('bad words', '@!#$*%&')
class OneIngestor(Ingestor):
filename_pattern = r'data\.\d{8}_\d{4}\.csv(\.gz)?'
tables = [
{
'table': 'my_first_table',
'csv_columns': ('their_id', 'their_value'),
'column_map': {'their_id': 'id', 'their_value': 'value'},
'on_conflict': '(id) DO UPDATE SET value = excluded.value',
}
]
class AnotherIngestor(Ingestor):
filename_pattern = r'other_data\.\d{8}\.csv(\.gz)?'
csv_picker = MyPicker
tables = [
{
'table': 'my_other_table',
'csv_columns': ('id', 'value'),
'on_conflict': '(id) DO UPDATE SET value = excluded.value',
},
{
'table': 'a_third_table',
'csv_columns': ('id', 'metadata'),
'on_conflict': '(id) DO NOTHING',
}
]
ingest_file('data.20240910_1430.csv.gz')
ingest_file('other_data.20240910.csv')
Each Ingestor subclass will be tried in turn until one matches the filename, and that one will
be used to parse and load the data into its DB tables.
Metadata
Release files for csv-ingestor 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| csv_ingestor-0.1.3.tar.gz | 5.0 kB | Without provenance | Details for csv_ingestor-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| csv_ingestor-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for csv_ingestor-0.1.3-py3-none-any.whl |
Total release size: 10.3 kB
Release files / csv_ingestor-0.1.3.tar.gz
| Download URL | csv_ingestor-0.1.3.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
affcd91111b1a1466bdcc20ef542dd2f74bd3b22774b6f73c59092a633fd5f54
|
|
BLAKE2b-256 checksum How to use checksums |
3896aad656e77e129e175c75579d83021a02b12d65c10dbe4b15fcf4c718a4f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Release files / csv_ingestor-0.1.3-py3-none-any.whl
| Download URL | csv_ingestor-0.1.3-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d3b49898cb851c654e9ae576947ee6b8bd6f66e6bcfa1ba28a6b2b8366a470ff
|
|
BLAKE2b-256 checksum How to use checksums |
e7124b6e45694e386a6375e4b3f5891e48eb1a49fc9a937ee318d82cc54bab77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.4
|
Security for csv-ingestor 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.