Skip to main content

safeway-coupons

Automatic coupon clipper for Safeway's online "Safeway for U" coupons

License PyPI Python CI Coverage Renovate GitHub stars

safeway-coupons is a tool that will log in to an account on safeway.com, and attempt to select all of the "Safeway for U" electronic coupons on the site so they don't have to each be clicked manually.

Design notes

Safeway's sign in page is protected by a web application firewall (WAF). safeway-coupons performs authentication using Google Chrome. Authentication may fail based on your IP's reputation, either by presenting an interactive challenge or denying sign in attempts altogether.

safeway-coupons currently does not have support for prompting the user to solve interactive challenges.

Safeway's sign in page may also require verifying a new device with a multi-factor authentication (MFA) verification code. To reduce how often this happens, a persistent Google Chrome profile directory is created for each account and reused for logins with the same account. These are stored within the User state directory (see user_state_dir).

Once a signed in session is established, coupon clipping is performed using HTTP requests via requests.

Installation and usage

Prerequisites

Installation

Installation with uv or pipx is recommended:

uv tool install safeway-coupons
pipx install safeway-coupons

Installation with pip is also available:

pip install safeway-coupons

Usage

For best results, run this program once a day or so with a cron daemon.

For full usage options, run

safeway-coupons --help

Configuration

safeway-coupons can clip coupons for one or more Safeway accounts in a single run, depending on the configuration method used.

If a sender email address is configured, a summary email will be sent for each Safeway account via sendmail. The email recipient defaults to the Safeway account email address, but can be overridden for each account.

Accounts are searched via the following methods in the listed order. Only one account configuration method may be used at a time.

With environment variables

A single Safeway account can be configured with environment variables:

  • SAFEWAY_ACCOUNT_USERNAME: Account email address (required)
  • SAFEWAY_ACCOUNT_PASSWORD: Account password (required)
  • SAFEWAY_ACCOUNT_MAIL_FROM: Sender address for email summary
  • SAFEWAY_ACCOUNT_MAIL_TO: Recipient address for email summary

With config file

Multiple Safeway accounts can be provided in an ini-style config file, with a section for each account. For example:

; optional
email_sender = sender@example.com

; required
[safeway.account@example.com]
; required
password = 12345
; optional
notify = your.email@example.com

Provide the path to your config file using the -c or --accounts-config option:

safeway-coupons -c path/to/config/file

Multi-factor authentication (MFA) verification codes

Safeway's sign in page will ask for an MFA code when signing in from a new device, and occasionally on other logins.

When run interactively, safeway-coupons can request Safeway's sign in page to send an MFA code to the first listed destination for your account (e.g. email or text). safeway-coupons will then prompt for the code in the terminal to complete sign in. To sign in interactively with an MFA code, run:

safeway-coupons -c path/to/config/file --login-only

Scheduled and noninteractive invocations of safeway-coupons cannot obtain or enter MFA verification codes. If the sign in page asks for an MFA code, safeway-coupons exits with an error message. When this happens, run safeway-coupons interactively to refresh your sign in session.

Installation and usage with Docker Compose

A Docker container is provided which runs safeway-coupons with cron. The cron schedule and your Safeway account details may be configured using environment variables, or with an accounts file.

Example compose.yaml with configuration via environment variables:

services:
  safeway-coupons:
    image: ghcr.io/smkent/safeway-coupons:latest
    environment:
      CRON_SCHEDULE: "0 2 * * *"  # Run at 2:00 AM UTC each day
      # TZ: Antarctica/McMurdo  # Optional time zone to use instead of UTC
      SMTPHOST: your.smtp.host
      SAFEWAY_ACCOUNT_USERNAME: your.safeway.account.email@example.com
      SAFEWAY_ACCOUNT_PASSWORD: very_secret
      SAFEWAY_ACCOUNT_MAIL_FROM: your.email@example.com
      SAFEWAY_ACCOUNT_MAIL_TO: your.email@example.com
      # EXTRA_ARGS: --debug  # Optional
    restart: unless-stopped
    volumes:
      - state:/state:rw

volumes:
  state:

Example compose.yaml with configuration via accounts file:

services:
  safeway-coupons:
    image: ghcr.io/smkent/safeway-coupons:latest
    environment:
      CRON_SCHEDULE: "0 2 * * *"  # Run at 2:00 AM UTC each day
      # TZ: Antarctica/McMurdo  # Optional time zone to use instead of UTC
      SMTPHOST: your.smtp.host
      SAFEWAY_ACCOUNTS_FILE: /accounts_file
      # EXTRA_ARGS: --debug  # Optional
    restart: unless-stopped
    volumes:
      - path/to/safeway_accounts_file:/accounts_file:ro
      - state:/state:rw

volumes:
  state:

Start the container by running:

docker compose up -d

Debugging information can be viewed in the container log:

docker compose logs -f

To sign in and enter a multi-factor authentication (MFA) verification code, run safeway-coupons interactively in the running container:

docker compose exec -it safeway-coupons /entrypoint --login-only

Development

Invocation with docker compose

safeway-coupons can be executed within a Docker container using compose.dev.yaml.

To use, first create an accounts file in the same directory with your safeway-coupons accounts configuration. Then, execute safeway-coupons within a container using docker compose:

docker compose -f compose.dev.yaml up --build

The container will run safeway-coupons once, attempt to clip one coupon, and then stop.

To change the safeway-coupons arguments, modify the command value in compose.dev.yaml.

When finished with development tasks, the docker compose state can be cleaned up with:

docker compose -f compose.dev.yaml down

License

Copyright (C) 2012 Stephen Kent and contributors

Licensed under the GNU General Public License v3.0 or later (GPL-3.0-or-later).

Project template

This project is based on and maintained with copier-project.

Metadata

Release files for safeway-coupons 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for safeway-coupons 0.7.1
File Size Uploaded Provenance Actions
safeway_coupons-0.7.1.tar.gz 38.6 kB With provenance Details for safeway_coupons-0.7.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for safeway-coupons 0.7.1
File Interpreter ABI Platform Actions
safeway_coupons-0.7.1-py3-none-any.whl Python 3 none any Details for safeway_coupons-0.7.1-py3-none-any.whl

Total release size: 72.8 kB

Release files / safeway_coupons-0.7.1.tar.gz

Download URL safeway_coupons-0.7.1.tar.gz
Size 38.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c3a7094268cb8639c9b111cbf496fb3e01fe016c089fb38edfabd51cc791a564
BLAKE2b-256 checksum
How to use checksums
7f04135c50c9bb356d3bb3800feae5ea22b48621f76eea634fbb86a683d95429
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Release files / safeway_coupons-0.7.1-py3-none-any.whl

Download URL safeway_coupons-0.7.1-py3-none-any.whl
Size 34.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d619f09e5dbadc291cb05440fb8b7f99d2a6d9ba8febc20125c2574c477bd36d
BLAKE2b-256 checksum
How to use checksums
deb21210918454011d508aa4d284bcd78ad1813a1d20ce8bd77e8513b9871d49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

Security for safeway-coupons 0.7.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for safeway_coupons-0.7.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.7.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page