kroger-api 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- kroger_api-0.1.0/LICENSE +21 -0
- kroger_api-0.1.0/MANIFEST.in +40 -0
- kroger_api-0.1.0/PKG-INFO +244 -0
- kroger_api-0.1.0/README.md +176 -0
- kroger_api-0.1.0/assets/product_api_script.gif +0 -0
- kroger_api-0.1.0/examples/authorization_api_examples.py +210 -0
- kroger_api-0.1.0/examples/cart_api_examples.py +181 -0
- kroger_api-0.1.0/examples/clear_tokens.py +43 -0
- kroger_api-0.1.0/examples/identity_api_examples.py +77 -0
- kroger_api-0.1.0/examples/location_api_examples.py +303 -0
- kroger_api-0.1.0/examples/oauth_flow.py +114 -0
- kroger_api-0.1.0/examples/product_api_examples.py +280 -0
- kroger_api-0.1.0/examples/token_refresh_example.py +102 -0
- kroger_api-0.1.0/kroger_api/__init__.py +6 -0
- kroger_api-0.1.0/kroger_api/api/__init__.py +0 -0
- kroger_api-0.1.0/kroger_api/api/authorization.py +107 -0
- kroger_api-0.1.0/kroger_api/api/cart.py +37 -0
- kroger_api-0.1.0/kroger_api/api/identity.py +27 -0
- kroger_api-0.1.0/kroger_api/api/location.py +185 -0
- kroger_api-0.1.0/kroger_api/api/product.py +84 -0
- kroger_api-0.1.0/kroger_api/auth/__init__.py +6 -0
- kroger_api-0.1.0/kroger_api/auth/interactive.py +173 -0
- kroger_api-0.1.0/kroger_api/client.py +376 -0
- kroger_api-0.1.0/kroger_api/kroger_api.py +41 -0
- kroger_api-0.1.0/kroger_api/token_storage.py +81 -0
- kroger_api-0.1.0/kroger_api/utils/__init__.py +3 -0
- kroger_api-0.1.0/kroger_api/utils/env.py +76 -0
- kroger_api-0.1.0/kroger_api/utils/oauth.py +133 -0
- kroger_api-0.1.0/kroger_api.egg-info/PKG-INFO +244 -0
- kroger_api-0.1.0/kroger_api.egg-info/SOURCES.txt +36 -0
- kroger_api-0.1.0/kroger_api.egg-info/dependency_links.txt +1 -0
- kroger_api-0.1.0/kroger_api.egg-info/not-zip-safe +1 -0
- kroger_api-0.1.0/kroger_api.egg-info/requires.txt +15 -0
- kroger_api-0.1.0/kroger_api.egg-info/top_level.txt +2 -0
- kroger_api-0.1.0/pyproject.toml +61 -0
- kroger_api-0.1.0/requirements.txt +18 -0
- kroger_api-0.1.0/setup.cfg +4 -0
- kroger_api-0.1.0/setup.py +75 -0
kroger_api-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Stephen Thoemmes
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Include the README
|
|
2
|
+
include README.md
|
|
3
|
+
|
|
4
|
+
# Include the license
|
|
5
|
+
include LICENSE
|
|
6
|
+
|
|
7
|
+
# Include requirements
|
|
8
|
+
include requirements.txt
|
|
9
|
+
|
|
10
|
+
# Include assets (demo videos, images, etc.)
|
|
11
|
+
recursive-include assets *.mp4 *.gif *.png *.jpg *.jpeg
|
|
12
|
+
|
|
13
|
+
# Include examples directory but don't package them in the main distribution
|
|
14
|
+
recursive-include examples *.py
|
|
15
|
+
prune examples/__pycache__
|
|
16
|
+
|
|
17
|
+
# Exclude test files
|
|
18
|
+
recursive-exclude tests *
|
|
19
|
+
|
|
20
|
+
# Exclude development and build files
|
|
21
|
+
exclude .env*
|
|
22
|
+
exclude .gitignore
|
|
23
|
+
exclude test_all_examples.sh
|
|
24
|
+
exclude *.egg-info
|
|
25
|
+
exclude .kroger_token*
|
|
26
|
+
global-exclude *.pyc
|
|
27
|
+
global-exclude __pycache__
|
|
28
|
+
|
|
29
|
+
# Exclude documentation that shouldn't be in the package
|
|
30
|
+
recursive-exclude docs_kroger_api *
|
|
31
|
+
|
|
32
|
+
# Exclude virtual environment
|
|
33
|
+
recursive-exclude venv *
|
|
34
|
+
|
|
35
|
+
# Exclude git files
|
|
36
|
+
recursive-exclude .git *
|
|
37
|
+
|
|
38
|
+
# Exclude build artifacts
|
|
39
|
+
recursive-exclude build *
|
|
40
|
+
recursive-exclude dist *
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: kroger-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python client library for the Kroger Public API
|
|
5
|
+
Home-page: https://github.com/CupOfOwls/kroger-api
|
|
6
|
+
Author: Stephen Thoemmes
|
|
7
|
+
Author-email: Stephen Thoemmes <thoemmes.stephen@gmail.com>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2025 Stephen Thoemmes
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
Project-URL: Homepage, https://github.com/CupOfOwls/kroger-api
|
|
30
|
+
Project-URL: Repository, https://github.com/CupOfOwls/kroger-api
|
|
31
|
+
Project-URL: Documentation, https://developer.kroger.com/documentation/public/
|
|
32
|
+
Project-URL: Bug Reports, https://github.com/CupOfOwls/kroger-api/issues
|
|
33
|
+
Project-URL: Demo Video, https://github.com/CupOfOwls/kroger-api/blob/main/assets/kroger-api-python-add-to-cart-demo.mp4
|
|
34
|
+
Keywords: kroger,api,grocery,shopping,retail
|
|
35
|
+
Classifier: Development Status :: 4 - Beta
|
|
36
|
+
Classifier: Intended Audience :: Developers
|
|
37
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
38
|
+
Classifier: Operating System :: OS Independent
|
|
39
|
+
Classifier: Programming Language :: Python :: 3
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
43
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
44
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
45
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
46
|
+
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
47
|
+
Classifier: Topic :: Office/Business
|
|
48
|
+
Requires-Python: >=3.8
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
License-File: LICENSE
|
|
51
|
+
Requires-Dist: requests>=2.25.0
|
|
52
|
+
Requires-Dist: python-dotenv>=0.15.0
|
|
53
|
+
Requires-Dist: certifi>=2021.0.0
|
|
54
|
+
Requires-Dist: urllib3>=1.26.0
|
|
55
|
+
Provides-Extra: dev
|
|
56
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
57
|
+
Requires-Dist: pytest-mock>=3.0.0; extra == "dev"
|
|
58
|
+
Requires-Dist: requests-mock>=1.9.0; extra == "dev"
|
|
59
|
+
Requires-Dist: black; extra == "dev"
|
|
60
|
+
Requires-Dist: flake8; extra == "dev"
|
|
61
|
+
Requires-Dist: mypy; extra == "dev"
|
|
62
|
+
Provides-Extra: examples
|
|
63
|
+
Requires-Dist: tabulate>=0.8.0; extra == "examples"
|
|
64
|
+
Dynamic: author
|
|
65
|
+
Dynamic: home-page
|
|
66
|
+
Dynamic: license-file
|
|
67
|
+
Dynamic: requires-python
|
|
68
|
+
|
|
69
|
+
# 🛒 Kroger Public API 🛍️ -- with Examples in Python 🐍
|
|
70
|
+
|
|
71
|
+
A comprehensive Python client library for the Kroger Public API, featuring robust token management, comprehensive examples, and easy-to-use interfaces for all available endpoints.
|
|
72
|
+
|
|
73
|
+
## 📺 Demo
|
|
74
|
+
|
|
75
|
+
Here's a quick demo of browsing via the Product API:
|
|
76
|
+
|
|
77
|
+
<div align="center">
|
|
78
|
+
<img src="assets/product_api_script.gif" alt="Kroger API Python Demo">
|
|
79
|
+
</div>
|
|
80
|
+
|
|
81
|
+
## 🚀 Quick Start
|
|
82
|
+
|
|
83
|
+
### Installation
|
|
84
|
+
|
|
85
|
+
#### From PyPI (Recommended)
|
|
86
|
+
```bash
|
|
87
|
+
pip install kroger-api
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
#### From Source
|
|
91
|
+
```bash
|
|
92
|
+
git clone https://github.com/CupOfOwls/kroger-api.git
|
|
93
|
+
cd kroger-api
|
|
94
|
+
python3 -m venv venv
|
|
95
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
96
|
+
pip install -r requirements.txt
|
|
97
|
+
pip install -e .
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Basic Usage
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from kroger_api import KrogerAPI
|
|
104
|
+
|
|
105
|
+
# Initialize the client
|
|
106
|
+
kroger = KrogerAPI()
|
|
107
|
+
|
|
108
|
+
# Get a client credentials token for public data
|
|
109
|
+
kroger.authorization.get_token_with_client_credentials("product.compact")
|
|
110
|
+
|
|
111
|
+
# Search for products
|
|
112
|
+
products = kroger.product.search_products(
|
|
113
|
+
term="milk",
|
|
114
|
+
location_id="01400443", # A Kroger store location
|
|
115
|
+
limit=5
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
print(f"Found {len(products['data'])} products!")
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 🔐 Getting Started with Credentials
|
|
122
|
+
|
|
123
|
+
### 1. Create a Kroger Developer Account
|
|
124
|
+
Visit the [Kroger Developer Portal](https://developer.kroger.com/manage/apps/register) to:
|
|
125
|
+
1. Create a developer account
|
|
126
|
+
2. Register your application
|
|
127
|
+
3. Get your `CLIENT_ID`, `CLIENT_SECRET`, and set your `REDIRECT_URI`
|
|
128
|
+
|
|
129
|
+
### 2. Set Up Environment Variables
|
|
130
|
+
Copy `.env.example` to `.env` and fill in your credentials:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
# Kroger API Credentials
|
|
134
|
+
KROGER_CLIENT_ID=your_client_id_here
|
|
135
|
+
KROGER_CLIENT_SECRET=your_client_secret_here
|
|
136
|
+
KROGER_REDIRECT_URI=http://localhost:8000/callback
|
|
137
|
+
|
|
138
|
+
# Optional (Recommended): Your zip code for location-based searches
|
|
139
|
+
KROGER_USER_ZIP_CODE=90210
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Important:** Set your `KROGER_REDIRECT_URI` during app registration. While marked as optional in the form, the OAuth flow requires it.
|
|
143
|
+
|
|
144
|
+
### 3. First Run Authorization
|
|
145
|
+
The first time you run a script requiring user authentication, you'll be prompted to authorize your app through your web browser. You're granting permission to **your own registered app**, not to any third party.
|
|
146
|
+
|
|
147
|
+
## 🔄 Token Management
|
|
148
|
+
|
|
149
|
+
This library implements robust, automatic token management:
|
|
150
|
+
|
|
151
|
+
### ✨ Features
|
|
152
|
+
- **Automatic token refresh** - No manual token handling required
|
|
153
|
+
- **Persistent storage** - Tokens saved securely to avoid repeated logins
|
|
154
|
+
- **Proactive validation** - Tests tokens before use
|
|
155
|
+
- **Reactive recovery** - Automatically refreshes expired tokens during API calls
|
|
156
|
+
|
|
157
|
+
### 🔧 How it Works
|
|
158
|
+
|
|
159
|
+
**Proactive Approach:**
|
|
160
|
+
1. Loads saved tokens and tests them with a lightweight API request
|
|
161
|
+
2. Automatically refreshes if token is expired and refresh token is available
|
|
162
|
+
|
|
163
|
+
**Reactive Approach:**
|
|
164
|
+
1. Makes API requests with current token
|
|
165
|
+
2. On 401 Unauthorized errors, attempts token refresh
|
|
166
|
+
3. Retries original request with new token
|
|
167
|
+
|
|
168
|
+
Token files (automatically managed, stored in project root):
|
|
169
|
+
- `.kroger_token_client_product.compact.json` - Client credentials tokens
|
|
170
|
+
- `.kroger_token_user.json` - User authorization tokens
|
|
171
|
+
|
|
172
|
+
## 📚 Example Scripts
|
|
173
|
+
|
|
174
|
+
The `examples/` directory contains comprehensive demonstrations:
|
|
175
|
+
|
|
176
|
+
| Script | Description | Authentication Required |
|
|
177
|
+
|--------|-------------|------------------------|
|
|
178
|
+
| `location_api_examples.py` | Search stores, get details about locations, chains, and departments | Client credentials |
|
|
179
|
+
| `product_api_examples.py` | Search products, get details, filter by various criteria | Client credentials |
|
|
180
|
+
| `cart_api_examples.py` | Add items to user's cart, full shopping workflow | User authorization |
|
|
181
|
+
| `identity_api_examples.py` | Get user profile information | User authorization |
|
|
182
|
+
| `oauth_flow.py` | Complete OAuth2 authorization code flow example | User authorization |
|
|
183
|
+
| `token_refresh_example.py` | Demonstrates automatic token refresh functionality | Both |
|
|
184
|
+
| `authorization_api_examples.py` | All authorization endpoints and flows | Both |
|
|
185
|
+
| `clear_tokens.py` | Utility to delete all saved token files | None |
|
|
186
|
+
|
|
187
|
+
### 🏃♂️ Running Examples
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
# Make sure your .env file is configured first!
|
|
191
|
+
|
|
192
|
+
# Public API examples (no user login required)
|
|
193
|
+
python examples/location_api_examples.py
|
|
194
|
+
python examples/product_api_examples.py
|
|
195
|
+
|
|
196
|
+
# User-specific examples (requires browser login)
|
|
197
|
+
python examples/cart_api_examples.py
|
|
198
|
+
python examples/identity_api_examples.py
|
|
199
|
+
python examples/oauth_flow.py
|
|
200
|
+
|
|
201
|
+
# Utility scripts
|
|
202
|
+
python examples/clear_tokens.py # Clear saved tokens
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## 🏪 Kroger Public API Information
|
|
206
|
+
|
|
207
|
+
### API Versions & Rate Limits
|
|
208
|
+
|
|
209
|
+
| API | Version | Rate Limit | Notes |
|
|
210
|
+
|-----|---------|------------|-------|
|
|
211
|
+
| **Authorization** | 1.0.13 | No specific limit | Token management |
|
|
212
|
+
| **Products** | 1.2.4 | 10,000 calls/day | Search and product details |
|
|
213
|
+
| **Locations** | 1.2.2 | 1,600 calls/day per endpoint | Store locations and details |
|
|
214
|
+
| **Cart** | 1.2.3 | 5,000 calls/day | Add/manage cart items |
|
|
215
|
+
| **Identity** | 1.2.3 | 5,000 calls/day | User profile information |
|
|
216
|
+
|
|
217
|
+
**Note:** Rate limits are enforced per endpoint, not per operation. You can distribute calls across operations using the same endpoint as needed.
|
|
218
|
+
|
|
219
|
+
### 🔑 Available Scopes
|
|
220
|
+
|
|
221
|
+
When requesting user authorization, you can specify these scopes:
|
|
222
|
+
|
|
223
|
+
- `product.compact` - Read product information
|
|
224
|
+
- `cart.basic:write` - Add items to cart
|
|
225
|
+
- `profile.compact` - Read user profile information
|
|
226
|
+
|
|
227
|
+
## 📖 API Documentation
|
|
228
|
+
|
|
229
|
+
For complete API documentation, visit:
|
|
230
|
+
- [Kroger Developer Portal](https://developer.kroger.com/)
|
|
231
|
+
- [API Documentation](https://developer.kroger.com/documentation/public/)
|
|
232
|
+
- [Acceptable Use Policy](https://developer.kroger.com/documentation/public/getting-started/acceptable-use)
|
|
233
|
+
|
|
234
|
+
## 🤝 Contributing
|
|
235
|
+
|
|
236
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
237
|
+
|
|
238
|
+
## 📄 License
|
|
239
|
+
|
|
240
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
241
|
+
|
|
242
|
+
## ⚠️ Disclaimer
|
|
243
|
+
|
|
244
|
+
This is an unofficial Python client for the Kroger Public API. It is not affiliated with, endorsed by, or sponsored by Kroger.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
# 🛒 Kroger Public API 🛍️ -- with Examples in Python 🐍
|
|
2
|
+
|
|
3
|
+
A comprehensive Python client library for the Kroger Public API, featuring robust token management, comprehensive examples, and easy-to-use interfaces for all available endpoints.
|
|
4
|
+
|
|
5
|
+
## 📺 Demo
|
|
6
|
+
|
|
7
|
+
Here's a quick demo of browsing via the Product API:
|
|
8
|
+
|
|
9
|
+
<div align="center">
|
|
10
|
+
<img src="assets/product_api_script.gif" alt="Kroger API Python Demo">
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
## 🚀 Quick Start
|
|
14
|
+
|
|
15
|
+
### Installation
|
|
16
|
+
|
|
17
|
+
#### From PyPI (Recommended)
|
|
18
|
+
```bash
|
|
19
|
+
pip install kroger-api
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
#### From Source
|
|
23
|
+
```bash
|
|
24
|
+
git clone https://github.com/CupOfOwls/kroger-api.git
|
|
25
|
+
cd kroger-api
|
|
26
|
+
python3 -m venv venv
|
|
27
|
+
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
28
|
+
pip install -r requirements.txt
|
|
29
|
+
pip install -e .
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Basic Usage
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from kroger_api import KrogerAPI
|
|
36
|
+
|
|
37
|
+
# Initialize the client
|
|
38
|
+
kroger = KrogerAPI()
|
|
39
|
+
|
|
40
|
+
# Get a client credentials token for public data
|
|
41
|
+
kroger.authorization.get_token_with_client_credentials("product.compact")
|
|
42
|
+
|
|
43
|
+
# Search for products
|
|
44
|
+
products = kroger.product.search_products(
|
|
45
|
+
term="milk",
|
|
46
|
+
location_id="01400443", # A Kroger store location
|
|
47
|
+
limit=5
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
print(f"Found {len(products['data'])} products!")
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## 🔐 Getting Started with Credentials
|
|
54
|
+
|
|
55
|
+
### 1. Create a Kroger Developer Account
|
|
56
|
+
Visit the [Kroger Developer Portal](https://developer.kroger.com/manage/apps/register) to:
|
|
57
|
+
1. Create a developer account
|
|
58
|
+
2. Register your application
|
|
59
|
+
3. Get your `CLIENT_ID`, `CLIENT_SECRET`, and set your `REDIRECT_URI`
|
|
60
|
+
|
|
61
|
+
### 2. Set Up Environment Variables
|
|
62
|
+
Copy `.env.example` to `.env` and fill in your credentials:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Kroger API Credentials
|
|
66
|
+
KROGER_CLIENT_ID=your_client_id_here
|
|
67
|
+
KROGER_CLIENT_SECRET=your_client_secret_here
|
|
68
|
+
KROGER_REDIRECT_URI=http://localhost:8000/callback
|
|
69
|
+
|
|
70
|
+
# Optional (Recommended): Your zip code for location-based searches
|
|
71
|
+
KROGER_USER_ZIP_CODE=90210
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
**Important:** Set your `KROGER_REDIRECT_URI` during app registration. While marked as optional in the form, the OAuth flow requires it.
|
|
75
|
+
|
|
76
|
+
### 3. First Run Authorization
|
|
77
|
+
The first time you run a script requiring user authentication, you'll be prompted to authorize your app through your web browser. You're granting permission to **your own registered app**, not to any third party.
|
|
78
|
+
|
|
79
|
+
## 🔄 Token Management
|
|
80
|
+
|
|
81
|
+
This library implements robust, automatic token management:
|
|
82
|
+
|
|
83
|
+
### ✨ Features
|
|
84
|
+
- **Automatic token refresh** - No manual token handling required
|
|
85
|
+
- **Persistent storage** - Tokens saved securely to avoid repeated logins
|
|
86
|
+
- **Proactive validation** - Tests tokens before use
|
|
87
|
+
- **Reactive recovery** - Automatically refreshes expired tokens during API calls
|
|
88
|
+
|
|
89
|
+
### 🔧 How it Works
|
|
90
|
+
|
|
91
|
+
**Proactive Approach:**
|
|
92
|
+
1. Loads saved tokens and tests them with a lightweight API request
|
|
93
|
+
2. Automatically refreshes if token is expired and refresh token is available
|
|
94
|
+
|
|
95
|
+
**Reactive Approach:**
|
|
96
|
+
1. Makes API requests with current token
|
|
97
|
+
2. On 401 Unauthorized errors, attempts token refresh
|
|
98
|
+
3. Retries original request with new token
|
|
99
|
+
|
|
100
|
+
Token files (automatically managed, stored in project root):
|
|
101
|
+
- `.kroger_token_client_product.compact.json` - Client credentials tokens
|
|
102
|
+
- `.kroger_token_user.json` - User authorization tokens
|
|
103
|
+
|
|
104
|
+
## 📚 Example Scripts
|
|
105
|
+
|
|
106
|
+
The `examples/` directory contains comprehensive demonstrations:
|
|
107
|
+
|
|
108
|
+
| Script | Description | Authentication Required |
|
|
109
|
+
|--------|-------------|------------------------|
|
|
110
|
+
| `location_api_examples.py` | Search stores, get details about locations, chains, and departments | Client credentials |
|
|
111
|
+
| `product_api_examples.py` | Search products, get details, filter by various criteria | Client credentials |
|
|
112
|
+
| `cart_api_examples.py` | Add items to user's cart, full shopping workflow | User authorization |
|
|
113
|
+
| `identity_api_examples.py` | Get user profile information | User authorization |
|
|
114
|
+
| `oauth_flow.py` | Complete OAuth2 authorization code flow example | User authorization |
|
|
115
|
+
| `token_refresh_example.py` | Demonstrates automatic token refresh functionality | Both |
|
|
116
|
+
| `authorization_api_examples.py` | All authorization endpoints and flows | Both |
|
|
117
|
+
| `clear_tokens.py` | Utility to delete all saved token files | None |
|
|
118
|
+
|
|
119
|
+
### 🏃♂️ Running Examples
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
# Make sure your .env file is configured first!
|
|
123
|
+
|
|
124
|
+
# Public API examples (no user login required)
|
|
125
|
+
python examples/location_api_examples.py
|
|
126
|
+
python examples/product_api_examples.py
|
|
127
|
+
|
|
128
|
+
# User-specific examples (requires browser login)
|
|
129
|
+
python examples/cart_api_examples.py
|
|
130
|
+
python examples/identity_api_examples.py
|
|
131
|
+
python examples/oauth_flow.py
|
|
132
|
+
|
|
133
|
+
# Utility scripts
|
|
134
|
+
python examples/clear_tokens.py # Clear saved tokens
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## 🏪 Kroger Public API Information
|
|
138
|
+
|
|
139
|
+
### API Versions & Rate Limits
|
|
140
|
+
|
|
141
|
+
| API | Version | Rate Limit | Notes |
|
|
142
|
+
|-----|---------|------------|-------|
|
|
143
|
+
| **Authorization** | 1.0.13 | No specific limit | Token management |
|
|
144
|
+
| **Products** | 1.2.4 | 10,000 calls/day | Search and product details |
|
|
145
|
+
| **Locations** | 1.2.2 | 1,600 calls/day per endpoint | Store locations and details |
|
|
146
|
+
| **Cart** | 1.2.3 | 5,000 calls/day | Add/manage cart items |
|
|
147
|
+
| **Identity** | 1.2.3 | 5,000 calls/day | User profile information |
|
|
148
|
+
|
|
149
|
+
**Note:** Rate limits are enforced per endpoint, not per operation. You can distribute calls across operations using the same endpoint as needed.
|
|
150
|
+
|
|
151
|
+
### 🔑 Available Scopes
|
|
152
|
+
|
|
153
|
+
When requesting user authorization, you can specify these scopes:
|
|
154
|
+
|
|
155
|
+
- `product.compact` - Read product information
|
|
156
|
+
- `cart.basic:write` - Add items to cart
|
|
157
|
+
- `profile.compact` - Read user profile information
|
|
158
|
+
|
|
159
|
+
## 📖 API Documentation
|
|
160
|
+
|
|
161
|
+
For complete API documentation, visit:
|
|
162
|
+
- [Kroger Developer Portal](https://developer.kroger.com/)
|
|
163
|
+
- [API Documentation](https://developer.kroger.com/documentation/public/)
|
|
164
|
+
- [Acceptable Use Policy](https://developer.kroger.com/documentation/public/getting-started/acceptable-use)
|
|
165
|
+
|
|
166
|
+
## 🤝 Contributing
|
|
167
|
+
|
|
168
|
+
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
|
|
169
|
+
|
|
170
|
+
## 📄 License
|
|
171
|
+
|
|
172
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
173
|
+
|
|
174
|
+
## ⚠️ Disclaimer
|
|
175
|
+
|
|
176
|
+
This is an unofficial Python client for the Kroger Public API. It is not affiliated with, endorsed by, or sponsored by Kroger.
|
|
Binary file
|