Barcodes API Wrapper for Python
Elevate your Python applications by seamlessly integrating with the Barcodes.GG API. Our Python SDK makes it easy, efficient, and user-friendly. Dive into the steps below and kick-start your barcode journey.
Prerequisites
Ensure your environment has the requests
library. If not, a quick pip installation does the trick:
pip install requests
SDK Wrapper Code
import requests
class BarcodesAPI:
def __init__(self, api_key):
self.api_key = api_key
self.base_url = "https://barcodes.gg/api"
def make_request(self, endpoint):
headers = {
"Authorization": f"Bearer {self.api_key}"
}
response = requests.get(self.base_url + endpoint, headers=headers)
return response.json()
def searchProducts(self, query):
return self.make_request(f"/product/search?query={query}")
def lookupBarcode(self, ean, show_data=1, fields='*'):
return self.make_request(f"/barcode/lookup/{ean}?show_data={show_data}&fields={fields}")
def getImage(self, style_code):
return self.make_request(f"/image/{style_code}")
def reverseLookupBySKU(self, sku, is_verified=1, page=1):
return self.make_request(f"/barcode/lookup/sku/{sku}?is_verified={is_verified}&page={page}")
Integration Steps
- Initialization: Set the stage by introducing the
BarcodesAPI
class.
api = BarcodesAPI('YOUR_API_KEY')
Make sure you replace 'YOUR_API_KEY'
with your authentic API key.
- Product Search: Embark on your product search journey with just a line of code.
print(api.searchProducts('dd1503-100'))
- Barcode Lookup: Unveil product details using its barcode.
print(api.lookupBarcode('195245980597'))
- Image Acquisition: Get your hands on product images using the style code.
print(api.getImage('DH4756-100'))
- SKU-based Reverse Barcode Lookup: Turn the tables by using SKU to fetch barcodes.
print(api.reverseLookupBySKU('DD1391-100'))
Each function returns the parsed JSON data, ensuring you have the freedom to process it further according to your needs.
Discover the power of barcodes with Python, and unlock a world of possibilities.