Skip to main content

stapel-referrals

CI coverage pypi downloads python license llms.txt

Referral codes, attribution and rewards. Every member gets one personal code (minted lazily, collision-proof; vanity codes by policy) and a share link; staff issue campaign codes with a window and an attribution cap. A visitor's client stores the code on the first visit and claims it right after sign-up: the account is attributed once (unique constraint, first touch wins), self-referral, old accounts, stale captures and closed or used-up campaign codes are refused, and opt-in guards (same device, duplicate contact, custom) can refuse a claim with a recorded reason. Reward rules fire on facts — sign-up (user.signed_up), the first qualifying order or the Nth order (orders.order.placed) — for the referrer, the referee or both, with caps per referrer per rolling period and budgets counted under a lock on the rule row. The reward ledger is idempotent per (rule, attribution, trigger, role), holds order rewards for a period, rejects them when the order is cancelled during the hold and reverses them after it. Rewards are paid by a strategy that calls the paying brick by comm Function (billing_credit, promo_code) or just records them (noop); the module never imports auth, orders, billing or promotions.

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

Install

pip install stapel-referrals

At a glance

Fact Value
Version 0.1.0
Python >=3.11 (3.11, 3.12, 3.13, 3.14)
HTTP operations 17
Config axes 4
Usage surface 6
Extension points 7
Error codes 64
Documented flows 3
Fleet dependencies stapel-auth (optional) · stapel-billing (optional) · stapel-core · stapel-notifications (optional) · stapel-orders (optional) · stapel-promotions (optional)

Documentation

Errors: English · Español · Русский · OpenAPI · capabilities.json · llms.txt (for agents)

What this is

Referral codes, attribution and rewards for a Stapel product — "invite a friend, both get a bonus" and partner links. Every member gets one personal code (minted on first use, vanity codes by policy) and a share link; staff issue campaign codes with a window and a cap. A visitor's client stores the code on the first visit and claims it right after sign-up; the account is attributed once, first touch wins. Reward rules fire on facts — sign-up, the first qualifying order, the Nth order — and pay through a strategy that asks the paying brick by comm Function (billing_credit, promo_code) or just records the reward (noop). The module never imports auth, orders, billing or promotions.

Quick start

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

STAPEL_REFERRALS = {
    "SHARE_URL_TEMPLATE": "https://shop.example/r/{code}",
}

# urls.py
path("referrals/api/", include("stapel_referrals.urls"))   # -> /referrals/api/v1/...

# settings.py — grants after the hold, reversal retries, purge (Celery optional)
from stapel_referrals.beat import get_referrals_beat_schedule
CELERY_BEAT_SCHEDULE = {**get_referrals_beat_schedule()}

Then a staff member creates a rule (POST /referrals/api/v1/staff/rules/):

{"name": "Friend bonus", "trigger": "first_order", "min_order_total": "30.00",
 "currency": "USD", "beneficiary": "both", "strategy": "billing_credit",
 "referrer_params": {"credits": 100}, "referee_params": {"credits": 50},
 "cap_per_referrer": 10, "cap_period_days": 30}

The client side is two calls: GET me/ (my code and link) for the referrer, and POST claim/ {code, captured_at} right after sign-up for the referee.

Concepts

  • Code — personal (one primary per member; a vanity change retires the old code, which stays claimable so shared links keep working) or campaign (staff-owned, starts_at/ends_at, max_attributions). 31-symbol alphabet without look-alikes; case-insensitive.
  • Attribution — one per account, enforced by a unique constraint. Self referral, old accounts (CLAIM_MAX_ACCOUNT_AGE_HOURS), stale captures (ATTRIBUTION_WINDOW_DAYS) and closed or used-up campaign codes are refused. Opt-in guards (same_device, duplicate_contact, or your own) record a refused attribution that keeps the account's slot.
  • Reward rule — trigger, beneficiary (referrer / referee / both), strategy and params per beneficiary, caps per referrer per rolling period, budgets in triggers and in value, a hold for order rewards.
  • Reward — the ledger: pending → granted | rejected, granted → reversed. Idempotent on (rule, attribution, trigger, role). Caps are counted under a lock on the rule row. A provider failure keeps a reward pending and the beat retries; it is never recorded as a refusal. An order cancelled during the hold rejects its rewards; after the grant (within REVERSAL_WINDOW_DAYS) it reverses them.
  • GDPR — erasure pseudonymises the person on codes, attributions and rewards and replaces their code text; the ledger stays.

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-referrals 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-referrals 0.1.0
File Size Uploaded Provenance Actions
stapel_referrals-0.1.0.tar.gz 106.7 kB With provenance Details for stapel_referrals-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 200.6 kB

Release files / stapel_referrals-0.1.0.tar.gz

Download URL stapel_referrals-0.1.0.tar.gz
Size 106.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c93d9d1182713f8e3793fb99536c12584e020c6fde585dc08845d54773874108
BLAKE2b-256 checksum
How to use checksums
9038c714a3542204995b75ed103fc6d2091c111ac794f89b989324d436914de9
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_referrals-0.1.0-py3-none-any.whl

Download URL stapel_referrals-0.1.0-py3-none-any.whl
Size 93.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4bd2f5bc855fd520cff6fcfd1355a02b563290215ce5b134236cc218233eb620
BLAKE2b-256 checksum
How to use checksums
cdaf67d151f3420d615ea3a51b5bfa90d81bfb4459f214cc5445a26c3e80dff1
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-referrals 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_referrals-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