Quickstart
Basic Usage
After installing the package, you can use the gpc command-line tool to import GS1 GPC data into a database.
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}.xmlImport the data into the default SQLite database
Specify Language
gpc import-gpc --download --language fr
This will download and import the French 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"
Python API Usage
You can also use the package as a Python library:
from gs1_gpc.db import DatabaseConnection, setup_database
from gs1_gpc.parser import process_gpc_xml
from gs1_gpc.downloader import find_latest_xml_file
# Find the latest XML file
xml_file = find_latest_xml_file()
# Create database connection
db_connection = DatabaseConnection("my_database.sqlite3")
# Setup database
setup_database(db_connection)
# Process XML file
process_gpc_xml(xml_file, db_connection)
# Close database connection
db_connection.close()