Package: keepa
This Python library allows you to interface with the API atKeepato query for Amazon product information and
history.  It also contains a plotting module to allow for plotting of
a product.See API pricing atKeepa API.Documentation can be found on readthedocs atkeepa Documentation.RequirementsThis library is compatible with Python >= 3.8 and requires:numpyaiohttpmatplotlibtqdmProduct history can be plotted from the raw data whenmatplotlibis installed.Interfacing with thekeeparequires an access key and a monthly
subscription fromKeepa API.InstallationModule can be installed fromPyPiwith:pip install keepaSource code can also be downloaded fromGitHuband installed using:cd keepa
pip install .Brief Exampleimportkeepaaccesskey='XXXXXXXXXXXXXXXX'# enter real access key hereapi=keepa.Keepa(accesskey)# Single ASIN queryproducts=api.query('B0088PUEPK')# returns list of product data# Plot result (requires matplotlib)keepa.plot_product(products[0])Product Price PlotProduct Offers PlotBrief Example using asyncHere’s an example of obtaining a product and plotting its price and
offer history using thekeepa.AsyncKeepaclass:>>>importasyncio>>>importkeepa>>>product_parms={'author':'jim butcher'}>>>asyncdefmain():...key='<REAL_KEEPA_KEY>'...api=awaitkeepa.AsyncKeepa().create(key)...returnawaitapi.product_finder(product_parms)>>>asins=asyncio.run(main())>>>asins['B000HRMAR2','0578799790','B07PW1SVHM',...'B003MXM744','0133235750','B01MXXLJPZ']Query for product with ASIN'B0088PUEPK'using the asynchronous
keepa interface.>>>importasyncio>>>importkeepa>>>asyncdefmain():...key='<REAL_KEEPA_KEY>'...api=awaitkeepa.AsyncKeepa().create(key)...returnawaitapi.query('B0088PUEPK')>>>response=asyncio.run(main())>>>response[0]['title']'Western Digital 1TB WD Blue PC Internal Hard Drive HDD - 7200 RPM,SATA6Gb/s,64MBCache,3.5" - WD10EZEX'Detailed ExamplesImport interface and establish connection to serverimportkeepaaccesskey='XXXXXXXXXXXXXXXX'# enter real access key hereapi=keepa.Keepa(accesskey)Single ASIN queryproducts=api.query('059035342X')# See help(api.query) for available options when querying the APIYou can use keepa witch async / await tooimportkeepaaccesskey='XXXXXXXXXXXXXXXX'# enter real access key hereapi=awaitkeepa.AsyncKeepa.create(accesskey)Single ASIN query (async)products=awaitapi.query('059035342X')Multiple ASIN query from Listasins=['0022841350','0022841369','0022841369','0022841369']products=api.query(asins)Multiple ASIN query from numpy arrayasins=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 fromAmazon.# Available keysprint(products[0].keys())# Print ASIN and titleprint('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 datanewprice=products[0]['data']['NEW']newpricetime=products[0]['data']['NEW_time']# Can be plotted with matplotlib using:importmatplotlib.pyplotaspltplt.step(newpricetime,newprice,where='pre')# Keys can be listed byprint(products[0]['data'].keys())The product history can also be plotted from the module ifmatplotlibis installedkeepa.plot_product(products[0])You can obtain the offers history for an ASIN (or multiple ASINs) using theoffersparameter.  See the documentation atRequest Productsfor further details.products=api.query(asins,offers=20)product=products[0]offers=product['offers']# each offer contains the price history of each offeroffer=offers[0]csv=offer['offerCSV']# convert these values to numpy arraystimes,prices=keepa.convert_offer_history(csv)# for a list of active offers, seeindices=product['liveOffersOrder']# with this you can loop through active offers:indices=product['liveOffersOrder']offer_times=[]offer_prices=[]forindexinindices: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 individuallyimportmatplotlib.pyplotaspltforiinrange(len(offer_prices)):plt.step(offer_times[i],offer_prices[i])plt.show()If you plan to do a lot of simulatneous query, you might want to speedup query usingwait=Falsearguments.products=awaitapi.query('059035342X',wait=False)Buy Box StatisticsTo load used buy box statistics, you have to enableoffers. This example
loads in product offers and converts the buy box data into apandas.DataFrame.>>>importkeepa>>>key='<REAL_KEEPA_KEY>'>>>api=keepa.Keepa(key)>>>response=api.query('B0088PUEPK',offers=20)>>>product=response[0]>>>buybox_info=product['buyBoxUsedHistory']>>>df=keepa.process_used_buybox(buybox_info)datetime         user_id         condition  isFBA
0   2022-11-02 16:46:00  A1QUAC68EAM09F   Used - Like New   True
1   2022-11-13 10:36:00  A18WXU4I7YR6UA  Used - Very Good  False
2   2022-11-15 23:50:00   AYUGEV9WZ4X5O   Used - Like New  False
3   2022-11-17 06:16:00  A18WXU4I7YR6UA  Used - Very Good  False
4   2022-11-17 10:56:00   AYUGEV9WZ4X5O   Used - Like New  False
..                  ...             ...               ...    ...
115 2023-10-23 10:00:00   AYUGEV9WZ4X5O   Used - Like New  False
116 2023-10-25 21:14:00  A1U9HDFCZO1A84   Used - Like New  False
117 2023-10-26 04:08:00   AYUGEV9WZ4X5O   Used - Like New  False
118 2023-10-27 08:14:00  A1U9HDFCZO1A84   Used - Like New  False
119 2023-10-27 12:34:00   AYUGEV9WZ4X5O   Used - Like New  FalseContributingContribute to this repository by forking this repository and installing in
development mode with:git clone https://github.com/<USERNAME>/keepa
pip install -e .[test]You can then add your feature or commit your bug fix and then run your unit
testing with:pytestUnit testing will automatically enforce minimum code coverage standards.Next, to ensure your code meets minimum code styling standards, run:pip install pre-commit
pre-commit run --all-filesFinally,create a pull requestfrom your fork and I’ll be sure to review it.CreditsThis Python module, written by Alex Kaszynski and several contribitors, is
based on Java code written by Marius Johann, CEO Keepa. Java source is can be
found atkeepacom/api_backend.LicenseApache License, please see license file. Work is credited to both Alex
Kaszynski and Marius Johann.