Skip to main content

stapel-inventory

CI coverage pypi downloads python license llms.txt

Stock per location for opaque purchasables (the orders purchasable pair), an append-only movement ledger whose sum is on_hand, and checkout holds with a TTL. Plugs into stapel-orders as a checkout hook (reserve / commit / release, idempotent on the checkout attempt key): a reserve locks the stock rows in ascending id order and re-counts availability under the lock, all-or-nothing across lines, so two shoppers racing for the last unit end as one order and one error.409.insufficient_stock. Allocation across locations is a strategy (single_default, priority); oversell is an axis (deny, backorder) with a per-item override; untracked purchasables pass through. A public availability endpoint discloses in-stock / few-left / out-of-stock per a policy; staff receive, adjust with a reason, transfer and import CSV. Low-stock, out-of-stock, back-in-stock and oversold facts fire once per transition. Beat tasks expire holds of crashed checkouts and reconcile the cache with the ledger.

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

Install

pip install stapel-inventory

At a glance

Fact Value
Version 0.1.0
Python >=3.11 (3.11, 3.12, 3.13, 3.14)
HTTP operations 11
Config axes 6
Usage surface 5
Extension points 6
Error codes 54
Documented flows 2
Fleet dependencies stapel-auth (optional) · stapel-core · stapel-orders (optional)

Documentation

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

What this is

Stock for a Stapel shop — per location, with checkout holds and an append-only movement ledger — over the same opaque purchasables orders sells (purchasable_type, purchasable_key). Inventory never imports the module that owns a product. Installed next to stapel-orders it becomes a checkout hook: a checkout reserves stock, the placed order commits it, a failed checkout or a cancel releases it. Without orders its staff API, availability Function and facts work on their own.

Quick start

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

# urls.py
path("inventory/api/", include("stapel_inventory.urls"))   # -> /inventory/api/v1/...

# hold expiry (every minute) and ledger reconciliation (hourly); Celery optional
from stapel_inventory.beat import get_inventory_beat_schedule
CELERY_BEAT_SCHEDULE = {**get_inventory_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_inventory.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_inventory.preset import SETTINGS_DEFAULTS as _INVENTORY

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

Load stock and ask for it:

python manage.py inventory_import stock.csv --dry-run   # purchasable_type,purchasable_key,quantity[,location][,low_stock_threshold]
python manage.py inventory_import stock.csv
from stapel_core.comm import call

call("inventory.availability", {"purchasable_type": "listing", "keys": ["42", "43"]})
# -> {"items": {"42": {"tracked": true, "available": 3, "in_stock": true, ...}, ...}}

Concepts

  • Location — where stock sits. One default location (main) is created on migrate. ALLOCATION="single_default" sells only from it; "priority" sells from every active location, highest priority first, splitting a line when it must.
  • Stock item — one purchasable at one location. on_hand is a cache of the ledger; available = on_hand − active, unexpired holds.
  • Ledger — every change is a StockMovement (receipt, adjust, hold, commit, release, transfer, restock) written in the same transaction under the item's row lock; rows are never edited or deleted. The beat proves on_hand = Σ movements hourly and repairs a drifted cache from the ledger.
  • Hold — a checkout's claim, keyed on the checkout attempt key, with a TTL (HOLD_TTL_SECONDS, 30 min). Reserve locks the stock rows in ascending id order and re-counts under the lock, all-or-nothing across lines: two shoppers racing for the last unit end as one order and one error.409.insufficient_stock. Replays are idempotent; a released key reserves anew. A crashed checkout's hold is released by the beat.
  • Oversell — deny (default) refuses; backorder holds the remainder and lets stock go negative. A purchasable with no stock record is not stock-managed and always sells, unless TRACK_UNKNOWN="deny".
  • Availability — inventory.availability answers numbers to other modules; GET availability/ answers visitors what PUBLIC_AVAILABILITY allows (few_left by default: in stock / a few left / out / backorder).
  • Facts — inventory.stock.low, .out, .back_in_stock fire once per transition, never per sale; .oversold when an expired hold's order still had to be decremented.
  • GDPR — erasure pseudonymizes the shopper on holds and the staff member on the ledger; the numbers stay.

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-inventory 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-inventory 0.1.0
File Size Uploaded Provenance Actions
stapel_inventory-0.1.0.tar.gz 88.4 kB With provenance Details for stapel_inventory-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 169.8 kB

Release files / stapel_inventory-0.1.0.tar.gz

Download URL stapel_inventory-0.1.0.tar.gz
Size 88.4 kB
Tags Source
SHA-256 checksum
How to use checksums
05ecb890115c00cdbd426e6e5d7650ca7ff1aacd17e0b53c061b72720f0a72e1
BLAKE2b-256 checksum
How to use checksums
cf49658035f280aea7308d203833bdcf84d5b64b74d64e9246b55b849ce06200
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_inventory-0.1.0-py3-none-any.whl

Download URL stapel_inventory-0.1.0-py3-none-any.whl
Size 81.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
422e705a4583a1fade4d522e1c30f2f6d61812ee3c17719f1d72de6ed38e9c0b
BLAKE2b-256 checksum
How to use checksums
957a9e804573b3618ebe2da5cedb8fc359d0f3fbe281e19555fcd3effeced8c4
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-inventory 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_inventory-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