upcdatabase 0.1.0__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.
upcdatabase/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""UPC Database Python Library
|
|
2
|
+
|
|
3
|
+
A Python library for accessing the UPC Database API.
|
|
4
|
+
Access product information, search capabilities, and more.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.0"
|
|
8
|
+
__author__ = "Your Name"
|
|
9
|
+
__license__ = "MIT"
|
|
10
|
+
|
|
11
|
+
from .client import UPCDatabase, UPCDatabaseError
|
|
12
|
+
|
|
13
|
+
__all__ = ["UPCDatabase", "UPCDatabaseError"]
|
upcdatabase/client.py
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"""Main UPC Database API client"""
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, Optional
|
|
4
|
+
from urllib.parse import quote
|
|
5
|
+
|
|
6
|
+
import requests
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class UPCDatabaseError(Exception):
|
|
10
|
+
"""Base exception for UPC Database errors"""
|
|
11
|
+
|
|
12
|
+
pass
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class UPCDatabase:
|
|
16
|
+
"""Client for the UPC Database API
|
|
17
|
+
|
|
18
|
+
Provides access to product lookups, search, currency data, and more.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
api_key: Your UPC Database API key from https://upcdatabase.org/apikeys
|
|
22
|
+
|
|
23
|
+
Example:
|
|
24
|
+
>>> client = UPCDatabase(api_key="your_api_key")
|
|
25
|
+
>>> product = client.lookup("036000291204")
|
|
26
|
+
>>> print(product["name"])
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
BASE_URL = "https://api.upcdatabase.org"
|
|
30
|
+
|
|
31
|
+
def __init__(self, api_key: str):
|
|
32
|
+
"""Initialize the API client
|
|
33
|
+
|
|
34
|
+
Args:
|
|
35
|
+
api_key: Your UPC Database API key
|
|
36
|
+
|
|
37
|
+
Raises:
|
|
38
|
+
ValueError: If api_key is empty
|
|
39
|
+
"""
|
|
40
|
+
if not api_key:
|
|
41
|
+
raise ValueError("api_key cannot be empty")
|
|
42
|
+
|
|
43
|
+
self.api_key = api_key
|
|
44
|
+
self.session = requests.Session()
|
|
45
|
+
self.session.headers.update({"User-Agent": "upcdatabase-python/0.1.0"})
|
|
46
|
+
|
|
47
|
+
def _make_request(
|
|
48
|
+
self, endpoint: str, params: Optional[Dict[str, Any]] = None
|
|
49
|
+
) -> Dict[str, Any]:
|
|
50
|
+
"""Make an API request
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
endpoint: API endpoint path
|
|
54
|
+
params: Query parameters
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
Response JSON as dictionary
|
|
58
|
+
|
|
59
|
+
Raises:
|
|
60
|
+
UPCDatabaseError: If API returns an error
|
|
61
|
+
requests.RequestException: If network request fails
|
|
62
|
+
"""
|
|
63
|
+
url = f"{self.BASE_URL}{endpoint}"
|
|
64
|
+
|
|
65
|
+
# Add API key to params
|
|
66
|
+
if params is None:
|
|
67
|
+
params = {}
|
|
68
|
+
params["key"] = self.api_key
|
|
69
|
+
|
|
70
|
+
try:
|
|
71
|
+
response = self.session.get(url, params=params, timeout=10)
|
|
72
|
+
response.raise_for_status()
|
|
73
|
+
return response.json()
|
|
74
|
+
except requests.exceptions.HTTPError as e:
|
|
75
|
+
raise UPCDatabaseError(
|
|
76
|
+
f"API request failed: {e.response.status_code} - {e.response.text}"
|
|
77
|
+
)
|
|
78
|
+
except requests.exceptions.RequestException as e:
|
|
79
|
+
raise UPCDatabaseError(f"Request failed: {str(e)}")
|
|
80
|
+
|
|
81
|
+
def lookup(self, upc: str) -> Dict[str, Any]:
|
|
82
|
+
"""Look up a product by UPC/EAN code
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
upc: The UPC or EAN code to lookup
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
Dict containing product information with keys:
|
|
89
|
+
- success (bool): Request success status
|
|
90
|
+
- barcode (str): Product barcode/UPC
|
|
91
|
+
- title (str): Product name
|
|
92
|
+
- alias (str): Product short name
|
|
93
|
+
- description (str): Product description
|
|
94
|
+
- brand (str): Brand name
|
|
95
|
+
- manufacturer (str): Manufacturer name
|
|
96
|
+
- mpn (str): Manufacturer part number
|
|
97
|
+
- msrp (str): Suggested retail price
|
|
98
|
+
- ASIN (str): Amazon identifier
|
|
99
|
+
- category (str): Product category
|
|
100
|
+
- metadata (dict): Additional product metadata
|
|
101
|
+
- stores (list): Retail store information
|
|
102
|
+
- images (list): Product images
|
|
103
|
+
- reviews (dict): Review ratings
|
|
104
|
+
|
|
105
|
+
Example:
|
|
106
|
+
>>> product = client.lookup("036000291204")
|
|
107
|
+
>>> print(product["title"])
|
|
108
|
+
>>> print(product["manufacturer"])
|
|
109
|
+
>>> print(product["msrp"])
|
|
110
|
+
|
|
111
|
+
Raises:
|
|
112
|
+
UPCDatabaseError: If lookup fails or product not found
|
|
113
|
+
"""
|
|
114
|
+
return self._make_request(f"/product/{quote(upc)}")
|
|
115
|
+
|
|
116
|
+
def search(self, query: str, limit: int = 10) -> Dict[str, Any]:
|
|
117
|
+
"""Search for products
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
query: Search query string
|
|
121
|
+
limit: Maximum number of results (default: 10)
|
|
122
|
+
|
|
123
|
+
Returns:
|
|
124
|
+
Dict containing search results with keys:
|
|
125
|
+
- success (bool): Request success status
|
|
126
|
+
- timestamp (int): Unix timestamp
|
|
127
|
+
- results (int): Number of results found
|
|
128
|
+
- items (list): List of product dicts (barcode, title, alias, description)
|
|
129
|
+
|
|
130
|
+
Example:
|
|
131
|
+
>>> results = client.search("coca cola")
|
|
132
|
+
>>> print(f"Found {results['results']} results")
|
|
133
|
+
>>> for item in results.get("items", []):
|
|
134
|
+
... print(f"{item['title']} - {item['barcode']}")
|
|
135
|
+
|
|
136
|
+
Raises:
|
|
137
|
+
UPCDatabaseError: If search fails
|
|
138
|
+
"""
|
|
139
|
+
params = {"s": query, "limit": limit}
|
|
140
|
+
return self._make_request("/search", params=params)
|
|
141
|
+
|
|
142
|
+
def get_latest_currency(self) -> Dict[str, Any]:
|
|
143
|
+
"""Get latest currency exchange rates
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
Dict containing currency rates with keys:
|
|
147
|
+
- success (bool): Request success status
|
|
148
|
+
- date (str): Date of rates
|
|
149
|
+
- timestamp (int): Unix timestamp
|
|
150
|
+
- base (str): Base currency code
|
|
151
|
+
- rates (dict): Currency codes mapped to exchange rates (float)
|
|
152
|
+
|
|
153
|
+
Example:
|
|
154
|
+
>>> rates = client.get_latest_currency()
|
|
155
|
+
>>> print(f"USD/EUR: {rates['rates']['EUR']}")
|
|
156
|
+
|
|
157
|
+
Raises:
|
|
158
|
+
UPCDatabaseError: If request fails
|
|
159
|
+
"""
|
|
160
|
+
return self._make_request("/currency/latest")
|
|
161
|
+
|
|
162
|
+
def get_currency_history(self, date: str) -> Dict[str, Any]:
|
|
163
|
+
"""Get historical currency exchange rates
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
date: Date in YYYY-MM-DD format
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
Dict containing historical currency rates with keys:
|
|
170
|
+
- success (bool): Request success status
|
|
171
|
+
- date (str): Date of rates
|
|
172
|
+
- timestamp (int): Unix timestamp
|
|
173
|
+
- base (str): Base currency code
|
|
174
|
+
- rates (dict): Currency codes mapped to exchange rates (float)
|
|
175
|
+
|
|
176
|
+
Example:
|
|
177
|
+
>>> history = client.get_currency_history("2025-01-15")
|
|
178
|
+
>>> print(f"On 2025-01-15, USD/EUR was {history['rates']['EUR']}")
|
|
179
|
+
|
|
180
|
+
Raises:
|
|
181
|
+
UPCDatabaseError: If request fails
|
|
182
|
+
"""
|
|
183
|
+
params = {"date": date}
|
|
184
|
+
return self._make_request("/currency/history", params=params)
|
|
185
|
+
|
|
186
|
+
def get_currency_symbols(self) -> Dict[str, Any]:
|
|
187
|
+
"""Get list of supported currency symbols
|
|
188
|
+
|
|
189
|
+
Returns:
|
|
190
|
+
Dict containing currency symbols with keys:
|
|
191
|
+
- success (bool): Request success status
|
|
192
|
+
- timestamp (int): Unix timestamp
|
|
193
|
+
- symbols (dict): Currency codes mapped to full names
|
|
194
|
+
|
|
195
|
+
Example:
|
|
196
|
+
>>> symbols = client.get_currency_symbols()
|
|
197
|
+
>>> print(symbols["symbols"]["USD"])
|
|
198
|
+
|
|
199
|
+
Raises:
|
|
200
|
+
UPCDatabaseError: If request fails
|
|
201
|
+
"""
|
|
202
|
+
return self._make_request("/currency/symbols")
|
|
203
|
+
|
|
204
|
+
def get_latest_bitcoin(self) -> Dict[str, Any]:
|
|
205
|
+
"""Get latest Bitcoin exchange rate
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
Dict containing Bitcoin rates with keys:
|
|
209
|
+
- success (bool): Request success status
|
|
210
|
+
- timestamp (int): Unix timestamp
|
|
211
|
+
- date (str): Current date
|
|
212
|
+
- base (str): Base currency (USD)
|
|
213
|
+
- rates (dict): Bitcoin rates with high, low, latest (string values)
|
|
214
|
+
|
|
215
|
+
Example:
|
|
216
|
+
>>> btc = client.get_latest_bitcoin()
|
|
217
|
+
>>> print(f"BTC latest: ${btc['rates']['latest']}")
|
|
218
|
+
|
|
219
|
+
Raises:
|
|
220
|
+
UPCDatabaseError: If request fails
|
|
221
|
+
"""
|
|
222
|
+
return self._make_request("/bitcoin/latest")
|
|
223
|
+
|
|
224
|
+
def get_bitcoin_history(self, date: str) -> Dict[str, Any]:
|
|
225
|
+
"""Get historical Bitcoin exchange rate
|
|
226
|
+
|
|
227
|
+
Args:
|
|
228
|
+
date: Date in YYYY-MM-DD format
|
|
229
|
+
|
|
230
|
+
Returns:
|
|
231
|
+
Dict containing historical Bitcoin rates with keys:
|
|
232
|
+
- success (bool): Request success status
|
|
233
|
+
- timestamp (int): Unix timestamp
|
|
234
|
+
- date (str): Date of rates
|
|
235
|
+
- base (str): Base currency (USD)
|
|
236
|
+
- rates (dict): Bitcoin rates with high, low, close (string values)
|
|
237
|
+
|
|
238
|
+
Example:
|
|
239
|
+
>>> btc_history = client.get_bitcoin_history("2025-01-15")
|
|
240
|
+
>>> print(f"BTC high: ${btc_history['rates']['high']}")
|
|
241
|
+
|
|
242
|
+
Raises:
|
|
243
|
+
UPCDatabaseError: If request fails
|
|
244
|
+
"""
|
|
245
|
+
params = {"date": date}
|
|
246
|
+
return self._make_request("/bitcoin/history", params=params)
|
|
247
|
+
|
|
248
|
+
def generate_qr(self, text: str) -> Dict[str, Any]:
|
|
249
|
+
"""Generate a QR code
|
|
250
|
+
|
|
251
|
+
Args:
|
|
252
|
+
text: Text/data to encode in the QR code
|
|
253
|
+
|
|
254
|
+
Returns:
|
|
255
|
+
PNG image binary data as response (Content-Type: image/png)
|
|
256
|
+
|
|
257
|
+
Example:
|
|
258
|
+
>>> qr = client.generate_qr("https://example.com")
|
|
259
|
+
>>> # Returns PNG image data
|
|
260
|
+
|
|
261
|
+
Raises:
|
|
262
|
+
UPCDatabaseError: If QR generation fails
|
|
263
|
+
"""
|
|
264
|
+
import base64
|
|
265
|
+
|
|
266
|
+
encoded_text = base64.b64encode(text.encode()).decode()
|
|
267
|
+
return self._make_request(f"/qr/{encoded_text}")
|
|
268
|
+
|
|
269
|
+
def get_account_info(self) -> Dict[str, Any]:
|
|
270
|
+
"""Get account information
|
|
271
|
+
|
|
272
|
+
Returns:
|
|
273
|
+
Dict containing account information with keys:
|
|
274
|
+
- success (bool): Request success status
|
|
275
|
+
- email (str): Account email
|
|
276
|
+
- registered (int): Registration timestamp
|
|
277
|
+
- active (int): Active timestamp
|
|
278
|
+
- score (str): Account score
|
|
279
|
+
- banned (bool): Account ban status
|
|
280
|
+
- apikey_count (str): Number of API keys
|
|
281
|
+
- products (dict): Added and modified product counts
|
|
282
|
+
- api_subscription (dict): Subscription details
|
|
283
|
+
- api_limits (dict): API rate limits
|
|
284
|
+
- api_remain (dict): Remaining API requests
|
|
285
|
+
- api_requests (str): Total API requests made
|
|
286
|
+
- timestamp (int): Current timestamp
|
|
287
|
+
|
|
288
|
+
Example:
|
|
289
|
+
>>> account = client.get_account_info()
|
|
290
|
+
>>> print(f"Lookups remaining: {account['api_remain']['lookups']}")
|
|
291
|
+
|
|
292
|
+
Raises:
|
|
293
|
+
UPCDatabaseError: If request fails
|
|
294
|
+
"""
|
|
295
|
+
return self._make_request("/account")
|
|
296
|
+
|
|
297
|
+
def __enter__(self):
|
|
298
|
+
"""Context manager entry"""
|
|
299
|
+
return self
|
|
300
|
+
|
|
301
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
302
|
+
"""Context manager exit"""
|
|
303
|
+
self.session.close()
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: upcdatabase
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python library for accessing the UPC Database API
|
|
5
|
+
Author-email: Your Name <your.email@example.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Nickatak/upcdatabase
|
|
8
|
+
Project-URL: Repository, https://github.com/Nickatak/upcdatabase.git
|
|
9
|
+
Project-URL: Documentation, https://github.com/Nickatak/upcdatabase#readme
|
|
10
|
+
Project-URL: Issues, https://github.com/Nickatak/upcdatabase/issues
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.7
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: requests>=2.25.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=6.0.0; extra == "dev"
|
|
27
|
+
Requires-Dist: pytest-cov>=2.12.0; extra == "dev"
|
|
28
|
+
Requires-Dist: pylint>=2.8.0; extra == "dev"
|
|
29
|
+
Requires-Dist: black>=21.0; extra == "dev"
|
|
30
|
+
Requires-Dist: isort>=5.0.0; extra == "dev"
|
|
31
|
+
Requires-Dist: mypy>=0.900; extra == "dev"
|
|
32
|
+
Requires-Dist: pre-commit>=2.20.0; extra == "dev"
|
|
33
|
+
Dynamic: license-file
|
|
34
|
+
|
|
35
|
+
# upcdatabase
|
|
36
|
+
|
|
37
|
+
A Python library for accessing the [UPC Database API](https://upcdatabase.org/). Look up product information by UPC/EAN code, search for products, access currency and Bitcoin data, and more.
|
|
38
|
+
|
|
39
|
+
## Features
|
|
40
|
+
|
|
41
|
+
- **Product Lookup**: Find product information by UPC or EAN code
|
|
42
|
+
- **Search**: Search for products by name or query
|
|
43
|
+
- **Currency Data**: Get latest and historical currency exchange rates
|
|
44
|
+
- **Bitcoin Data**: Access Bitcoin exchange rate information
|
|
45
|
+
- **QR Code Generation**: Generate QR codes programmatically
|
|
46
|
+
- **Account Management**: Access your API account information
|
|
47
|
+
|
|
48
|
+
## Installation
|
|
49
|
+
|
|
50
|
+
Install from PyPI:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install upcdatabase
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Project Structure
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
upcdatabase/
|
|
60
|
+
├── src/upcdatabase/
|
|
61
|
+
│ ├── __init__.py # Package initialization and exports
|
|
62
|
+
│ └── client.py # Main UPCDatabase API client
|
|
63
|
+
├── tests/
|
|
64
|
+
│ ├── __init__.py
|
|
65
|
+
│ └── test_client.py # Unit tests (17 tests, 100% coverage)
|
|
66
|
+
├── examples.py # Usage examples for all endpoints
|
|
67
|
+
├── README.md # Main documentation
|
|
68
|
+
├── QUICKSTART.md # Quick start guide
|
|
69
|
+
├── CONTRIBUTING.md # Contribution guidelines
|
|
70
|
+
├── PUBLISHING.md # PyPI publishing guide
|
|
71
|
+
├── pyproject.toml # Project configuration and metadata
|
|
72
|
+
├── .pre-commit-config.yaml # Pre-commit hooks (linting, formatting, tests)
|
|
73
|
+
└── requirements-dev.txt # Development dependencies
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Quick Start
|
|
77
|
+
|
|
78
|
+
First, you'll need an API key from [UPC Database](https://upcdatabase.org/):
|
|
79
|
+
|
|
80
|
+
1. Create a free account at https://upcdatabase.org/signup
|
|
81
|
+
2. Register your application at https://upcdatabase.org/apikeys to get your API key
|
|
82
|
+
|
|
83
|
+
Then use the library:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from upcdatabase import UPCDatabase
|
|
87
|
+
|
|
88
|
+
# Initialize the client
|
|
89
|
+
client = UPCDatabase(api_key="your_api_key_here")
|
|
90
|
+
|
|
91
|
+
# Look up a product by UPC
|
|
92
|
+
product = client.lookup("036000291204")
|
|
93
|
+
print(product["name"])
|
|
94
|
+
print(product["price"])
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Usage Examples
|
|
98
|
+
|
|
99
|
+
### Product Lookup
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from upcdatabase import UPCDatabase
|
|
103
|
+
|
|
104
|
+
client = UPCDatabase(api_key="your_api_key")
|
|
105
|
+
|
|
106
|
+
# Look up by UPC code
|
|
107
|
+
product = client.lookup("036000291204")
|
|
108
|
+
print(f"Product: {product['name']}")
|
|
109
|
+
print(f"Manufacturer: {product['manufacturer']}")
|
|
110
|
+
print(f"Price: ${product['price']}")
|
|
111
|
+
print(f"Image: {product['image']}")
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Search Products
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
# Search for products
|
|
118
|
+
results = client.search("coca cola", limit=20)
|
|
119
|
+
for item in results.get("items", []):
|
|
120
|
+
print(f"{item['name']} - {item['upc']}")
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Get Currency Data
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
# Latest currency rates
|
|
127
|
+
rates = client.get_latest_currency()
|
|
128
|
+
print(rates)
|
|
129
|
+
|
|
130
|
+
# Historical rates
|
|
131
|
+
history = client.get_currency_history("2025-01-15")
|
|
132
|
+
print(history)
|
|
133
|
+
|
|
134
|
+
# Available symbols
|
|
135
|
+
symbols = client.get_currency_symbols()
|
|
136
|
+
print(symbols)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Get Bitcoin Data
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
# Latest Bitcoin rate
|
|
143
|
+
btc = client.get_latest_bitcoin()
|
|
144
|
+
print(f"BTC: ${btc['price']}")
|
|
145
|
+
|
|
146
|
+
# Historical Bitcoin rate
|
|
147
|
+
btc_history = client.get_bitcoin_history("2025-01-15")
|
|
148
|
+
print(btc_history)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Generate QR Codes
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
# Generate a QR code
|
|
155
|
+
qr = client.generate_qr("https://example.com")
|
|
156
|
+
print(qr)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Get Account Information
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
# Check account and API usage
|
|
163
|
+
account = client.get_account_info()
|
|
164
|
+
print(f"Requests remaining: {account['requests_remaining']}")
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Using as a Context Manager
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from upcdatabase import UPCDatabase
|
|
171
|
+
|
|
172
|
+
# The session will be automatically closed when exiting the block
|
|
173
|
+
with UPCDatabase(api_key="your_api_key") as client:
|
|
174
|
+
product = client.lookup("036000291204")
|
|
175
|
+
print(product["name"])
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Error Handling
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from upcdatabase import UPCDatabase, UPCDatabaseError
|
|
182
|
+
|
|
183
|
+
client = UPCDatabase(api_key="your_api_key")
|
|
184
|
+
|
|
185
|
+
try:
|
|
186
|
+
product = client.lookup("invalid_code")
|
|
187
|
+
except UPCDatabaseError as e:
|
|
188
|
+
print(f"Error: {e}")
|
|
189
|
+
except Exception as e:
|
|
190
|
+
print(f"Unexpected error: {e}")
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## API Documentation
|
|
194
|
+
|
|
195
|
+
For detailed API documentation, visit:
|
|
196
|
+
- [API Reference](https://upcdatabase.org/api)
|
|
197
|
+
- [Authentication](https://upcdatabase.org/api-auth)
|
|
198
|
+
- [API Limits](https://upcdatabase.org/api-limits)
|
|
199
|
+
- [Pricing](https://upcdatabase.org/api-pricing)
|
|
200
|
+
|
|
201
|
+
## Documentation
|
|
202
|
+
|
|
203
|
+
### Client Methods
|
|
204
|
+
|
|
205
|
+
#### `lookup(upc: str) -> dict`
|
|
206
|
+
Look up a product by UPC or EAN code.
|
|
207
|
+
|
|
208
|
+
**Parameters:**
|
|
209
|
+
- `upc` (str): The UPC or EAN code to lookup
|
|
210
|
+
|
|
211
|
+
**Returns:** Product information dictionary
|
|
212
|
+
|
|
213
|
+
**Raises:** `UPCDatabaseError` if lookup fails
|
|
214
|
+
|
|
215
|
+
#### `search(query: str, limit: int = 10) -> dict`
|
|
216
|
+
Search for products by name or query.
|
|
217
|
+
|
|
218
|
+
**Parameters:**
|
|
219
|
+
- `query` (str): Search query string
|
|
220
|
+
- `limit` (int): Maximum number of results (default: 10)
|
|
221
|
+
|
|
222
|
+
**Returns:** Search results dictionary
|
|
223
|
+
|
|
224
|
+
#### `get_latest_currency() -> dict`
|
|
225
|
+
Get latest currency exchange rates.
|
|
226
|
+
|
|
227
|
+
#### `get_currency_history(date: str) -> dict`
|
|
228
|
+
Get historical currency rates for a specific date.
|
|
229
|
+
|
|
230
|
+
**Parameters:**
|
|
231
|
+
- `date` (str): Date in YYYY-MM-DD format
|
|
232
|
+
|
|
233
|
+
#### `get_currency_symbols() -> dict`
|
|
234
|
+
Get list of supported currency symbols.
|
|
235
|
+
|
|
236
|
+
#### `get_latest_bitcoin() -> dict`
|
|
237
|
+
Get latest Bitcoin exchange rate.
|
|
238
|
+
|
|
239
|
+
#### `get_bitcoin_history(date: str) -> dict`
|
|
240
|
+
Get historical Bitcoin rate for a specific date.
|
|
241
|
+
|
|
242
|
+
#### `generate_qr(text: str) -> dict`
|
|
243
|
+
Generate a QR code from text/data.
|
|
244
|
+
|
|
245
|
+
**Parameters:**
|
|
246
|
+
- `text` (str): Text to encode in the QR code
|
|
247
|
+
|
|
248
|
+
#### `get_account_info() -> dict`
|
|
249
|
+
Get account and API usage information.
|
|
250
|
+
|
|
251
|
+
## Requirements
|
|
252
|
+
|
|
253
|
+
- Python 3.7+
|
|
254
|
+
- `requests` library
|
|
255
|
+
|
|
256
|
+
## License
|
|
257
|
+
|
|
258
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
259
|
+
|
|
260
|
+
## Contributing
|
|
261
|
+
|
|
262
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
263
|
+
|
|
264
|
+
## Disclaimer
|
|
265
|
+
|
|
266
|
+
This library is not affiliated with or endorsed by UPC Database. It is an independent client library for accessing the public UPC Database API.
|
|
267
|
+
|
|
268
|
+
## Support
|
|
269
|
+
|
|
270
|
+
For issues, questions, or suggestions, please open an issue on the GitHub repository.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
upcdatabase/__init__.py,sha256=1-ZruaH5AORYizxF6_og3iZB37NhzgP1yyY5qKyyHUc,314
|
|
2
|
+
upcdatabase/client.py,sha256=JdBYICjbOSN3xAJZ0nqgk_I6m6ngynMziTdzscKLrR8,10268
|
|
3
|
+
upcdatabase-0.1.0.dist-info/licenses/LICENSE,sha256=ESYyLizI0WWtxMeS7rGVcX3ivMezm-HOd5WdeOh-9oU,1056
|
|
4
|
+
upcdatabase-0.1.0.dist-info/METADATA,sha256=Y-DXjqYmId1LvXkkQTVUG9HdVObeY7WhiM5qEUZk-pE,7330
|
|
5
|
+
upcdatabase-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
+
upcdatabase-0.1.0.dist-info/top_level.txt,sha256=Ef3xtkbmZuPiVGkQ192Nwt3vfCCG7mX12cDKKTpopTQ,12
|
|
7
|
+
upcdatabase-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
upcdatabase
|