Python function to ingest data from UN Comtrade's bulk API to PostgreSQL
Project description
pg-comtrade
Python utility function to ingest data from UN Comtrade's bulk API into a (partitioned) PostgreSQL table.
[!IMPORTANT] This is a work-in-progress. This README serves as a rough design spec.
Installation
pg-comtrade can be installed from PyPI using pip. psycopg2 or psycopg (Psycopg 3) must also be explicitly installed.
pip install pg-comtrade psycopg
Usage
from pg_comtrade import sync_goods_yearly
# For example purposes, PostgreSQL can be run locally using this...
# docker run --rm -it -e POSTGRES_HOST_AUTH_METHOD=trust -p 5432:5432 postgres
# ... which should work with this engine
engine = sa.create_engine('postgresql+psycopg://postgres@127.0.0.1:5432/')
# ... to ingest into the un.comtrade_goods table
with engine.connect() as conn:
sync_goods_yearly(conn, 'un', 'comtrade_goods', subscription_key='123456abcdef')
Development / running tests
To develop pg-comtrade, you will need to install the package in editable mode, and install development dependencies.
pip install -e '.[dev]'
And start a local PostgreSQL server:
./start-services.sh
And then to run the tests:
pytest
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 Distribution
Built Distribution
File details
Details for the file pg_comtrade-0.0.2.tar.gz
.
File metadata
- Download URL: pg_comtrade-0.0.2.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 435c155b73c144b0462b0f19535b84555c80f3874182e241d25e830f8c40df8c |
|
MD5 | 99393510b8f1bad58167cf5787882d19 |
|
BLAKE2b-256 | 7e4e46f90be0cfb7408e500b7a6070bdb46e1221003e2c93f97d0d6865f4dc16 |
File details
Details for the file pg_comtrade-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: pg_comtrade-0.0.2-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8a64223366a4f01360b9d190ba0911e5ca720ff15ac41f3948dfed5edf687f4 |
|
MD5 | e221b523152c8d767ca7d917a15e52b0 |
|
BLAKE2b-256 | c94b879a30d655b2ddfce61b50c105805cda2f93c0ecc9983f65e8173f35ac83 |