Product DataProduct Data SDK

Product Data SDK

The Datafiniti Product Data SDK is a lightweight Python wrapper around the Product Data API. It handles authentication, query construction, and pagination so you can fetch product records — names, brands, prices, categories, and more — without writing raw API requests.

Installation

The SDK is published to PyPI as part of the unified datafiniti-sdk package, which bundles the Business, People, Property, and Product clients together.

pip install datafiniti-sdk

Authentication

All SDK classes require a Datafiniti API key. Set it once as an environment variable and the client will pick it up automatically, or pass it directly when you instantiate the client.

export DATAFINITI_API_KEY="YOUR_API_KEY"

If you use the environment variable approach, initialize the client with DatafinitiProductSDK.from_env(). You can also import directly from the product module with from datafiniti.product import DatafinitiProductSDK.

Features

Search by name

Look up product records by product name, optionally narrowing by brand. Use this to quickly retrieve product details without writing raw API queries.

from datafiniti.product import DatafinitiProductSDK

sdk = DatafinitiProductSDK.from_env()

# Search by product name — optionally narrow by brand
results = sdk.search_by_name("iPhone 15", brand="Apple", num_records=10)

print("
=== NAME SEARCH TEST ===")
print("Matches:", results.get("num_found"))

records = results.get("records", [])

if records:
    product = records[0]
    print("
Product:")
    print(product.get("name"))
    print(product.get("brand"))
    print(product.get("primaryCategories"))
else:
    print("No product found.")

Code breakdown

SectionWhat it does
from datafiniti.product import DatafinitiProductSDKImports the DatafinitiProductSDK class from the datafiniti.product module.
sdk = DatafinitiProductSDK.from_env()Creates a client instance using the DATAFINITI_API_KEY environment variable.
sdk.search_by_name("iPhone 15", brand, num_records)Queries the Product Data API for records matching the given product name.
results.get("num_found")Returns the total number of products that matched the query.
results.get("records", [])Retrieves the list of product records, defaulting to an empty list if none exist.
records[0]Accesses the first (best-match) product record from the results.
.get("name"), .get("brand"), .get("primaryCategories")Safely reads individual fields from the product record.

The search_by_name method abstracts away the raw query syntax. You only need to provide a product name and an optional brand to narrow results.

Count

Get the total number of products matching a query without downloading any records. Use this to check result sizes before running larger searches or to build dashboards with aggregate counts.

from datafiniti.product import DatafinitiProductSDK

sdk = DatafinitiProductSDK.from_env()

count = sdk.count('brand:"Apple"')

print("
=== COUNT TEST ===")
print(f"Products found: {count:,}")

Code breakdown

SectionWhat it does
from datafiniti.product import DatafinitiProductSDKImports the DatafinitiProductSDK class from the datafiniti.product module.
sdk = DatafinitiProductSDK.from_env()Creates a client instance using the DATAFINITI_API_KEY environment variable.
sdk.count('brand:"Apple"')Returns the total number of Apple-branded products without fetching full records.
f"Products found: {count:,}"Formats the count with comma separators for readability (e.g., 1,234,567).

The count method accepts the same query syntax as search but only returns the total number of matching records — no data is downloaded.

Understanding the query syntax

The query string 'brand:"Apple"' uses Datafiniti's query language. Here's what you need to know:

QuestionAnswer
What is the format?See the Constructing Product Queries guide for the complete field reference, operators, and advanced examples.
How do I handle multi-word string values?Wrap them in exact quotes: brand:"Stanley Black & Decker".
What fields can I query & what is the full list of field names?Any field in the Product Data Schemaname, brand, gtins, mpn, sku, primaryCategories, categories, prices, and many more.

Build a query

Compose a product query using the fluent query builder. Chain field methods — such as brand, category, or GTIN — and call .build() to produce a Datafiniti query string.

from datafiniti.product import DatafinitiProductSDK

sdk = DatafinitiProductSDK.from_env()

# Build a product query without writing raw syntax
query = (
    sdk.query()
    .brand("Apple")
    .categories(["Cell Phones"])
    .build()
)

results = sdk.search(query, num_records=10)

print("
=== QUERY BUILDER TEST ===")
print(f"Total matches: {results.get('num_found'):,}")

for product in results.get("records", []):
    print(f"{product.get('name')}{product.get('brand')}")

Code breakdown

SectionWhat it does
from datafiniti.product import DatafinitiProductSDKImports the DatafinitiProductSDK class from the datafiniti.product module.
sdk = DatafinitiProductSDK.from_env()Creates a client instance using the DATAFINITI_API_KEY environment variable.
sdk.query()Returns a fluent ProductQuery builder for composing a query without raw syntax.
.brand(...).categories(...)Chains field methods to add constraints to the query.
.build()Produces the final Datafiniti query string from the chained fields.
sdk.search(query, num_records=10)Executes the search and returns up to num_records matching records.

ProductQuery is a fluent query builder exposing fields relevant to the Product data type. Chain field methods and call .build() to produce a Datafiniti query string you can pass to search, count, or paginate.

Search by GTIN

Search directly with a raw query to look up products by GTIN (UPC, EAN, ISBN, and other global trade item numbers). Use this when you have a barcode or product identifier and want to retrieve the matching product record.

from datafiniti.product import DatafinitiProductSDK

sdk = DatafinitiProductSDK.from_env()

# Search by GTIN (UPC, EAN, ISBN, etc.)
results = sdk.search('gtins:"885909950805"', num_records=1)

print("
=== GTIN SEARCH ===")
for product in results.get("records", []):
    print(f"{product.get('name')}{product.get('brand')}")
    print(f"--gtins: {product.get('gtins')}")
    print(f"--categories: {product.get('primaryCategories')}")

Code breakdown

SectionWhat it does
from datafiniti.product import DatafinitiProductSDKImports the DatafinitiProductSDK class from the datafiniti.product module.
sdk = DatafinitiProductSDK.from_env()Creates a client instance using the DATAFINITI_API_KEY environment variable.
sdk.search('gtins:"885909950805"', num_records=1)Looks up a product by an exact GTIN value.
results.get("records", [])Retrieves the list of matching product records.

The gtins field covers UPC, EAN, ISBN, and other global trade item numbers, all normalized into a single searchable field. This makes it the most reliable way to match a physical product to its Datafiniti record.

Paginate

Iterate through large result sets page by page without loading everything into memory at once. Use this to process thousands of records efficiently or to cap the number of retrievals at a specific limit.

from datafiniti.product import DatafinitiProductSDK

sdk = DatafinitiProductSDK.from_env()

print("
=== PAGINATION TEST ===")

records_seen = 0

for product in sdk.paginate(
    query='brand:"Apple"',
    page_size=10,
    max_records=50,
):
    records_seen += 1
    print(f"{records_seen}. {product.get('name', 'Unknown Product')}")

print(f"
Total Retrieved: {records_seen}")

Code breakdown

SectionWhat it does
from datafiniti.product import DatafinitiProductSDKImports the DatafinitiProductSDK class from the datafiniti.product module.
sdk = DatafinitiProductSDK.from_env()Creates a client instance using the DATAFINITI_API_KEY environment variable.
sdk.paginate(query, page_size, max_records)Returns a generator that yields individual product records across multiple API pages.
query='brand:"Apple"'The search query — in this case, all Apple-branded products.
page_size=10Fetches 10 records per API request.
max_records=50Stops after retrieving 50 total records, even if more are available.
for product in sdk.paginate(...)Iterates through each yielded record one at a time without loading the full result set into memory.
product.get('name', 'Unknown Product')Safely reads the name field with a fallback default if the field is missing.

The paginate method is a generator — it handles API pagination automatically behind the scenes. Set max_records to limit total retrieval, or omit it to iterate through all matching results.

Understanding the query syntax

The query parameter uses Datafiniti's query language. Here's what you need to know:

QuestionAnswer
What is the format?See the Constructing Product Queries guide for the complete field reference, operators, and advanced examples.
How do I handle multi-word values?Wrap them in quotes: brand:"Stanley Black & Decker".
What fields can I query?Any field in the Product Data Schemaname, brand, gtins, mpn, sku, primaryCategories, categories, prices, and many more.

Views

Control which fields are returned in API responses using custom inline views or premade named views. Use this to reduce payload size, speed up requests, and tailor results to specific use cases — such as building a lightweight pricing feed. For a full list of available product data views, see Product Data Views.

"""
Product Views Example: Lightweight Pricing Feed

Uses a custom view to fetch only the fields needed to build a price-tracking
feed — name, brand, GTIN, and prices — keeping the response small and fast.
"""

from datafiniti.product import DatafinitiProductSDK

# ---------------------------------------------------------------------------
# View options
#
# OPTION 1 (used below): Custom inline view
#   Pass a list of field objects directly in the request. No setup required.
#   Each object can set "flatten" and "sub_fields" to control nested output.
#
# OPTION 2: Premade (named) view — pass a string instead of a list.
#   "default"            All fields (same as omitting view entirely).
#   "product_pricesFlat" All fields; one row per price entry.
#   "product_reviewsFlat" All fields; one row per review.
#     Example: sdk.search(query, view="product_pricesFlat", num_records=10)
#   Reference: https://docs.datafiniti.co/docs/available-views-for-product-data
# ---------------------------------------------------------------------------

PRODUCT_VIEW = [
    {"flatten": False, "sub_fields": [], "name": "name"},
    {"flatten": False, "sub_fields": [], "name": "brand"},
    {"flatten": False, "sub_fields": [], "name": "gtins"},
    {"flatten": True, "sub_fields": ["amountMin", "amountMax", "currency"], "name": "prices"},
]

sdk = DatafinitiProductSDK.from_env()

results = sdk.search(
    query='brand:"Apple" AND categories:"Cell Phones"',
    num_records=5,
    view=PRODUCT_VIEW,
)

print("
=== PRODUCT VIEWS ===")
print(f"Total matches: {results.get('num_found'):,}
")

for product in results.get("records", []):
    prices = product.get("prices", [])
    price = prices[0] if prices else {}
    print(f"Name: {product.get('name', 'N/A')}")
    print(f"Brand: {product.get('brand', 'N/A')}")
    print(f"GTIN: {product.get('gtins', ['N/A'])[0] if product.get('gtins') else 'N/A'}")
    print(f"Price: {price.get('amountMin', 'N/A')} {price.get('currency', '')}")
    print()

Code breakdown

SectionWhat it does
from datafiniti.product import DatafinitiProductSDKImports the DatafinitiProductSDK class from the datafiniti.product module.
PRODUCT_VIEW = [...]Defines a custom inline view — a list of field objects specifying exactly which fields to return per record.
{"flatten": True, "sub_fields": [...], "name": "prices"}A single field object. flatten and sub_fields control how nested/multi-valued fields like prices are returned.
sdk.search(query, num_records=5, view=PRODUCT_VIEW)Executes the search with the inline view — only the specified fields are returned.
query='brand:"Apple" AND categories:"Cell Phones"'Limits results to Apple products in the Cell Phones category.
for product in results.get("records", []):Iterates through each result and prints the name, brand, GTIN, and price.

You can use either a custom inline view (a list of field objects) or a premade named view (a string like "product_pricesFlat" or "default"). Custom views give you precise control over the response payload; named views are convenient presets for common use cases.

Code Examples

Here are some Python examples built upon what we have just discussed. All scripts here should be ready to run as long as you have your DATAFINITI_API_KEY exported.

Every Product SDK method — search, count, paginate, and query — shares the same query language and view system as the Business, People, and Property SDKs. Once you know one, you know them all. For the full set of queryable fields, see the Product Data Schema.

from datafiniti.product import DatafinitiProductSDK
from datafiniti.errors import DatafinitiAPIError

sdk = DatafinitiProductSDK.from_env()

try:
    count = sdk.count("brand:*")
    print("
=== PRODUCT COUNT TEST ===")
    print(f"Products found: {count:,}")
except DatafinitiAPIError as e:
    print(f"
API Error {e.status_code}: {e}")
    for msg in e.errors:
        print(f"  {msg}")