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 to get your CLIENT_ID and CLIENT_SECRET.
  2. Run the setup wizard:
kroger-cart --setup

This saves your credentials to ~/.config/kroger-cart/.env.

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 (KROGER_CLIENT_ID, KROGER_CLIENT_SECRET)
tokens.json OAuth tokens (auto-managed, chmod 600)

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

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.1.tar.gz (23.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.1-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kroger_cart-1.1.1.tar.gz
  • Upload date:
  • Size: 23.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.1.tar.gz
Algorithm Hash digest
SHA256 00614443f4f3f71b0eb261b3295a47c81ca3d03bbb32421725ad95c5e110261f
MD5 4766a627636aac0ac925fc1ffa56a08b
BLAKE2b-256 4485f5f934d6547ea3e7821db1eebe53c136d6be94c9b60ac7a9474cac3a9f6f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: kroger_cart-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e420fa598b4bae3ef333e56db4d3a12a0e7c31c817af91ce1be89d64118a9b18
MD5 c9735b68d417e8d59a983b95f02c5250
BLAKE2b-256 83dcb731e007f0a121c6c0787710bfa598e182078ff5b03f43ebd2802b061a25

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