Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

Interfaces with keepa.com

Project description

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

Requirements

Module is compatible with Python 2 and 3. keepaAPI requires:

  • numpy
  • requests

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

Interfacing with the keepaAPI requires an accesskey and a monthly subscription from https://keepa.com/#!api

Installation

Module can be installed from PyPi using pip install keepaAPI

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

Brief Example

import keepaAPI
accesskey = 'XXXXXXXXXXXXXXXX' # enter real access key here
api = keepaAPI.API(accesskey)

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

# Plot result (requires matplotlib)
keepaAPI.PlotProduct(products[0])

Detailed Example

Import interface and establish connection to server

import keepaAPI
accesskey = 'XXXXXXXXXXXXXXXX' # enter real access key here
api = keepaAPI.API(accesskey)

Single ASIN query

products = api.ProductQuery('059035342X')

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

Multiple ASIN query from List

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

Multiple ASIN query from numpy array

asins = np.asarray(['0022841350', '0022841369', '0022841369', '0022841369'])
products = api.ProductQuery(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 dictonary 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

keepaAPI.PlotProduct(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.ProductQuery(asins)
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 = ConvertOfferHistory(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 = keepaAPI.ConvertOfferHistory(csv)
    offer_times.append(times)
    offer_prices.append(prices)

# you can aggregrate 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 writen by Marius Johann, CEO keepa. Java source is can be found at https://github.com/keepacom/api_backend/

License

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

Project details


Release history Release notifications

This version
History Node

0.15.5

History Node

0.15.4

History Node

0.15.3

History Node

0.15.2

History Node

0.15.1

History Node

0.15.0

History Node

0.14.2

History Node

0.14.1

History Node

0.14

History Node

0.13.3

History Node

0.13.2

History Node

0.12

History Node

0.11

History Node

0.10.1

History Node

0.10.0

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
keepaAPI-0.15.5.tar.gz (14.3 kB) Copy SHA256 hash SHA256 Source None Jun 18, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page