{"id":29908866,"url":"https://github.com/mcgarrah/gs1_gpc_python","last_synced_at":"2026-04-02T02:02:12.431Z","repository":{"id":295901577,"uuid":"991629936","full_name":"mcgarrah/gs1_gpc_python","owner":"mcgarrah","description":"A tool for importing GS1 Global Product Classification (GPC) data into SQL databases.","archived":false,"fork":false,"pushed_at":"2025-06-19T21:40:03.000Z","size":7139,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-25T14:10:14.566Z","etag":null,"topics":["classification","gpc","gs1","product"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mcgarrah.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-27T23:26:57.000Z","updated_at":"2025-06-19T21:39:57.000Z","dependencies_parsed_at":"2025-05-28T00:41:05.553Z","dependency_job_id":null,"html_url":"https://github.com/mcgarrah/gs1_gpc_python","commit_stats":null,"previous_names":["mcgarrah/gs1_gpc_python"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mcgarrah/gs1_gpc_python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcgarrah%2Fgs1_gpc_python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcgarrah%2Fgs1_gpc_python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcgarrah%2Fgs1_gpc_python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcgarrah%2Fgs1_gpc_python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mcgarrah","download_url":"https://codeload.github.com/mcgarrah/gs1_gpc_python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mcgarrah%2Fgs1_gpc_python/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268320420,"owners_count":24231804,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["classification","gpc","gs1","product"],"created_at":"2025-08-02T00:44:57.849Z","updated_at":"2026-04-02T02:02:12.370Z","avatar_url":"https://github.com/mcgarrah.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GS1 GPC\n\nA tool for importing GS1 Global Product Classification (GPC) data into SQL databases.\n\n## Features\n\n- Import GS1 GPC XML data into SQLite or PostgreSQL databases\n- Download the latest GPC data directly from GS1 API using the gpcc library\n- Automatically use the newest cached version if download is not available\n- Export database tables to SQL file for backup or migration\n- Path handling relative to script location for reliable execution from any directory\n- Command-line interface with Click\n- Pip installable package\n\n## Installation\n\n\n### Development Installation\n\n```bash\n# Clone the repository\ngit clone https://github.com/mcgarrah/gs1_gpc_python.git\ncd gs1_gpc_python\n\n# Create and activate a virtual environment\npython -m venv .venv\nsource .venv/bin/activate  # On Windows: .venv\\Scripts\\activate\n\n# Install dependencies\npip install -r requirements.txt\n\n# Install the package in development mode\npip install -e .\n```\n\n### Using requirements.txt\n\nFor convenience, you can install all dependencies including gpcc from GitHub:\n\n```bash\npip install -r requirements.txt\npip install -e .\n```\n\n### PostgreSQL Support\n\nTo use PostgreSQL instead of SQLite, install the PostgreSQL extra:\n\n```bash\npip install -e \".[postgresql]\"\n```\n\n## Directory Structure\n\n- `/data/imports` - Directory for XML files (downloaded or manually placed)\n- `/data/instances` - Directory for SQLite database files\n- `/data/exports` - Directory for SQL dump files\n\n## Usage\n\n### Basic Import\n\n```bash\ngpc import-gpc\n```\n\nThis will:\n\n1. Look for the latest cached XML file in the imports directory\n2. If none found, use the fallback file\n3. Import the data into the default SQLite database\n\n### Download Latest Data\n\n```bash\ngpc import-gpc --download\n```\n\nThis will:\n\n1. Download the latest GPC data from the GS1 API\n2. Save it to the imports directory with standard naming convention: `{language_code}-{version}.xml`\n3. Import the data into the default SQLite database\n\n### Specify Language\n\n```bash\ngpc import-gpc --download --language nl\n```\n\nThis will download and import the Dutch version of the GPC data.\n\n### Custom Files\n\n```bash\ngpc import-gpc --xml-file ./my_custom_file.xml --db-file ./my_database.sqlite3\n```\n\n### Export Database to SQL\n\n```bash\ngpc import-gpc --dump-sql\n```\n\nThis will:\n\n1. Import data as usual\n2. Export all GPC tables to a SQL file in the exports directory\n3. The SQL file will follow the naming convention: `{language_code}-v{date}.sql`\n\n### Export Only (No Import)\n\n```bash\ngpc export-sql --db-file ./data/instances/gpc_data_xml.sqlite3\n```\n\n### PostgreSQL Support\n\n```bash\ngpc import-gpc --db-type postgresql --db-file \"postgresql://user:password@localhost/dbname\"\n```\n\n### Other Options\n\n```bash\ngpc import-gpc --help\n```\n\n## Database Schema\n\nThe database uses the following schema with all tables prefixed with \"gpc_\":\n\n```sql\nCREATE TABLE gpc_segments (\n    segment_code TEXT PRIMARY KEY,\n    description TEXT\n);\n\nCREATE TABLE gpc_families (\n    family_code TEXT PRIMARY KEY,\n    description TEXT,\n    segment_code TEXT,\n    FOREIGN KEY (segment_code) REFERENCES gpc_segments (segment_code)\n);\n\nCREATE TABLE gpc_classes (\n    class_code TEXT PRIMARY KEY,\n    description TEXT,\n    family_code TEXT,\n    FOREIGN KEY (family_code) REFERENCES gpc_families (family_code)\n);\n\nCREATE TABLE gpc_bricks (\n    brick_code TEXT PRIMARY KEY,\n    description TEXT,\n    class_code TEXT,\n    FOREIGN KEY (class_code) REFERENCES gpc_classes (class_code)\n);\n\nCREATE TABLE gpc_attribute_types (\n    att_type_code TEXT PRIMARY KEY,\n    att_type_text TEXT,\n    brick_code TEXT,\n    FOREIGN KEY (brick_code) REFERENCES gpc_bricks (brick_code)\n);\n\nCREATE TABLE gpc_attribute_values (\n    att_value_code TEXT PRIMARY KEY,\n    att_value_text TEXT,\n    att_type_code TEXT,\n    FOREIGN KEY (att_type_code) REFERENCES gpc_attribute_types (att_type_code)\n);\n```\n\n## Example Queries\n\n### List all segments and families\n\n```sql\nSELECT \n    gpc_segments.segment_code, \n    gpc_families.family_code, \n    gpc_segments.description AS segment_text, \n    gpc_families.description AS family_text \nFROM gpc_segments \nJOIN gpc_families ON gpc_segments.segment_code = gpc_families.segment_code;\n```\n\n### List all hierarchy levels with limit\n\n```sql\nSELECT \n    gpc_segments.segment_code, \n    gpc_families.family_code, \n    gpc_classes.class_code, \n    gpc_bricks.brick_code,\n    gpc_segments.description AS segment_text, \n    gpc_families.description AS family_text, \n    gpc_classes.description AS class_text, \n    gpc_bricks.description AS brick_text\nFROM gpc_segments \nJOIN gpc_families ON gpc_segments.segment_code = gpc_families.segment_code\nJOIN gpc_classes ON gpc_families.family_code = gpc_classes.family_code\nJOIN gpc_bricks ON gpc_classes.class_code = gpc_bricks.class_code\nLIMIT 16;\n```\n\n### Filter by segment\n\n```sql\nSELECT \n    gpc_segments.segment_code, \n    gpc_families.family_code, \n    gpc_classes.class_code, \n    gpc_bricks.brick_code,\n    gpc_segments.description AS segment_text, \n    gpc_families.description AS family_text, \n    gpc_classes.description AS class_text, \n    gpc_bricks.description AS brick_text\nFROM gpc_segments \nJOIN gpc_families ON gpc_segments.segment_code = gpc_families.segment_code\nJOIN gpc_classes ON gpc_families.family_code = gpc_classes.family_code\nJOIN gpc_bricks ON gpc_classes.class_code = gpc_bricks.class_code\nWHERE gpc_segments.segment_code = '50000000' \nLIMIT 16;\n```\n\n## Development\n\n### Running Tests\n\n```bash\npip install -e \".[dev]\"\npytest gs1_gpc/tests/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcgarrah%2Fgs1_gpc_python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmcgarrah%2Fgs1_gpc_python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmcgarrah%2Fgs1_gpc_python/lists"}