Skip to main content

CLI to add grocery items to your Kroger/Smith's cart via the Kroger API

Project description

Kroger Cart CLI

Add grocery items to your Kroger/Smith's cart via the Kroger Public API.

Note: This tool adds items to your cart โ€” it does not and cannot automate checkout. The Kroger API has no checkout endpoint; you always complete purchases manually in your browser or mobile app.

Features

  • ๐Ÿ›’ Search and add items to your cart for delivery or pickup
  • ๏ฟฝ --deals mode to check promotions and savings
  • ๏ฟฝ๐Ÿ“„ Multiple input methods: CLI flags, JSON, CSV, or stdin
  • ๐Ÿ” OAuth2 + PKCE authentication with automatic token refresh
  • ๐Ÿ”‘ Optional OS keychain storage (pip install kroger-cart[keyring])
  • ๐Ÿ”„ Automatic retry with exponential backoff on transient errors
  • ๐Ÿ” --dry-run mode to preview without modifying your cart
  • ๐Ÿ“Š Machine-readable --output json for automation

Why This Tool

One command, entire grocery list. Pass all your items in and get a single JSON result back. No multi-step workflows, no interactive prompts, no back-and-forth.

kroger-cart --json '[{"query": "milk", "quantity": 2}, {"query": "eggs"}]' --output json

Built for AI agents. An agent reads your grocery list, reasons about what to search for, and calls this CLI once. All the searching and cart-adding happens inside a single process โ€” the agent doesn't need to make a separate call for every item. This keeps agent costs low and execution fast.

Works with anything. It's a CLI that takes input and produces JSON output. Pipe from a script, call from an AI agent, run from cron, or just type it yourself. No protocol lock-in, no specific AI platform required.

Quick Start

1. Install

pip install kroger-cart

# Or install from source:
pip install -e .

# Optional: enable OS keychain for token storage
pip install kroger-cart[keyring]

