Metadata-Version: 2.4
Name: stapel-reservations
Version: 0.1.0
Summary: Schedules, slots and reservations over opaque bookables for the Stapel framework
License: MIT
Project-URL: Homepage, https://github.com/usestapel/stapel-reservations
Project-URL: Repository, https://github.com/usestapel/stapel-reservations
Project-URL: Documentation, https://github.com/usestapel/stapel-reservations#readme
Project-URL: Changelog, https://github.com/usestapel/stapel-reservations/blob/main/CHANGELOG.md
Project-URL: Issues, https://github.com/usestapel/stapel-reservations/issues
Keywords: django,stapel,reservations,booking,appointments,scheduling
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"
Requires-Dist: stapel-billing<1,>=0.24.1; 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-reservations

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

> Schedules, free slots and reservations over opaque bookables. A host registers what can be booked (bookable_type -> a keyed-batch resolver Function answering title, price, currency, availability and the provider's seller_id — the listings.purchasables contract, so a service listing is bookable with no change to listings). Each bookable has a schedule of weekly rules in a named time zone, dated exceptions, duration, capacity, lead time, horizon and a cancellation window; until its provider saves one it offers DEFAULT_SCHEDULE. Free slots are computed on read with zero comm calls. A booking is idempotent on a client key and re-counts the slot under a lock on the schedule row, so two customers racing for the last seat end as one reservation and one slot_full. Reservations follow a table FSM (auto- or manual confirmation, customer cancel inside the window, provider confirm/cancel/no-show, completion by beat); payment is a provider seam (none, mock) whose outcome arrives as the reservations.payment.completed fact (or the payment module's payment.completed).

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-reservations
```

## At a glance

| Fact | Value |
|---|---|
| Version | `0.1.0` |
| Python | `>=3.11` (3.11, 3.12, 3.13, 3.14) |
| HTTP operations | 9 |
| Config axes | 5 |
| Usage surface | 13 |
| Extension points | 9 |
| Error codes | 64 |
| Documented flows | 3 |
| Fleet dependencies | [`stapel-auth`](https://github.com/usestapel/stapel-auth) (optional) · [`stapel-core`](https://github.com/usestapel/stapel-core) · [`stapel-currencies`](https://github.com/usestapel/stapel-currencies) (optional) · [`stapel-listings`](https://github.com/usestapel/stapel-listings) (optional) · [`stapel-notifications`](https://github.com/usestapel/stapel-notifications) (optional) |

## Documentation

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

## What this is

Schedules, free slots and reservations for a Stapel booking site — over
**opaque bookables**. The module ships knowing nothing about what is booked:
a host registers each bookable type with a comm Function that resolves a
keyed batch of keys to title, price and the provider who owns it. The
contract is `listings.purchasables`, so a service listing is bookable with
no change to listings, and a room, a table or a class from a custom app is
booked through the same calendar.

## Quick start

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

STAPEL_RESERVATIONS = {
    "BOOKABLE_TYPES": {
        "listing": {"resolve": "listings.bookables"},  # stapel-booking preset default
    },
}

# urls.py
path("reservations/api/", include("stapel_reservations.urls"))   # -> /reservations/api/v1/...

# settings.py — reminders, completion, idempotency purge (Celery optional)
from stapel_reservations.beat import get_reservations_beat_schedule
CELERY_BEAT_SCHEDULE = {**get_reservations_beat_schedule()}
```

A custom bookable is one resolver and one registration:

```python
from stapel_core.comm import function

@function("hotel.bookables")
def bookables(payload):
    rooms = Room.objects.filter(pk__in=payload["keys"])
    return {str(r.pk): {"title": r.name, "price": str(r.rate), "currency": "USD",
                        "available": r.active, "seller_id": str(r.manager_id),
                        "image": None, "url": f"/rooms/{r.pk}"}
            for r in rooms}

# AppConfig.ready()
from stapel_reservations.registry import register_bookable_type
register_bookable_type("room", {"resolve": "hotel.bookables"})
```

## Concepts

- **Bookable** — an opaque pair `(bookable_type, bookable_key)`. The
  resolver answers "what and whose" (title, price per reservation, the
  provider's `seller_id`); `price: null` books for free. It is asked when a
  reservation is booked and when a provider saves a schedule — never on a
  read.
- **Schedule** — "when": weekly rules in a named IANA time zone, dated
  exceptions (closed, or other hours), duration, step, capacity, lead time,
  horizon, cancellation window. Until the provider saves one, a bookable
  offers `DEFAULT_SCHEDULE` (weekdays 09:00–18:00 UTC, one-hour slots), so a
  fresh site is bookable on day one.
- **Slots** — computed on read from the schedule minus holding
  reservations; never stored. Local wall-clock time; a start inside a DST
  gap is skipped, an ambiguous one takes its first occurrence.
- **Booking** — one idempotent call (`idempotency_key`). The slot is
  re-counted under a lock on the bookable's schedule row: two customers
  racing for the last seat end as one reservation and one
  `error.409.slot_full`. Guests are asked to sign in unless
  `BOOKING_REQUIRES_ACCOUNT` is off.
- **Reservation** — `confirmed` at once (or `pending` with
  `AUTO_CONFIRM` off), cancelled by the customer inside the window or by the
  provider any time, `no_show` after the start, `completed` by the beat an
  hour after the end, `needs_review` when a payment does not match. The
  customer's history and the provider's agenda are anchor-paginated.
- **Payment** — a provider seam: `none` (pay on site) or `mock` (prototype
  posture only). The outcome arrives as `reservations.payment.completed`
  (what providers registered here emit; the mock marks it `simulated`) or
  as the payment module's `payment.completed`, the one path that marks a
  reservation paid. Reservations never emits `payment.completed`.
- **GDPR** — erasure deletes the person's schedules and pseudonymizes them
  on reservations; amounts and times stay.

## License

MIT — see [LICENSE](https://github.com/usestapel/stapel-reservations/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>
