Skip to content

Commit 9dabac6

Browse files
committed
Better docs, stability, formatting; use ruff
1 parent 130f10e commit 9dabac6

File tree

10 files changed

+984
-823
lines changed

10 files changed

+984
-823
lines changed

README.md

Lines changed: 55 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
[![Python](https://img.shields.io/badge/Python->=3.8-%23FFD140)](https://www.python.org/)
22
[![PyPI](https://img.shields.io/pypi/v/WIOpy)](https://pypi.org/project/WIOpy/)
3-
[![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/CoderJoshDK/WIOpy?include_prereleases)](https://github.com/CoderJoshDK/WIOpy)
4-
[![GitHub issues](https://img.shields.io/github/issues/CoderJoshDK/WIOpy)](https://github.com/CoderJoshDK/WIOpy/issues)
3+
[![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/CoderJoshDK/WIOpy?include_prereleases)](https://github.com/CoderJoshDK/WIOpy) [![GitHub issues](https://img.shields.io/github/issues/CoderJoshDK/WIOpy)](https://github.com/CoderJoshDK/WIOpy/issues)
54
[![GitHub Repo stars](https://img.shields.io/github/stars/CoderJoshDK/WIOpy?style=social)](https://github.com/CoderJoshDK/WIOpy)
65

76
# WalmartIO Python Wrapper - WIOpy
87

9-
A python wrapper for the Walmart io API. Only supports the Affiliate API for now. The project is open to contributions
8+
A python wrapper for the Walmart io API. Only supports the Affiliate API for now. The project is open to contributions
109

1110
## Getting it
1211

1312
To download WIOpy, either fork this github repo or simply use Pypi via pip.
13+
1414
```sh
15-
$ pip install WIOpy
16-
```
15+
pip install WIOpy
16+
```
17+
1718
To upgrade the package simply run
19+
1820
```sh
19-
$ pip install WIOpy --upgrade
20-
```
21+
pip install WIOpy --upgrade
22+
```
2123

2224
## How to use
23-
An example of creating a WIOpy connection
25+
26+
An example of creating a WIOpy connection
2427
One important note is that you need to pass in the private key file *path*.
28+
2529
```py
2630
from wiopy import WalmartIO
2731
walmart_io = WalmartIO(
@@ -32,129 +36,157 @@ walmart_io = WalmartIO(
3236
)
3337
data = walmart_io.product_lookup('33093101')[0]
3438
```
39+
3540
WIOpy also supports asynchronous calls. To use, everything will be the same but you must await a call and the constructed object is different.
41+
3642
```py
3743
from wiopy import AsyncWalmartIO
3844
async_walmart_io = AsyncWalmartIO(...)
3945
data = await async_walmart_io.product_lookup('33093101')[0]
4046
```
4147

4248
## Response Examples
49+
4350
When making a call to the API, an object will be returned. That object is an object version of returned JSON.
4451
There are two ways to get info from the object:
45-
- `data.name`
46-
- `data['name']`
52+
53+
- `data.name`
54+
- `data['name']`
4755
An example of a returned object and one that is not (review/search are variables returned):
48-
- `review.reviewStatistics.averageOverallRating` # Nested call
49-
- `search.facets` # Gives back a dict that can now be used like a dict and not object
56+
- `review.reviewStatistics.averageOverallRating` # Nested call
57+
- `search.facets` # Gives back a dict that can now be used like a dict and not object
5058
Some attributes will return a dict and not an object due to a lack of documentation from Walmart.
5159
When getting an attribute from a `WalmartResponse`, it will return either `response` or `None`\. But trying to get an attribute of `None` will still raise an error.
5260
[Extra details on calls and responses](walmart.io/docs). However, the docs are inconsistent and lack typical practices such as response schema. That is why something like the search facets response is missing because the docs show it is in the response but not what type of data it will contain.
5361
While there may be a response missing or a response not being converted to an object, please check [WalmartResponse](./wiopy/WalmartResponse.py) to get an idea of what a response will return. Some properties are not always present in a response.
5462

55-
5663
## Examples of calls
5764

5865
### [Catalog Product](https://walmart.io/docs/affiliate/paginated-items)
66+
5967
Catalog Product API allows a developer to retrieve the products catalog in a paginated fashion. Catalog can be filtered by category, brand and/or any special offers like rollback, clearance etc.
68+
6069
```py
6170
data = walmart_io.catalog_product(category='3944', maxId='8342714')
6271
```
63-
A catalog response contains category, format, nextPage, totalPages, and a list of items
6472

73+
A catalog response contains category, format, nextPage, totalPages, and a list of items
6574

6675
### [Post Browsed Products](https://walmart.io/docs/affiliate/post-browsed-products)
76+
6777
The post browsed products API allows you to recommend products to someone based on their product viewing history.
78+
6879
```py
6980
data = walmart_io.post_browsed_products('54518466')
7081
```
71-
Response gives top 10 relevant items to the given id
7282

83+
Response gives top 10 relevant items to the given id
7384

7485
### [Product lookup](https://walmart.io/docs/affiliate/product-lookup)
75-
There are two ways to lookup a product
86+
87+
There are two ways to lookup a product
7688
The first is to pass a single string in
89+
7790
```py
7891
data = walmart_io.product_lookup('33093101')[0]
7992
```
93+
8094
or you can pass a list of strings
95+
8196
```py
8297
data = walmart_io.product_lookup('33093101, 54518466, 516833054')
8398
data = walmart_io.product_lookup(['33093101', '54518466', '516833054'])
8499
```
85-
Remember: product_lookup always returns a list of [WalmartProducts](https://walmart.io/docs/affiliate/item_response_groups)
86100

101+
Remember: product_lookup always returns a list of [WalmartProducts](https://walmart.io/docs/affiliate/item_response_groups)
87102

88103
### [Bulk product lookup](https://walmart.io/docs/affiliate/product-lookup)
104+
89105
`bulk_product_lookup` is similar to `product_lookup` however, the bulk version does not raise errors and it is a generator.
90106
Items are passed in as chunks of max size 20. If an error occurs on that call, the same call will be retried based on the given amount. If error still occurs, all items will be lost. But the entire call will not be lost.
107+
91108
```py
92109
data = walmart_io.bulk_product_lookup('33093101, 54518466, 516833054', amount=1, retries=3)
93110
for items in data:
94111
for item in items:
95112
print(item)
96113
```
114+
97115
Response gives generator of [WalmartProducts](https://walmart.io/docs/affiliate/item_response_groups)
98116
If you are unfamiliar with async generators; to properly call the async version:
117+
99118
```py
100119
data = async_walmart_io.bulk_product_lookup('33093101, 54518466, 516833054')
101120
async for items in data:
102121
...
103122
```
104123

105-
106124
### [Product Recommendation](https://walmart.io/docs/affiliate/product-recommendation)
125+
107126
Get recommendations based on a given product id
127+
108128
```py
109129
data = walmart_io.product_recommendation('54518466')
110130
```
111-
Response gives a list of related products
112131

132+
Response gives a list of related products
113133

114134
### [Reviews](https://walmart.io/docs/affiliate/reviews)
135+
115136
The Reviews API gives you access to the extensive item reviews on Walmart that have been written by the users of Walmart.com
137+
116138
```py
117139
data = walmart_io.reviews('33093101')
118140
```
119-
Response gives review data
120141

142+
Response gives review data
121143

122144
### [Search](https://walmart.io/docs/affiliate/search)
145+
123146
Search API allows text search on the Walmart.com catalogue and returns matching items available for sale online.
147+
124148
```py
125149
# Search for tv within electronics and sort by increasing price:
126150
data = walmart_io.search('tv', categoryId='3944', sort='price', order='ascending')
127151
```
152+
128153
You can also add facets to your search
154+
129155
```py
130156
data = walmart_io.search('tv', filter='brand:Samsung')
131157
```
132-
The search response gives back a list of products and some meta data. It returns a `facets` element but there is no detail on the API about what it could return. It is a list of some unknown type
133158

159+
The search response gives back a list of products and some meta data. It returns a `facets` element but there is no detail on the API about what it could return. It is a list of some unknown type
134160

135161
### [Stores](https://walmart.io/docs/affiliate/stores)
162+
136163
The API can return a list of closest stores near a specified location. Either zip code or lon/lat
164+
137165
```py
138166
data = walmart_io.stores(lat=29.735577, lon=-95.511747)
139167
```
140168

141-
142169
### [Taxonomy](https://walmart.io/docs/affiliate/taxonomy)
170+
143171
The taxonomy service exposes the taxonomy used to categorize items on Walmart.com.
144172
Details about params is missing from docs
173+
145174
```py
146175
data = walmart_io.taxonomy()
147176
```
148177

149-
150178
### [Trending Items](https://walmart.io/docs/affiliate/trending-items)
179+
151180
The Trending Items API is designed to give the information on what is bestselling on Walmart.com right now.
181+
152182
```py
153183
data = walmart_io.trending()
154184
```
155185

156186
## Logging
187+
157188
WIOpy supports logging via the logging module. Configuration of the logging module can be as simple as:
189+
158190
```py
159191
import logging
160192

pyproject.toml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "WIOpy"
7-
version = "1.0.0"
7+
version = "1.1.0"
88
description = "A Python wrapper for the Walmart IO API"
99
readme = { file = "README.md", content-type = "text/markdown" }
1010
license = { file = "LICENSE" }
@@ -37,17 +37,22 @@ classifiers = [
3737
"Typing :: Typed",
3838
]
3939

40+
[project.optional-dependencies]
41+
dev = ["ruff", "pre-commit"]
42+
4043
[project.urls]
4144
"Homepage" = "https://github.com/CoderJoshDK/WIOpy"
4245
"Bug Reports" = "https://github.com/CoderJoshDK/WIOpy/issues"
4346
"Source" = "https://github.com/CoderJoshDK/WIOpy"
4447

45-
46-
[tool.black]
48+
[tool.ruff]
4749
line-length = 100
50+
fix = true
51+
target-version = "py38"
52+
53+
unfixable = ["F841"]
54+
ignore = ["PLR0913", "ISC001", "PLR2004"]
4855

49-
[tool.isort]
50-
profile = "black"
51-
combine_as_imports = true
52-
combine_star = true
53-
line_length = 100
56+
[tool.ruff.lint]
57+
select = ["E", "F", "B", "W", "Q", "A", "I", "D",
58+
"UP", "ASYNC", "FA", "ISC", "RET", "SIM", "ARG", "PL", "RUF"]

0 commit comments

Comments
 (0)