Skip to main content

A Python client for the 1WorldSync API

Project description

1WorldSync Python Client

A comprehensive Python Client library module for accessing the 1WorldSync REST API.

Package Structure

oneworldsync_python/
├── oneworldsync/
│   ├── __init__.py      # Package exports
│   ├── auth.py          # HMAC authentication
│   ├── client.py        # Main API client
│   ├── exceptions.py    # Custom exceptions
│   ├── models.py        # Data models for API responses
│   └── utils.py         # Utility functions
├── examples/
│   ├── search_example.py        # Example for product search
│   └── product_fetch_example.py # Example for fetching product details
├── README.md            # Documentation
└── setup.py             # Package installation

Key Features

  • HMAC Authentication: Handles the complex HMAC authentication required by the 1WorldSync API.
  • Easy-to-use Client: Provides a simple interface for interacting with the API.
  • Data Models: Structured models for API responses, making it easier to work with the data.
  • Error Handling: Custom exceptions for different types of errors.
  • Examples: Ready-to-use example scripts demonstrating common use cases.

Installation

pip install oneworldsync

Or install from source:

git clone https://github.com/mcgarrah/oneworldsync_client.git
cd oneworldsync_python
pip install -e .

Authentication

The 1WorldSync API uses HMAC authentication. You'll need an App ID and Secret Key from 1WorldSync.

You can store these credentials in a .env file:

APP_ID=your_app_id
SECRET_KEY=your_secret_key

Usage

Basic Usage

from oneworldsync import OneWorldSyncClient
import os
from dotenv import load_dotenv

# Load credentials from .env file
load_dotenv()
app_id = os.getenv("APP_ID")
secret_key = os.getenv("SECRET_KEY")

# Initialize client
client = OneWorldSyncClient(app_id, secret_key)

# Perform a free text search
results = client.free_text_search("apple")

# Print number of results
print(f"Found {len(results.products)} products")

# Print details of the first product
if results.products:
    product = results.products[0]
    print(f"Product: {product.brand_name} - {product.product_name}")
    print(f"Description: {product.description}")

Advanced Search

# Search for a product by UPC
results = client.advanced_search("itemPrimaryId", "00007252147019")

# Search with geo location
results = client.free_text_search(
    "coffee",
    geo_location=(37.7749, -122.4194)  # San Francisco coordinates
)

Working with Products

# Get a specific product by ID
product_data = client.get_product("some_product_id")

# Access product attributes
for product in results.products:
    print(f"ID: {product.item_id}")
    print(f"Brand: {product.brand_name}")
    print(f"Name: {product.product_name}")
    print(f"Description: {product.description}")
    
    # Get product dimensions
    dimensions = product.dimensions
    if dimensions:
        print(f"Dimensions: {dimensions['height']['value']} {dimensions['height']['unit']} x "
              f"{dimensions['width']['value']} {dimensions['width']['unit']} x "
              f"{dimensions['depth']['value']} {dimensions['depth']['unit']}")
    
    # Get product images
    for image in product.images:
        print(f"Image URL: {image['url']} (Primary: {image['is_primary']})")

Error Handling

from oneworldsync import OneWorldSyncClient, AuthenticationError, APIError

try:
    client = OneWorldSyncClient(app_id, secret_key)
    results = client.free_text_search("apple")
except AuthenticationError as e:
    print(f"Authentication failed: {e}")
except APIError as e:
    print(f"API error: {e}")
    print(f"Status code: {e.status_code}")

Development

Running Tests

pytest

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.1.0.tar.gz (9.3 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.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for oneworldsync-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5e351c0f2686c09b2ade6120873f4af46a8de8dc8c7117b725972e5012fbcb8d
MD5 4372aa452d04e664420cac1be5e6ca7b
BLAKE2b-256 2cf1a602f218926e0135a24fe8a1d9cf39222d69a16b8e3c5dc296d00add671f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: oneworldsync-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6219fb96c8364e77de5b9f1a4d2db530112efe2065e8b4e289e0670da8eef4a3
MD5 443c81bbbbb9461f816aaad55aa16bf7
BLAKE2b-256 4ab72e6ab47e60f9b6b298f095708adfd4696d7fea946f9a31b53ad697ab7964

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