Python library for accessing the UPC Database API
Project description
upcdatabase
A Python library for accessing the UPC Database API. Look up product information by UPC/EAN code, search for products, access currency and Bitcoin data, and more.
Features
- Product Lookup: Find product information by UPC or EAN code
- Search: Search for products by name or query
- Currency Data: Get latest and historical currency exchange rates
- Bitcoin Data: Access Bitcoin exchange rate information
- QR Code Generation: Generate QR codes programmatically
- Account Management: Access your API account information
Installation
Install from PyPI:
pip install upcdatabase
Project Structure
upcdatabase/
├── src/upcdatabase/
│ ├── __init__.py # Package initialization and exports
│ └── client.py # Main UPCDatabase API client
├── tests/
│ ├── __init__.py
│ └── test_client.py # Unit tests (17 tests, 100% coverage)
├── examples.py # Usage examples for all endpoints
├── README.md # Main documentation
├── QUICKSTART.md # Quick start guide
├── CONTRIBUTING.md # Contribution guidelines
├── PUBLISHING.md # PyPI publishing guide
├── pyproject.toml # Project configuration and metadata
├── .pre-commit-config.yaml # Pre-commit hooks (linting, formatting, tests)
└── requirements-dev.txt # Development dependencies
Quick Start
First, you'll need an API key from UPC Database:
- Create a free account at https://upcdatabase.org/signup
- Register your application at https://upcdatabase.org/apikeys to get your API key
Then use the library:
from upcdatabase import UPCDatabase
# Initialize the client
client = UPCDatabase(api_key="your_api_key_here")
# Look up a product by UPC
product = client.lookup("036000291204")
print(product["name"])
print(product["price"])
Usage Examples
Product Lookup
from upcdatabase import UPCDatabase
client = UPCDatabase(api_key="your_api_key")
# Look up by UPC code
product = client.lookup("036000291204")
print(f"Product: {product['name']}")
print(f"Manufacturer: {product['manufacturer']}")
print(f"Price: ${product['price']}")
print(f"Image: {product['image']}")
Search Products
# Search for products
results = client.search("coca cola", limit=20)
for item in results.get("items", []):
print(f"{item['name']} - {item['upc']}")
Get Currency Data
# Latest currency rates
rates = client.get_latest_currency()
print(rates)
# Historical rates
history = client.get_currency_history("2025-01-15")
print(history)
# Available symbols
symbols = client.get_currency_symbols()
print(symbols)
Get Bitcoin Data
# Latest Bitcoin rate
btc = client.get_latest_bitcoin()
print(f"BTC: ${btc['price']}")
# Historical Bitcoin rate
btc_history = client.get_bitcoin_history("2025-01-15")
print(btc_history)
Generate QR Codes
# Generate a QR code
qr = client.generate_qr("https://example.com")
print(qr)
Get Account Information
# Check account and API usage
account = client.get_account_info()
print(f"Requests remaining: {account['requests_remaining']}")
Using as a Context Manager
from upcdatabase import UPCDatabase
# The session will be automatically closed when exiting the block
with UPCDatabase(api_key="your_api_key") as client:
product = client.lookup("036000291204")
print(product["name"])
Error Handling
from upcdatabase import UPCDatabase, UPCDatabaseError
client = UPCDatabase(api_key="your_api_key")
try:
product = client.lookup("invalid_code")
except UPCDatabaseError as e:
print(f"Error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
API Documentation
For detailed API documentation, visit:
Documentation
Client Methods
lookup(upc: str) -> dict
Look up a product by UPC or EAN code.
Parameters:
upc(str): The UPC or EAN code to lookup
Returns: Product information dictionary
Raises: UPCDatabaseError if lookup fails
search(query: str, limit: int = 10) -> dict
Search for products by name or query.
Parameters:
query(str): Search query stringlimit(int): Maximum number of results (default: 10)
Returns: Search results dictionary
get_latest_currency() -> dict
Get latest currency exchange rates.
get_currency_history(date: str) -> dict
Get historical currency rates for a specific date.
Parameters:
date(str): Date in YYYY-MM-DD format
get_currency_symbols() -> dict
Get list of supported currency symbols.
get_latest_bitcoin() -> dict
Get latest Bitcoin exchange rate.
get_bitcoin_history(date: str) -> dict
Get historical Bitcoin rate for a specific date.
generate_qr(text: str) -> dict
Generate a QR code from text/data.
Parameters:
text(str): Text to encode in the QR code
get_account_info() -> dict
Get account and API usage information.
Requirements
- Python 3.7+
requestslibrary
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Disclaimer
This library is not affiliated with or endorsed by UPC Database. It is an independent client library for accessing the public UPC Database API.
Support
For issues, questions, or suggestions, please open an issue on the GitHub repository.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file upcdatabase-0.1.2.tar.gz.
File metadata
- Download URL: upcdatabase-0.1.2.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba14ec9cf515daa2e45ba0abf5810ac0c9e49d9d38b4bd15f984a09811ab2bb1
|
|
| MD5 |
7766a9f4ed59a9b39d40f546a4382019
|
|
| BLAKE2b-256 |
adc625cc08e1eab6c62e3ed1951c3cab18d5256e2df8ef115f7baf78c6803611
|
File details
Details for the file upcdatabase-0.1.2-py3-none-any.whl.
File metadata
- Download URL: upcdatabase-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d23727e66fb419ce977011b70fa9b55c5c6d3fd2f02f7e96ec6383ed72dd62ed
|
|
| MD5 |
aeec94fbbffba53df89d0fb7bf41e907
|
|
| BLAKE2b-256 |
a932cd1248f4f1932a604a4ed105b4dee587816eb51adfecee620ef926d2c250
|