Skip to main content

stapel-promotions

CI coverage pypi downloads python license llms.txt

Promo codes and automatic discounts for a Stapel shop. Staff define promotions (percent off, a fixed amount off, or free shipping), scoped to the whole cart, one purchasable type or a list of purchasable keys, with a time window, a minimum subtotal, a stackable flag and usage caps in total and per shopper; codes are many per promotion, case-insensitive, single-use or shared, optionally bound to one shopper, and generated in bulk. Automatic promotions apply without a code. The brick plugs into stapel-orders by Function name only: promotions.quote is the discount adjuster (deterministic, no writes, one adjustment per promotion, free shipping as a marker the shipping adjuster honours) and promotions.reserve/commit/release is the checkout hook that ledgers each use under the promotion's row lock, so two shoppers racing for the last use end as one order and one promo_code_exhausted. Money is Decimal end to end; a discount never exceeds what it applies to.

Part of the Stapel framework — composable Django apps that deploy as a monolith or as microservices without changing module code.

Install

pip install stapel-promotions

At a glance

Fact Value
Version 0.1.0
Python >=3.11 (3.11, 3.12, 3.13, 3.14)
HTTP operations 14
Config axes 1
Extension points 7
Error codes 67
Documented flows 2
Fleet dependencies stapel-auth (optional) · stapel-core · stapel-orders (optional)

Documentation

OpenAPI · capabilities.json · llms.txt (for agents)

What this is

Promo codes and automatic discounts for a Stapel shop: "a promo code", "a sale", "free shipping over N". Staff define promotions; shoppers unlock them with codes (or get them automatically); the orders checkout asks this brick for the discount and records every use on a ledger, so usage caps hold even when two shoppers race for the last use.

The brick never imports stapel-orders: it answers the orders checkout contract by comm Function name (promotions.quote is the discount adjuster, promotions.reserve/commit/release the checkout hook).

Quick start

INSTALLED_APPS = [
    # ...
    "stapel_promotions",
]

# urls.py
path("promotions/api/", include("stapel_promotions.urls"))   # -> /promotions/api/v1/...

# settings.py — expire lapsed holds, purge old attempts (Celery optional)
from stapel_promotions.beat import get_promotions_beat_schedule
CELERY_BEAT_SCHEDULE = {**get_promotions_beat_schedule()}

Wire it into the orders checkout. A scaffolded project already calls the merge helper in settings.py: add this brick's preset to that list (the helper merges two levels deep, so other presets and your own keys stay):

_stapel_merge_preset_defaults(globals(), [
    # ... the presets already listed (stapel_shop.preset, other companions),
    "stapel_promotions.preset",
])

A hand-wired project merges per key instead — never assign STAPEL_ORDERS = {...}: pasted after another fragment it would drop that fragment and the host's PURCHASABLE_TYPES:

from stapel_promotions.preset import SETTINGS_DEFAULTS as _PROMOTIONS

STAPEL_ORDERS = globals().get("STAPEL_ORDERS") or {}
STAPEL_ORDERS = {
    **STAPEL_ORDERS,
    "ADJUSTERS": {**_PROMOTIONS["STAPEL_ORDERS"]["ADJUSTERS"], **STAPEL_ORDERS.get("ADJUSTERS", {})},
    "CHECKOUT_HOOKS": {**_PROMOTIONS["STAPEL_ORDERS"]["CHECKOUT_HOOKS"], **STAPEL_ORDERS.get("CHECKOUT_HOOKS", {})},
}

The shopper's codes travel in the orders checkout context: {"codes": ["SUMMER10"]} on quote and on checkout.

Concepts

  • Promotion — percent (capped by max_discount), fixed (in one currency) or free_shipping; scope cart, one purchasable_type, or a list of keys; a [starts_at, ends_at) window; min_subtotal; stackable; priority; usage_limit_total and usage_limit_per_user; automatic = applies with no code.
  • Promo code — many per promotion, stored upper-cased (case-insensitive by construction), optional per-code usage_limit (1 = single-use) and assigned_user_id (only that shopper). Bulk generation: manage.py promotions_generate_codes <key> <count> or the staff API.
  • Ledger — one Redemption per promotion per checkout attempt: reserved → committed → (released on cancel); a hold that lapses is expired. Caps count committed uses plus live holds, under the promotion's row lock.
  • Stacking — all stackable promotions together, or one non-stackable alone, whichever saves the shopper more. Free shipping breaks ties.
  • Free shipping — a zero-amount discount adjustment with meta.free_shipping: true; the shipping adjuster (order 200, after discounts) sees it in adjustments_so_far and quotes its line at 0.
  • Money — Decimal end to end, strings on the wire. A percent rounds half-up to the cent; shares across lines round down with the leftover cents to the largest remainders. A discount never exceeds the line totals it applies to.

API

Method Path Who
GET active/ anyone — live automatic promotions for a banner
POST codes/validate/ anyone (throttled) — would this code apply
GET/POST staff/promotions/ staff
GET/PATCH/DELETE staff/promotions/{id}/ staff
GET/POST staff/promotions/{id}/codes/ staff
POST staff/promotions/{id}/codes/generate/ staff
GET staff/promotions/{id}/redemptions/ staff
PATCH/DELETE staff/codes/{id}/ staff

Functions: promotions.quote, promotions.reserve, promotions.commit, promotions.release, promotions.codes.issue, promotions.codes.revoke. Facts: promotions.redemption.committed, promotions.redemption.released, promotions.promotion.exhausted. Settings: CONFIG.MD. Design: docs/SPEC.md. Extension points: MODULE.md.

License

MIT — see LICENSE.


This page is assembled by stapel-readme from docs/readme.md plus the contract artifacts in docs/. Edit the prose in docs/readme.md; the badges, facts and links above and below it are generated — do not hand-edit README.md.

Metadata

Release files for stapel-promotions 0.1.0

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

Source distribution (sdist)

Source distribution for stapel-promotions 0.1.0
File Size Uploaded Provenance Actions
stapel_promotions-0.1.0.tar.gz 99.3 kB With provenance Details for stapel_promotions-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stapel-promotions 0.1.0
File Interpreter ABI Platform Actions
stapel_promotions-0.1.0-py3-none-any.whl Python 3 none any Details for stapel_promotions-0.1.0-py3-none-any.whl

Total release size: 186.6 kB

Release files / stapel_promotions-0.1.0.tar.gz

Download URL stapel_promotions-0.1.0.tar.gz
Size 99.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e7f813858c1101985979e2c4c0a0efbe538db59aeeb1fdcf8e6f95a04d7da90b
BLAKE2b-256 checksum
How to use checksums
e8f70b0d39af91a67887599334f66e1f57becc4198083738b2063752622bc469
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 27, 2026.

Transparency log

Release files / stapel_promotions-0.1.0-py3-none-any.whl

Download URL stapel_promotions-0.1.0-py3-none-any.whl
Size 87.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b63311488245198eae3d8d2b1e9684dc35809643f15eacff96ff8e15c101eaf
BLAKE2b-256 checksum
How to use checksums
2a80544f4e107145c482b3ed1209d2c412dd19efe8cff582890a220fd07dfb70
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 27, 2026.

Transparency log

Security for stapel-promotions 0.1.0

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 stapel_promotions-0.1.0.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 27, 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.1.0 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