Skip to main content

Interfaces with keepa.com

Project description

https://img.shields.io/pypi/v/keepa.svg?logo=python&logoColor=white https://travis-ci.org/akaszynski/keepa.svg?branch=master Documentation Status https://codecov.io/gh/akaszynski/keepa/branch/master/graph/badge.svg

Python module to interface to Keepa to query for Amazon product information and history.

Documentation can be found on readthedocs at keepa Documentation.

Requirements

Module is compatible with Python >= 3.5 . keepa requires:

  • numpy

  • aiohttp

  • matplotlib

  • tqdm

Product history can be plotted from the raw data when matplotlib is installed.

Interfacing with the keepa requires an access key and a monthly subscription from Keepa API

Installation

Module can be installed from PyPi with:

pip install keepa

Source code can also be downloaded from GitHub and installed using python setup.py install or pip install .

Brief Example

import keepa
accesskey = 'XXXXXXXXXXXXXXXX' # enter real access key here
api = keepa.Keepa(accesskey)

# Single ASIN query
products = api.query('B0088PUEPK') # returns list of product data

# Plot result (requires matplotlib)
keepa.plot_product(products[0])
https://github.com/akaszynski/keepa/raw/master/docs/source/images/Product_Price_Plot.png

Product Price Plot

https://github.com/akaszynski/keepa/raw/master/docs/source/images/Product_Offer_Plot.png

Product Offers Plot

Detailed Example

Import interface and establish connection to server

import keepa
accesskey = 'XXXXXXXXXXXXXXXX' # enter real access key here
api = keepa.Keepa(accesskey)

Single ASIN query

products = api.query('059035342X')

# See help(api.query) for available options when querying the API

You can use keepa witch async / await too

import keepa
accesskey = 'XXXXXXXXXXXXXXXX' # enter real access key here
api = await keepa.AsyncKeepa.create(accesskey)

Single ASIN query (async)

products = await api.query('059035342X')

Multiple ASIN query from List

asins = ['0022841350', '0022841369', '0022841369', '0022841369']
products = api.query(asins)

Multiple ASIN query from numpy array

asins = np.asarray(['0022841350', '0022841369', '0022841369', '0022841369'])
products = api.query(asins)

Products is a list of product data with one entry per successful result from the Keepa server. Each entry is a dictionary containing the same product data available from Amazon.

# Available keys
print(products[0].keys())

# Print ASIN and title
print('ASIN is ' + products[0]['asin'])
print('Title is ' + products[0]['title'])

The raw data is contained within each product result. Raw data is stored as a dictionary with each key paired with its associated time history.

# Access new price history and associated time data
newprice = products[0]['data']['NEW']
newpricetime = products[0]['data']['NEW_time']

# Can be plotted with matplotlib using:
import matplotlib.pyplot as plt
plt.step(newpricetime, newprice, where='pre')

# Keys can be listed by
print(products[0]['data'].keys())

The product history can also be plotted from the module if matplotlib is installed

keepa.plot_product(products[0])

You can obtain the offers history for an ASIN (or multiple ASINs) using the offers parameter. See the documentation at Request Products for further details.

products = api.query(asins, offers=20)
product = products[0]
offers = product['offers']

# each offer contains the price history of each offer
offer = offers[0]
csv = offer['offerCSV']

# convert these values to numpy arrays
times, prices = keepa.convert_offer_history(csv)

# for a list of active offers, see
indices = product['liveOffersOrder']

# with this you can loop through active offers:
indices = product['liveOffersOrder']
offer_times = []
offer_prices = []
for index in indices:
    csv = offers[index]['offerCSV']
    times, prices = keepa.convert_offer_history(csv)
    offer_times.append(times)
    offer_prices.append(prices)

# you can aggregate these using np.hstack or plot at the history individually
import matplotlib.pyplot as plt
for i in range(len(offer_prices)):
    plt.step(offer_times[i], offer_prices[i])
plt.show()

Credits

This Python code, written by Alex Kaszynski, is based on Java code written by Marius Johann, CEO keepa. Java source is can be found at api_backend.

License

Apache License, please see license file. Work is credited to both Alex Kaszynski and Marius Johann.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keepa-1.0.0.tar.gz (26.5 kB view details)

Uploaded Source

File details

Details for the file keepa-1.0.0.tar.gz.

File metadata

  • Download URL: keepa-1.0.0.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.1.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

File hashes

Hashes for keepa-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c7c2bab70da3469de5bb9357ca0baeb8d0b015221e13eb12d15b3675fe7f42b2
MD5 0e2e4359ac2953f8035b2967faa05c1c
BLAKE2b-256 0e38830a0aafbe0eaf49884c68e12f5b3b5ba50b7af08fef38d0ade0ea3e4f81

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page