channel3-sdk 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of channel3-sdk might be problematic. Click here for more details.
channel3_sdk/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .client import Channel3Client
|
channel3_sdk/client.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# channel3_sdk/client.py
|
|
2
|
+
import os
|
|
3
|
+
import requests
|
|
4
|
+
from typing import List, Optional, Dict, Any, Union
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Channel3Client:
|
|
8
|
+
def __init__(self, api_key: str = None):
|
|
9
|
+
"""
|
|
10
|
+
Initialize a Channel3 API client.
|
|
11
|
+
|
|
12
|
+
The client provides methods to interact with Channel3's product search and retrieval API.
|
|
13
|
+
|
|
14
|
+
Args:
|
|
15
|
+
api_key: Your Channel3 API key. If not provided, will look for CHANNEL3_API_KEY in environment.
|
|
16
|
+
|
|
17
|
+
Raises:
|
|
18
|
+
ValueError: If no API key is provided and none is found in environment variables.
|
|
19
|
+
|
|
20
|
+
Example:
|
|
21
|
+
```python
|
|
22
|
+
# Initialize with explicit API key
|
|
23
|
+
client = Channel3Client(api_key="your_api_key")
|
|
24
|
+
|
|
25
|
+
# Or use environment variable
|
|
26
|
+
# os.environ["CHANNEL3_API_KEY"] = "your_api_key"
|
|
27
|
+
# client = Channel3Client()
|
|
28
|
+
```
|
|
29
|
+
"""
|
|
30
|
+
self.api_key = api_key or os.getenv("CHANNEL3_API_KEY")
|
|
31
|
+
if not self.api_key:
|
|
32
|
+
raise ValueError("No API key provided for Channel3Client")
|
|
33
|
+
self.headers = {"x-api-key": self.api_key}
|
|
34
|
+
self.api_version = "v0"
|
|
35
|
+
self.base_url = f"https://api.channel3.com/{self.api_version}"
|
|
36
|
+
|
|
37
|
+
def search(
|
|
38
|
+
self,
|
|
39
|
+
query: Optional[str] = None,
|
|
40
|
+
image_url: Optional[str] = None,
|
|
41
|
+
base64_image: Optional[str] = None,
|
|
42
|
+
filters: Optional[Dict[str, Any]] = None,
|
|
43
|
+
limit: int = 20,
|
|
44
|
+
) -> List[Dict[str, Any]]:
|
|
45
|
+
"""
|
|
46
|
+
Search for products using text query, image, or both with optional filters.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
query: Text search query
|
|
50
|
+
image_url: URL to an image to use for visual search
|
|
51
|
+
base64_image: Base64-encoded image to use for visual search
|
|
52
|
+
filters: Dict containing optional filters with these possible keys:
|
|
53
|
+
- colors: List of color strings
|
|
54
|
+
- materials: List of material strings
|
|
55
|
+
- min_price: Minimum price (float)
|
|
56
|
+
- max_price: Maximum price (float)
|
|
57
|
+
limit: Maximum number of products to return (default: 20)
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
List of product dictionaries containing:
|
|
61
|
+
id, url, score, price, brand_id, brand_name, title, description, image_url, variants
|
|
62
|
+
|
|
63
|
+
Examples:
|
|
64
|
+
```python
|
|
65
|
+
# Text search
|
|
66
|
+
products = client.search(query="blue denim jacket")
|
|
67
|
+
|
|
68
|
+
# Image search
|
|
69
|
+
products = client.search(image_url="https://example.com/image.jpg")
|
|
70
|
+
|
|
71
|
+
# Multimodal search
|
|
72
|
+
products = client.search(
|
|
73
|
+
query="blue denim jacket",
|
|
74
|
+
base64_image="data:image/jpeg;base64,...",
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
# Search with filters
|
|
78
|
+
products = client.search(
|
|
79
|
+
query="running shoes",
|
|
80
|
+
filters={
|
|
81
|
+
"colors": ["black", "white"],
|
|
82
|
+
"min_price": 50.0,
|
|
83
|
+
"max_price": 150.0
|
|
84
|
+
},
|
|
85
|
+
limit=10
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
"""
|
|
89
|
+
payload = {
|
|
90
|
+
"query": query,
|
|
91
|
+
"image_url": image_url,
|
|
92
|
+
"base64_image": base64_image,
|
|
93
|
+
"limit": limit,
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if filters:
|
|
97
|
+
payload["filters"] = filters
|
|
98
|
+
|
|
99
|
+
response = requests.post(
|
|
100
|
+
f"{self.base_url}/search",
|
|
101
|
+
json={k: v for k, v in payload.items() if v is not None},
|
|
102
|
+
headers=self.headers,
|
|
103
|
+
)
|
|
104
|
+
response.raise_for_status()
|
|
105
|
+
return response.json()
|
|
106
|
+
|
|
107
|
+
def get_product(self, product_id: str) -> Dict[str, Any]:
|
|
108
|
+
"""
|
|
109
|
+
Get detailed information about a specific product by its ID.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
product_id: The unique identifier of the product
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
Dictionary containing detailed product information:
|
|
116
|
+
url, brand_id, brand_name, title, description, image_urls, variants,
|
|
117
|
+
price, gender, materials, key_features
|
|
118
|
+
|
|
119
|
+
Raises:
|
|
120
|
+
requests.HTTPError: If the product does not exist or other API errors occur
|
|
121
|
+
|
|
122
|
+
Example:
|
|
123
|
+
```python
|
|
124
|
+
product_detail = client.get_product("prod_123456")
|
|
125
|
+
print(product_detail["title"])
|
|
126
|
+
print(product_detail["price"]["price"])
|
|
127
|
+
```
|
|
128
|
+
"""
|
|
129
|
+
response = requests.get(
|
|
130
|
+
f"{self.base_url}/products/{product_id}",
|
|
131
|
+
headers=self.headers,
|
|
132
|
+
)
|
|
133
|
+
response.raise_for_status()
|
|
134
|
+
return response.json()
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: channel3-sdk
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: The API for AI Shopping
|
|
5
|
+
License: MIT
|
|
6
|
+
Author: Alex
|
|
7
|
+
Author-email: alex@trychannel3.com
|
|
8
|
+
Requires-Python: >=3.10,<4.0
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
15
|
+
Requires-Dist: requests (>=2.31.0,<3.0.0)
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
channel3_sdk/__init__.py,sha256=RTKSE_cJNdqeRdvb2ezu7o_Jje08I9zWE2p7w5OAk9s,35
|
|
2
|
+
channel3_sdk/client.py,sha256=UYTPzAf2HmJOLPi3lAdrL5GmO359zY-NkuWgbeo_ass,4496
|
|
3
|
+
channel3_sdk-0.0.1.dist-info/METADATA,sha256=zvI-DgEYvUWF-GHC0vSqGoevJm7KYHtzcNu-_GDnTsA,566
|
|
4
|
+
channel3_sdk-0.0.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
5
|
+
channel3_sdk-0.0.1.dist-info/RECORD,,
|