2. Configure

  1. Go to developer.kroger.com and create an application.
  2. Use a Production app (KROGER_ENV=PROD) for real Kroger/Smith's shopper accounts.
  3. In your Kroger app settings, set Redirect URI (default: http://localhost:3000).
  4. Run the setup wizard and enter the same values:
kroger-cart --setup

This saves your credentials/config to ~/.config/kroger-cart/.env (KROGER_CLIENT_ID, KROGER_CLIENT_SECRET, KROGER_ENV, KROGER_REDIRECT_URI).

3. Link Shopper Account

Run this command to log in with the Kroger account you want to shop with:

kroger-cart --auth-only

This opens a web browser. Sign in and click "Authorize" to give the CLI access to your cart.

4. Add Items

kroger-cart --items "milk 1 gallon" "eggs dozen" "bread"

Usage

Add items by name

kroger-cart --items "milk" "eggs" "bread"

Add items with quantities (JSON)

kroger-cart --json '[{"query": "milk", "quantity": 2}, {"query": "eggs", "quantity": 1}]'

Pipe from another tool (stdin)

echo '[{"query": "butter"}, {"query": "cheese"}]' | kroger-cart --stdin

Load from CSV

kroger-cart groceries.csv

CSV format:

query,quantity
milk 1 gallon,2
eggs dozen,1

Check deals

kroger-cart --deals --items "milk" "eggs" "bread"

Shows promo pricing and savings inline:

โœ“ Deals found for (3):
  - Kroger 2% Milk (x1) โ€” $3.49 โ†’ $2.99 (SAVE $0.50, 14%)
  - Large Eggs (x1) โ€” $2.79
  - Bread (x1) โ€” $3.29 โ†’ $2.50 (SAVE $0.79, 24%) ๐Ÿ”ฅ

๐Ÿ’ฐ 2 item(s) on sale โ€” total savings: $1.29

Dry run (preview only)

kroger-cart --items "steak" --dry-run

Cart status note

Cart retrieval ("get cart" / list current cart contents) is not available to general developers via Kroger Public API access. It is available only with Partner API access.

For public usage of this CLI, review cart contents in the Kroger/Smith's web or mobile app after adding items.

Machine-readable output

kroger-cart --items "milk" --output json
{
  "success": true,
  "dry_run": false,
  "added": [{"name": "Krogerยฎ 2% Milk", "upc": "0001111041700", "quantity": 1, "query": "milk"}],
  "not_found": [],
  "added_count": 1,
  "not_found_count": 0,
  "cart_url": "https://www.smithsfoodanddrug.com/cart",
  "modality": "DELIVERY"
}

How It Works

The CLI operates in two phases:

  1. Search โ€” Each item is searched individually against the Kroger product catalog
  2. Add โ€” All found items are added to the cart in a single batched API call

For 5 items, this means 7 API calls total (1 location lookup + 5 searches + 1 batch cart add), not 11.

Product matching

The CLI picks the first search result from Kroger's API for each query. This is by design โ€” the CLI is a dumb pipe that executes whatever search terms it receives.

The caller is responsible for providing good search queries. If an AI agent is driving the CLI, the agent should reason about what to search for before calling the CLI. For example:

User says Agent should search for Why
"steak for lomo saltado" "flank steak" The agent knows the right cut for the dish
"enough yogurt for the week" "yogurt 32 oz" The agent estimates a reasonable quantity
"milk" "whole milk 1 gallon" More specific = better first result

This separation keeps the CLI simple, testable, and usable by both humans and AI agents โ€” the intelligence lives in the caller, not the tool.

All Options

Flag Default Description
--items ITEM [...] โ€” Item names to search and add
--json JSON โ€” JSON array of {query, quantity} objects
--stdin โ€” Read JSON from stdin
--output text|json text Output format
--zip CODE 84045 Zip code for store lookup
--modality DELIVERY|PICKUP DELIVERY Fulfillment type
--env PROD|CERT PROD Kroger API environment
--auth-only โ€” Run authentication only
--dry-run โ€” Search but don't add to cart
--deals โ€” Check deals/promotions (implies --dry-run)
--setup โ€” Interactive setup: configure API credentials
--token-storage auto|file|keyring auto Token storage backend
--version โ€” Show version and exit

Project Structure

kroger-cart/
โ”œโ”€โ”€ kroger_cart/           # Main package
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ __main__.py        # python -m kroger_cart
โ”‚   โ”œโ”€โ”€ cli.py             # Argument parsing, orchestration
โ”‚   โ”œโ”€โ”€ auth.py            # OAuth2 + PKCE, token management
โ”‚   โ”œโ”€โ”€ api.py             # Kroger API functions
โ”‚   โ””โ”€โ”€ session.py         # HTTP session with retry
โ”œโ”€โ”€ tests/                 # Pytest test suite
โ”œโ”€โ”€ pyproject.toml         # Package config
โ”œโ”€โ”€ .env.example           # Credentials template
โ””โ”€โ”€ LICENSE                # MIT license

Configuration & Token Storage

All configuration is stored in ~/.config/kroger-cart/:

File Purpose
.env API credentials + auth config (KROGER_CLIENT_ID, KROGER_CLIENT_SECRET, KROGER_ENV, KROGER_REDIRECT_URI)
tokens.json OAuth tokens (auto-managed, chmod 600)

Run kroger-cart --setup to create the config directory and save your credentials.

OAuth redirect behavior:

  • Default callback URI is http://localhost:3000
  • If you use a different redirect URI in Kroger Developer Portal, set KROGER_REDIRECT_URI to the exact same value in ~/.config/kroger-cart/.env
  • Redirect URI must match exactly between your app settings and the CLI config

By default, tokens are stored in tokens.json with restricted file permissions (chmod 600 on Unix). For enhanced security, install the keyring extra:

pip install kroger-cart[keyring]

This uses your OS keychain (macOS Keychain, GNOME Keyring, Windows Credential Locker). Falls back to file storage automatically on headless systems.

You can force a specific backend:

kroger-cart --items "milk" --token-storage keyring
kroger-cart --items "milk" --token-storage file

Development

pip install -e ".[dev]"
pytest tests/ -v

License

MIT

Project details


Download files

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

Source Distribution

kroger_cart-1.1.3.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kroger_cart-1.1.3-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

Details for the file kroger_cart-1.1.3.tar.gz.

File metadata

  • Download URL: kroger_cart-1.1.3.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for kroger_cart-1.1.3.tar.gz
Algorithm Hash digest
SHA256 a91cbcdb7a4e0af3500f5fe997d8bee80c1f640bd5c1dbd2fb9e27e03f509dd7
MD5 6ba0bc5e720830eb2619fe6624ba50f6
BLAKE2b-256 92b4a5ec3edc34ece371d5fbd3e418e88ec8cf1a92991f1f8ceedec506c477d2

See more details on using hashes here.

File details

Details for the file kroger_cart-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: kroger_cart-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for kroger_cart-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c758fa984aea4cf757dfab77fff4b2008a2d7b71bd7f1288dc61c8bedc4ac33f
MD5 291af465c7cc81b19db30fc0d0cf3b46
BLAKE2b-256 528b6a27f578f608c25ff9e878df01dc6b94d2048651de6ef31dbbbe6d30e787

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page