Trundler Python Package

We have some very exciting news to share today: we have just released trundlerpy, a Python package for interacting with Trundler! If you’re working in Python, this makes it even easier to get data from Trundler into Python.

Installation

First, you’ll need to install trundlerpy from PyPI.

pip3 install trundlerpy

If you want to keep up to date with the latest package developments, you can also install trundlerpy directly from GitHub.

pip3 install git+https://github.com/datawookie/trundlerpy

Authenticating

It’s a good idea to store your API key in an environment variable rather than hard-coded into a script.

import os

trundler_key = os.getenv('TRUNDLER_KEY')

Now, import the package and set your API key.

from trundlerpy import Trundler

# Set the API Key
tr = Trundler(key = trundler_key)

Retailers

You can use retailer() to return a Pandas DataFrame of retailers.

# Get retailers
retailer = tr.retailer()

# View the first 10 retailers
retailer.head(10)[["retailer_id", "retailer", "retailer_url", "currency"]]
   retailer_id          retailer                      retailer_url currency
0            1  EEM Technologies  https://www.eemtechnologies.com/      USD
1            2            Clicks             https://clicks.co.za/      ZAR
2            3           Dischem        https://www.dischem.co.za/      ZAR
3            4              Game           https://www.game.co.za/      ZAR
4            5        Woolworths     https://www.woolworths.co.za/      ZAR
5            6   Fortnum & Mason  https://www.fortnumandmason.com/      GBP
6            7        John Lewis        https://www.johnlewis.com/      GBP
7            8   Marks & Spencer  https://www.marksandspencer.com/      GBP
8            9       Pick 'n Pay            https://www.pnp.co.za/      ZAR
9           10             Makro          https://www.makro.co.za/      ZAR

You can use the currency field to focus on retailers from specific countries.

# Get South African retailers
retailer.loc[retailer.currency=='ZAR'].head(5)
   retailer_id     retailer  ... visible priority
1            2       Clicks  ...    True      0.0
2            3      Dischem  ...    True      0.0
3            4         Game  ...    True      0.0
4            5   Woolworths  ...    True      0.0
8            9  Pick 'n Pay  ...    True      0.0

[5 rows x 6 columns]

Products

The retailer_products() method yields a DataFrame with the products for a specific retailer, where each product is assigned a name, brand, model, SKU and barcode (if available).

# View first 5 products at a specific retailer
tr.retailer_products(5)[["product_id", "product", "sku"]].head(5)
   product_id                                 product            sku
0     2841918   Easy Care School Trousers - BLACK / 7  6009211458659
1     2841919  Easy Care School Trousers - BLACK / 87  6009211458703
2     2841920   Easy Care School Trousers - BLACK / 5  6009211458758
3     2841921   Easy Care School Trousers - BLACK / 9  6009211458680
4     2841922  Easy Care School Trousers - BLACK / 12  6009211458673

Products can also be filtered by name and brand.

product = tr.retailer_products(5, product = "coffee", brand = "nespresso").head(5)

To get details on a specific product, use the product_details() method and the product ID.

# Get details on an specific product
tr.product(711497)[["product_id", "product", "sku"]]
   product_id                                       product            sku
0      711497  Instant Coffee Café Gold Italian Sachets 50g  6009204582774

Prices

Finally, you can use product_prices() to get the price history for a particular product using its product ID.

# Get the price history for a specific product
tr.product_prices(711497).head(10)
   product_id                       time  price price_promotion available
0      711497  2020-02-07T18:04:06+00:00  49.99            None      None
1      711497  2020-02-14T10:43:49+00:00  49.99            None      None
2      711497  2020-02-27T20:46:19+00:00  49.99            None      None
3      711497  2020-03-12T19:43:53+00:00  49.99            None      None
4      711497  2020-03-13T18:15:52+00:00  49.99            None      None
5      711497  2020-03-14T11:41:39+00:00  49.99            None      None
6      711497  2020-03-16T12:17:37+00:00  49.99            None      None
7      711497  2020-03-17T13:28:26+00:00  49.99            None      None
8      711497  2020-03-18T11:07:31+00:00  49.99            None      None
9      711497  2020-03-19T15:42:42+00:00  49.99            None      None

Related

For more blog posts on R check out R-Bloggers.

For more blog posts on Python check out Python-Bloggers.