Downloader Module

GPC data downloading functionality.

This module provides classes for downloading GS1 GPC data from the GS1 API and finding the latest cached XML files.

The main class is GPCDownloader which handles downloading and locating GPC XML files. Legacy functions are provided for backward compatibility but new code should use the GPCDownloader class.

class gs1_gpc.downloader.GPCDownloader(download_dir=None, language_code='en')[source]

Bases: object

Class for downloading and managing GS1 GPC data files.

This class provides methods to download the latest GPC data from the GS1 API and find the latest cached XML files in a specified directory. It handles fallback mechanisms when downloads fail or when the gpcc library is not available.

__init__(download_dir=None, language_code='en')[source]

Initialize a GPCDownloader.

Parameters:
  • download_dir (str, optional) – Directory where GPC files will be stored. If None, uses the default GPC_DOWNLOAD_DIR.

  • language_code (str) – Language code for GPC data (default: ‘en’)

find_latest_xml_file()[source]

Find the latest GPC XML file in the download directory.

This method searches for XML files matching the pattern {language_code}-*.xml and returns the path to the file with the most recent version number. The version is extracted from the filename, which can be in either format: {language_code}-v{version}.xml or {language_code}-{version}.xml

Returns:

Path to the latest XML file or None if no files found

Return type:

str

download_latest_gpc_xml()[source]

Download the latest GS1 GPC data in XML format.

This method attempts to download the latest GPC data using the gpcc library. If the download fails or if gpcc is not available, it falls back to using cached XML files. If no cached files are found, it uses the default fallback file.

The downloaded file is saved in the download directory with the naming convention: {language_code}-{version}.xml

Returns:

Path to the XML file to use for import (either downloaded or cached)

Return type:

str

gs1_gpc.downloader.find_latest_xml_file(directory='/home/docs/checkouts/readthedocs.org/user_builds/gs1-gpc/checkouts/latest/data/imports', language_code='en')[source]

Find the latest GPC XML file in the specified directory.

This is a legacy function maintained for backward compatibility. New code should use the GPCDownloader class instead.

Parameters:
  • directory (str) – Directory to search for XML files

  • language_code (str) – Language code to filter files

Returns:

Path to the latest XML file or None if no files found

Return type:

str

gs1_gpc.downloader.download_latest_gpc_xml(language_code='en', target_directory=None)[source]

Download the latest GS1 GPC data in XML format.

This is a legacy function maintained for backward compatibility. New code should use the GPCDownloader class instead.

Parameters:
  • language_code – Language code to download

  • target_directory – Optional directory where the XML file will be saved. If None, uses GPC_DOWNLOAD_DIR.

Returns:

Path to the XML file to use for import

Return type:

str