# Python SDK

> Install shopsavvy-sdk from PyPI and fetch product details, prices from every retailer and price history in Python, with a context manager and typed errors.

*Source: https://shopsavvy.com/data/documentation/sdk-python* · Part of the [ShopSavvy Data API documentation](https://shopsavvy.com/data/documentation.md)

---

Our official Python SDK provides a convenient way to interact with the ShopSavvy Data API from Python applications with full type safety and modern async support.

- [View on GitHub](https://github.com/shopsavvy/sdk-python)
- [View on PyPI](https://pypi.org/project/shopsavvy-sdk/)

## Installation

```bash
pip install shopsavvy-sdk
```

## Basic Usage

```python
from shopsavvy import create_client

# Initialize the client
client = create_client("ss_live_your_api_key_here")

# Look up a product by barcode
product = client.get_product_details("012345678901")
print(product.data.name)

# Get current prices from all retailers
offers = client.get_current_offers("012345678901")
for offer in offers.data:
    print(f"{offer.retailer}: {offer.price}")

# Get price history
history = client.get_price_history(
    "012345678901",
    "2024-01-01",
    "2024-01-31"
)
```

## Features

- Full type safety with Pydantic models
- Modern HTTP client with automatic retries
- Comprehensive error handling
- Rails integration support
- Context manager support for automatic cleanup
- Python 2.7+ compatibility

## Context Manager Usage

```python
with create_client("ss_live_your_api_key_here") as client:
    product = client.get_product_details("012345678901")
    print(product.data.name)
# Client automatically closed
```

## Error Handling

```python
from shopsavvy import create_client, NotFoundError, AuthenticationError

try:
    client = create_client("ss_live_your_api_key_here")
    product = client.get_product_details("invalid-identifier")
except NotFoundError:
    print("Product not found")
except AuthenticationError:
    print("Invalid API key")
except Exception as e:
    print(f"Unexpected error: {e}")
```
