Skip to main content

A Python client for the 1WorldSync Content1 Search and Fetch REST API

Project description

1WorldSync Content1 API Python Client

A Python client for interacting with the 1WorldSync Content1 API.

Installation

pip install oneworldsync

Key Features

  • Authentication with HMAC
  • Product fetching by GTIN, GLN, or target market
  • Product hierarchy retrieval
  • Pagination support
  • Comprehensive error handling
  • Content1-specific data models
  • OpenAPI 3.0.1 specification support

Package Structure

oneworldsync/
├── __init__.py           # Package initialization and version
├── content1_client.py    # Main Content1 API client
├── content1_auth.py      # HMAC authentication for Content1 API
├── models.py             # Data models for API responses
├── exceptions.py         # Custom exceptions
└── utils.py              # Utility functions

Quick Start

from oneworldsync import Content1Client

# Initialize the client
client = Content1Client(
    app_id='your_app_id',
    secret_key='your_secret_key',
    gln='your_gln'  # Optional
)

# Count products
count = client.count_products()
print(f"Total products: {count}")

# Fetch products by GTIN
products = client.fetch_products_by_gtin(['00000000000000'])
print(f"Found {len(products.get('items', []))} products")

# Fetch products with criteria
criteria = {
    "targetMarket": "US",
    "fields": {
        "include": ["gtin", "brandName", "gpcCategory"]
    }
}
results = client.fetch_products(criteria)

Authentication

The client supports authentication using your 1WorldSync Content1 API credentials:

# Using parameters
client = Content1Client(
    app_id='your_app_id',
    secret_key='your_secret_key',
    gln='your_gln'  # Optional
)

# Using environment variables
# ONEWORLDSYNC_APP_ID
# ONEWORLDSYNC_SECRET_KEY
# ONEWORLDSYNC_USER_GLN (optional)
# ONEWORLDSYNC_CONTENT1_API_URL (optional)
client = Content1Client()

Examples

See the examples directory for more detailed usage examples:

Basic Example (content1_example.py)

Basic usage of the Content1 API client to fetch products.

Advanced Example (content1_advanced_example.py)

# Create a date range for the last 30 days
today = datetime.datetime.now()
thirty_days_ago = today - datetime.timedelta(days=30)

date_criteria = {
    "lastModifiedDate": {
        "from": {
            "date": thirty_days_ago.strftime("%Y-%m-%d"),
            "op": "GTE"
        },
        "to": {
            "date": today.strftime("%Y-%m-%d"),
            "op": "LTE"
        }
    }
}

# Fetch products with specific fields and sorting
fetch_criteria = {
    "targetMarket": "US",
    "lastModifiedDate": date_criteria["lastModifiedDate"],
    "fields": {
        "include": [
            "gtin", "informationProviderGLN", "targetMarket",
            "lastModifiedDate", "brandName", "gpcCategory"
        ]
    },
    "sortFields": [
        {"field": "lastModifiedDate", "desc": True},
        {"field": "gtin", "desc": False}
    ]
}

# Fetch first page with pagination
products = client.fetch_products(fetch_criteria, page_size=10)

# Handle pagination
if "searchAfter" in products:
    next_page_criteria = fetch_criteria.copy()
    next_page_criteria["searchAfter"] = products["searchAfter"]
    next_page = client.fetch_products(next_page_criteria, page_size=10)

Documentation

For more detailed documentation, see the docs directory.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oneworldsync-0.2.1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oneworldsync-0.2.1-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file oneworldsync-0.2.1.tar.gz.

File metadata

  • Download URL: oneworldsync-0.2.1.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for oneworldsync-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9b79b5b4b9b014f12bf8c1e81ec6f5090b9651f807b3c8a8f8fbd5d5e6a0886f
MD5 fda78046553770cb23b298d8ae64e8fd
BLAKE2b-256 a8753f859138c534c19f559c8c97dbbed68b0ed5efc2bbcdb68af4b60df73844

See more details on using hashes here.

File details

Details for the file oneworldsync-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: oneworldsync-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for oneworldsync-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f22afb914181318b8e5b090c163bbe85ee4f1b416546a575e8f560fb30c6930f
MD5 9bc789856137d4b659c3e73f93ca0456
BLAKE2b-256 75203e4aa24bcb622b6b89fbcf07db36234c7d156dcde714b16f314cc5f15630

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page