or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/pypi-google-shopping-type

Google Shopping Type API client library providing protobuf-generated classes for common shopping data types

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/google-shopping-type@1.0.x

To install, run

npx @tessl/cli install tessl/pypi-google-shopping-type@1.0.0

index.mddocs/

Google Shopping Type

Google Shopping Type API client library providing protobuf-generated classes for common shopping-related data types and structures. This package serves as a foundational dependency for other Google Shopping services with key features:

  • Standardized type definitions for shopping data structures
  • Type safety through protobuf-generated classes
  • Consistency across Google Shopping services
  • High-precision monetary and weight values using micros precision
  • Comprehensive enum definitions for channels, destinations, and reporting contexts

Package Information

  • Package Name: google-shopping-type
  • Package Type: pypi
  • Language: Python
  • Installation: pip install google-shopping-type
  • Version: 1.0.0

Core Imports

from google.shopping.type import (
    Channel,
    CustomAttribute, 
    Destination,
    Price,
    ReportingContext,
    Weight
)

Alternative import pattern:

from google.shopping.type.types import (
    Channel,
    CustomAttribute,
    Destination, 
    Price,
    ReportingContext,
    Weight
)

Version information:

from google.shopping.type import __version__

Basic Usage

from google.shopping.type import Price, Weight, Channel

# Create a price object
price = Price()
price.amount_micros = 1500000  # $1.50 in micros
price.currency_code = "USD"

# Create a weight object  
weight = Weight()
weight.amount_micros = 1000000  # 1kg in micros
weight.unit = Weight.WeightUnit.KILOGRAM

# Create a channel enum
channel_online = Channel.ChannelEnum.ONLINE
channel_local = Channel.ChannelEnum.LOCAL

print(f"Price: {price.amount_micros} micros {price.currency_code}")
print(f"Weight: {weight.amount_micros} micros, unit: {weight.unit}")
print(f"Channels: {channel_online}, {channel_local}")

Architecture

This package follows Google's protobuf-based API design patterns using the proto-plus library. All classes are protobuf message classes that provide type-safe representations of shopping-related data structures:

  • Message Classes: Each class extends proto.Message providing serialization and validation
  • Enum Types: Nested enum classes define valid values for categorical fields
  • Field Definitions: Fields use proto field descriptors with proper typing and optional handling
  • Micros Precision: Monetary and weight values use micros (1/1,000,000) for precision

Capabilities

Price Representation

Represents monetary values with micros precision and currency codes following ISO 4217 standards.

class Price(proto.Message):
    """
    The price represented as a number and currency.
    
    Attributes:
        amount_micros (int, optional): Price in micros (1 million micros = 1 currency unit)
        currency_code (str, optional): Three-letter ISO 4217 currency code
    """
    amount_micros: int = proto.Field(proto.INT64, number=1, optional=True)
    currency_code: str = proto.Field(proto.STRING, number=2, optional=True)

Weight Representation

Represents weight values with micros precision and standard units (kg/lb).

class Weight(proto.Message):
    """
    The weight represented as the value in string and the unit.
    
    Attributes:
        amount_micros (int, optional): Weight in micros (1 million micros = 1 unit)
                                      Can be set to -1 for infinity
        unit (WeightUnit): Required weight unit (kg or lb)
    """
    class WeightUnit(proto.Enum):
        """Weight unit enumeration."""
        WEIGHT_UNIT_UNSPECIFIED = 0
        POUND = 1
        KILOGRAM = 2
    
    amount_micros: int = proto.Field(proto.INT64, number=1, optional=True)
    unit: WeightUnit = proto.Field(proto.ENUM, number=2, enum=WeightUnit)

Custom Attributes

Represents custom attributes with hierarchical structure support for nested attributes.

class CustomAttribute(proto.Message):
    """
    Custom attributes with name/value pairs or nested groups.
    Exactly one of value or group_values must not be empty.
    
    Attributes:
        name (str, optional): The name of the attribute
        value (str, optional): The value (mutually exclusive with group_values)
        group_values (MutableSequence[CustomAttribute]): Nested attributes
    """
    name: str = proto.Field(proto.STRING, number=1, optional=True)
    value: str = proto.Field(proto.STRING, number=2, optional=True)
    group_values: MutableSequence["CustomAttribute"] = proto.RepeatedField(
        proto.MESSAGE, number=3, message="CustomAttribute"
    )

Product Destinations

Defines available destinations where products can be displayed across Google's merchant ecosystem.

class Destination(proto.Message):
    """
    Destinations available for a product.
    Used in Merchant Center to control where products are displayed.
    """
    class DestinationEnum(proto.Enum):
        """Destination values."""
        DESTINATION_ENUM_UNSPECIFIED = 0
        SHOPPING_ADS = 1
        DISPLAY_ADS = 2
        LOCAL_INVENTORY_ADS = 3
        FREE_LISTINGS = 4
        FREE_LOCAL_LISTINGS = 5
        YOUTUBE_SHOPPING = 6

Reporting Contexts

Defines reporting contexts for account and product issues across various Google surfaces and formats.

class ReportingContext(proto.Message):
    """
    Reporting contexts that account and product issues apply to.
    Groups surfaces and formats for product results on Google.
    """
    class ReportingContextEnum(proto.Enum):
        """Reporting context values."""
        REPORTING_CONTEXT_ENUM_UNSPECIFIED = 0
        SHOPPING_ADS = 1
        DISCOVERY_ADS = 2  # Deprecated: Use DEMAND_GEN_ADS instead
        DEMAND_GEN_ADS = 13
        DEMAND_GEN_ADS_DISCOVER_SURFACE = 14
        VIDEO_ADS = 3
        DISPLAY_ADS = 4
        LOCAL_INVENTORY_ADS = 5
        VEHICLE_INVENTORY_ADS = 6
        FREE_LISTINGS = 7
        FREE_LOCAL_LISTINGS = 8
        FREE_LOCAL_VEHICLE_LISTINGS = 9
        YOUTUBE_SHOPPING = 10
        CLOUD_RETAIL = 11
        LOCAL_CLOUD_RETAIL = 12

Channel Types

Distinguishes between online and local products in the merchant ecosystem.

class Channel(proto.Message):
    """
    Channel of a product, used to distinguish between online and local products.
    """
    class ChannelEnum(proto.Enum):
        """Channel values."""
        CHANNEL_ENUM_UNSPECIFIED = 0
        ONLINE = 1
        LOCAL = 2

Types

All message classes extend proto.Message and provide the following common functionality:

# Common proto.Message methods available on all classes
def __init__(self, mapping=None, **kwargs): ...
def __contains__(self, key): ...
def __getattr__(self, key): ...  
def __setattr__(self, key, value): ...
def to_dict(self, **kwargs): ...
def to_json(self, **kwargs): ...

Type Imports

from typing import MutableMapping, MutableSequence
import proto

Error Handling

This package uses proto-plus validation which will raise ValueError exceptions for:

  • Invalid enum values
  • Required fields that are not set
  • Type mismatches in field assignments

The protobuf classes handle serialization errors and will raise appropriate exceptions during message parsing or field validation.

Dependencies

  • google-api-core[grpc] >= 1.34.1, <3.0.0: Core Google API functionality
  • google-auth >= 2.14.1, <3.0.0: Authentication for Google APIs
  • proto-plus >= 1.22.3, <2.0.0: Enhanced protobuf support for Python
  • protobuf >=3.20.2,<7.0.0: Protocol buffer runtime