GS1 GPC
A tool for importing GS1 Global Product Classification (GPC) data into SQL databases.
Features
- Import GS1 GPC XML data into SQLite or PostgreSQL databases
- Download the latest GPC data directly from GS1 API using the gpcc library
- Automatically use the newest cached version if download is not available
- Export database tables to SQL file for backup or migration
- Path handling relative to script location for reliable execution from any directory
- Command-line interface with Click
- Pip installable package
Installation
Development Installation
# Clone the repository
git clone https://github.com/mcgarrah/gs1_gpc_python.git
cd gs1_gpc_python
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Install the package in development mode
pip install -e .
Using requirements.txt
For convenience, you can install all dependencies including gpcc from GitHub:
pip install -r requirements.txt
pip install -e .
PostgreSQL Support
To use PostgreSQL instead of SQLite, install the PostgreSQL extra:
pip install -e ".[postgresql]"
Directory Structure
/data/imports- Directory for XML files (downloaded or manually placed)/data/instances- Directory for SQLite database files/data/exports- Directory for SQL dump files
Usage
Basic Import
gpc import-gpc
This will:
- Look for the latest cached XML file in the imports directory
- If none found, use the fallback file
- Import the data into the default SQLite database
Download Latest Data
gpc import-gpc --download
This will:
- Download the latest GPC data from the GS1 API
- Save it to the imports directory with standard naming convention:
{language_code}-{version}.xml - Import the data into the default SQLite database
Specify Language
gpc import-gpc --download --language nl
This will download and import the Dutch version of the GPC data.
Custom Files
gpc import-gpc --xml-file ./my_custom_file.xml --db-file ./my_database.sqlite3
Export Database to SQL
gpc import-gpc --dump-sql
This will:
- Import data as usual
- Export all GPC tables to a SQL file in the exports directory
- The SQL file will follow the naming convention:
{language_code}-v{date}.sql
Export Only (No Import)
gpc export-sql --db-file ./data/instances/gpc_data_xml.sqlite3
PostgreSQL Support
gpc import-gpc --db-type postgresql --db-file "postgresql://user:password@localhost/dbname"
Other Options
gpc import-gpc --help
Database Schema
The database uses the following schema with all tables prefixed with "gpc_":
CREATE TABLE gpc_segments (
segment_code TEXT PRIMARY KEY,
description TEXT
);
CREATE TABLE gpc_families (
family_code TEXT PRIMARY KEY,
description TEXT,
segment_code TEXT,
FOREIGN KEY (segment_code) REFERENCES gpc_segments (segment_code)
);
CREATE TABLE gpc_classes (
class_code TEXT PRIMARY KEY,
description TEXT,
family_code TEXT,
FOREIGN KEY (family_code) REFERENCES gpc_families (family_code)
);
CREATE TABLE gpc_bricks (
brick_code TEXT PRIMARY KEY,
description TEXT,
class_code TEXT,
FOREIGN KEY (class_code) REFERENCES gpc_classes (class_code)
);
CREATE TABLE gpc_attribute_types (
att_type_code TEXT PRIMARY KEY,
att_type_text TEXT,
brick_code TEXT,
FOREIGN KEY (brick_code) REFERENCES gpc_bricks (brick_code)
);
CREATE TABLE gpc_attribute_values (
att_value_code TEXT PRIMARY KEY,
att_value_text TEXT,
att_type_code TEXT,
FOREIGN KEY (att_type_code) REFERENCES gpc_attribute_types (att_type_code)
);
Example Queries
List all segments and families
SELECT
gpc_segments.segment_code,
gpc_families.family_code,
gpc_segments.description AS segment_text,
gpc_families.description AS family_text
FROM gpc_segments
JOIN gpc_families ON gpc_segments.segment_code = gpc_families.segment_code;
List all hierarchy levels with limit
SELECT
gpc_segments.segment_code,
gpc_families.family_code,
gpc_classes.class_code,
gpc_bricks.brick_code,
gpc_segments.description AS segment_text,
gpc_families.description AS family_text,
gpc_classes.description AS class_text,
gpc_bricks.description AS brick_text
FROM gpc_segments
JOIN gpc_families ON gpc_segments.segment_code = gpc_families.segment_code
JOIN gpc_classes ON gpc_families.family_code = gpc_classes.family_code
JOIN gpc_bricks ON gpc_classes.class_code = gpc_bricks.class_code
LIMIT 16;
Filter by segment
SELECT
gpc_segments.segment_code,
gpc_families.family_code,
gpc_classes.class_code,
gpc_bricks.brick_code,
gpc_segments.description AS segment_text,
gpc_families.description AS family_text,
gpc_classes.description AS class_text,
gpc_bricks.description AS brick_text
FROM gpc_segments
JOIN gpc_families ON gpc_segments.segment_code = gpc_families.segment_code
JOIN gpc_classes ON gpc_families.family_code = gpc_classes.family_code
JOIN gpc_bricks ON gpc_classes.class_code = gpc_bricks.class_code
WHERE gpc_segments.segment_code = '50000000'
LIMIT 16;
Development
Running Tests
pip install -e ".[dev]"
pytest gs1_gpc/tests/
Metadata
Release files for gs1-gpc 0.3.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 |
|---|---|---|---|---|
| gs1_gpc-0.3.3.tar.gz | 18.9 kB | Without provenance | Details for gs1_gpc-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gs1_gpc-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for gs1_gpc-0.3.3-py3-none-any.whl |
Total release size: 37.6 kB
Release files / gs1_gpc-0.3.3.tar.gz
| Download URL | gs1_gpc-0.3.3.tar.gz |
|---|---|
| Size | 18.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9aa49a4a6d6e76feb4362027d18b49fd5e28c7675b350e1f0dff1d27edba00f1
|
|
BLAKE2b-256 checksum How to use checksums |
d149f81f7ee8b96f0dd0678b96910727021a2f6ce0336a46e42895e9297f46d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.18
|
Release files / gs1_gpc-0.3.3-py3-none-any.whl
| Download URL | gs1_gpc-0.3.3-py3-none-any.whl |
|---|---|
| Size | 18.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1a6297c609d4e7bcfbdc8bf8c26d7a086d10fedf3aff8d114a2ed82c1541b2a7
|
|
BLAKE2b-256 checksum How to use checksums |
6ac7f5db3c72b13400bca9118fac78374d89f50770b27073ea90bf23272d03ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.18
|
Security for gs1-gpc 0.3.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.