Metadata-Version: 2.4
Name: stapel-delivery
Version: 0.1.0
Summary: Delivery methods, rates, pickup points, address book and shipment tracking for the Stapel framework
License: MIT
Project-URL: Homepage, https://github.com/usestapel/stapel-delivery
Project-URL: Repository, https://github.com/usestapel/stapel-delivery
Project-URL: Documentation, https://github.com/usestapel/stapel-delivery#readme
Project-URL: Changelog, https://github.com/usestapel/stapel-delivery/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/usestapel/stapel-delivery/issues
Keywords: django,stapel,delivery,shipping,shipments,tracking,addresses
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: Django
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: stapel-core<1.0,>=0.99.3
Provides-Extra: all
Provides-Extra: test
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-django; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Requires-Dist: stapel-tools<1,>=0.84.0; extra == "test"
Requires-Dist: jsonschema>=4; extra == "test"
Dynamic: license-file

<!-- Generated by stapel-readme from docs/readme.md + docs/*.json. Do not edit this file; edit docs/readme.md and re-run `make readme`. -->

# stapel-delivery

[![CI](https://img.shields.io/github/actions/workflow/status/usestapel/stapel-delivery/ci.yml?branch=main&logo=github&label=CI)](https://github.com/usestapel/stapel-delivery/actions/workflows/ci.yml?query=branch%3Amain)
[![coverage](https://img.shields.io/codecov/c/github/usestapel/stapel-delivery?branch=main&logo=codecov&label=coverage)](https://app.codecov.io/gh/usestapel/stapel-delivery)
[![pypi](https://img.shields.io/pypi/v/stapel-delivery?logo=pypi&logoColor=white&label=pypi)](https://pypi.org/project/stapel-delivery/)
[![downloads](https://static.pepy.tech/badge/stapel-delivery/month)](https://pepy.tech/project/stapel-delivery)
[![python](https://img.shields.io/pypi/pyversions/stapel-delivery?logo=python&logoColor=white)](https://pypi.org/project/stapel-delivery/)
[![license](https://img.shields.io/github/license/usestapel/stapel-delivery)](https://github.com/usestapel/stapel-delivery/blob/main/LICENSE)
[![llms.txt](https://img.shields.io/badge/llms.txt-blue)](https://github.com/usestapel/stapel-delivery/blob/main/docs/llms.txt)

> Delivery methods (courier, pickup point, digital), zones matched by country / region / postcode prefix, rates (flat, free above a subtotal, per kilogram when cart lines carry attrs.weight_grams), pickup points with hours and coordinates, a per-user address book with one default, and shipments with a table FSM (pending, packed, shipped, delivered, returned, cancelled), a timeline, tracking number and link. It is the stapel-orders shipping adjuster (delivery.quote, kind shipping, order 200; honours a promotion's meta.free_shipping marker) and a checkout hook (delivery.reserve keeps the validated choice and the address snapshot under the checkout attempt key; commit creates the order's shipment; release on cancel cancels it). Carriers are a strategy registry: manual by default, an auto-advancing mock for prototypes, a documented Carrier ABC for real ones.

Part of the [Stapel framework](https://github.com/usestapel) — composable Django apps that deploy as a monolith or as microservices without changing module code.

## Install

```bash
pip install stapel-delivery
```

## At a glance

| Fact | Value |
|---|---|
| Version | `0.1.0` |
| Python | `>=3.11` (3.11, 3.12, 3.13, 3.14) |
| HTTP operations | 15 |
| Config axes | 2 |
| Usage surface | 9 |
| Extension points | 12 |
| Error codes | 55 |
| Documented flows | 4 |
| Fleet dependencies | [`stapel-auth`](https://github.com/usestapel/stapel-auth) (optional) · [`stapel-core`](https://github.com/usestapel/stapel-core) · [`stapel-geo`](https://github.com/usestapel/stapel-geo) (optional) · [`stapel-notifications`](https://github.com/usestapel/stapel-notifications) (optional) · [`stapel-orders`](https://github.com/usestapel/stapel-orders) (optional) · [`stapel-promotions`](https://github.com/usestapel/stapel-promotions) (optional) |

## Documentation

[OpenAPI](https://github.com/usestapel/stapel-delivery/blob/main/docs/schema.json) · [capabilities.json](https://github.com/usestapel/stapel-delivery/blob/main/docs/capabilities.json) · [llms.txt (for agents)](https://github.com/usestapel/stapel-delivery/blob/main/docs/llms.txt)

## What this is

Delivery for a Stapel shop: delivery methods (courier, pickup point,
digital), zones and rates, pickup points, a per-user address book, and
shipments with tracking. It plugs into **stapel-orders** without either
module importing the other: delivery is the orders shipping adjuster
(`delivery.quote`) and a checkout hook (`delivery.reserve` / `commit` /
`release`), and every placed order with a physical delivery gets a
shipment the buyer can track.

Without orders installed the catalog, the address book, the options
Function and the shipment API still work on their own.

## Quick start

```python
INSTALLED_APPS = [
    # ...
    "stapel_delivery",
]

# urls.py
path("delivery/api/", include("stapel_delivery.urls"))   # -> /delivery/api/v1/...

# carrier polling + intent purge (Celery optional: manage.py delivery_housekeeping)
from stapel_delivery.beat import get_delivery_beat_schedule
CELERY_BEAT_SCHEDULE = {**get_delivery_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):

<!-- orders-wiring:scaffold -->
```python
_stapel_merge_preset_defaults(globals(), [
    # ... the presets already listed (stapel_shop.preset, other companions),
    "stapel_delivery.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`:

<!-- orders-wiring:hand -->
```python
from stapel_delivery.preset import SETTINGS_DEFAULTS as _DELIVERY

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

Methods, zones, rates and pickup points are configured in the Django admin.
At checkout the client sends its choice in the orders `context`:

```json
{"delivery": {"method": "courier", "address": {"name": "Ada", "phone": "+1 555 0100",
  "line1": "1 Main St", "city": "Springfield", "postal_code": "62701", "country": "US"}}}
```

(`address_id` instead of `address` for a saved address; `pickup_point`
for a pickup method; nothing more for a digital one.)

**Delivery owns the delivery address.** `context.delivery` (`address` /
`address_id` / `pickup_point`) is the address the shipment is sent to. Orders still requires and stores its own `shipping_address`, which is never
compared with delivery's. The client sends the ship-to chosen in the delivery
widget as `shipping_address`, so the buyer types it once, and
`OrderResponse.address_from_delivery` is true when the order was placed with
`context.delivery`. The shipping adjustment's `code`
is the method code (e.g. `courier`), which orders records as the order's
shipping method.

## Concepts

- **Zone** — where a rate applies: lists of countries, regions and
  postcode prefixes (empty list = any). The most specific matching zone
  wins (longest postcode prefix, then region, then country); a rate with no
  zone applies everywhere. No GIS.
- **Rate** — per method, zone and currency: a flat amount, free above a
  cart subtotal, and an optional price per kilogram used when every
  shippable line carries `attrs.weight_grams` (the purchasable resolver's
  extra field); otherwise the flat amount. Never converted between
  currencies.
- **Free shipping from a promotion** — an earlier adjuster's adjustment
  with `meta.free_shipping: true` (optionally `meta.free_shipping_methods`)
  makes shipping 0.00.
- **Address book** — per user, one default, at most `MAX_ADDRESSES`.
  Checkout and shipments keep a **copy** of the address; editing or
  deleting a saved address never changes a placed order. Guests type the
  address inline.
- **Shipment** — one per order: `pending → packed → shipped → delivered`,
  `returned`, `cancelled`, with a timeline, a tracking number and link. An
  order cancelled before the parcel left cancels its shipment.
- **Carriers** — `manual` (staff type the tracking number) by default;
  `mock` advances shipments by itself for demos (prototype posture only);
  a real carrier is a small `Carrier` subclass registered by slug.
- **GDPR** — erasure deletes the address book and blanks the recipient on
  shipments; money, status and city/country stay.

## License

MIT — see [LICENSE](https://github.com/usestapel/stapel-delivery/blob/main/LICENSE).

---

<sub>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`.</sub>
