neveroversell
Holds that cannot oversell. A Postgres library for selling a finite thing exactly once when payment is asynchronous: seats, tickets, stock, appointment slots, rental units, cohort places.
This is the Python client. It ships the same SQL as the TypeScript package, so both languages share one set of guarantees and one database schema. The full documentation, the design notes and the test results live in the repository README.
pip install neveroversell
Postgres 13 or newer. No extensions, no Redis, no queue.
from datetime import timedelta
from neveroversell import Inventory
inv = Inventory(
"postgres://user:pass@host/db",
hold_ttl=timedelta(minutes=15), # a basket lives 15 minutes
payment_window=timedelta(minutes=30), # once payment starts, 30 minutes; must exceed the TTL
)
inv.migrate()
inv.upsert_resource("flight_AI202_2026-10-01", 180)
held = inv.hold("flight_AI202_2026-10-01", 2, account_id=user.id, idempotency_key=basket.id)
if held.status != "held":
... # "insufficient" (held.available says how many are left), "account_cap", "unknown_resource"
inv.begin_payment(held.hold.id)
# From the return URL and from the webhook, in any order, any number of times:
result = inv.confirm(held.hold.id, payment.id)
match result.status:
case "confirmed": fulfil(result.hold)
case "already_confirmed": pass
case "duplicate_payment": refund(result.payment_ref) # keep result.existing_payment_ref
case "payment_ref_in_use": investigate(result.other_hold_id)
case "expired" | "released": refund(result.payment_ref)
case "not_found": pass
Run inv.sweep() every minute from a scheduler, or select nos_sweep() from pg_cron. inv.check() compares the counters with the rows whenever you want proof.
Every method returns a Result with a status string and the fields that status needs. Nothing throws for an expected outcome; exceptions are for programmer errors such as a non-positive quantity.
Pass your own psycopg_pool.ConnectionPool with Inventory(pool=...) to share connections with the rest of your application.
Release files for neveroversell 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| neveroversell-0.1.0.tar.gz | 12.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| neveroversell-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.5 kB
Release files / neveroversell-0.1.0.tar.gz
| Download URL | neveroversell-0.1.0.tar.gz |
|---|---|
| Size | 12.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a39222bb80f3538fd61fbbc679db3a1e8e06569d1145d51c16624ccdd5f23566
|
|
BLAKE2b-256 checksum How to use checksums |
da78855e6c209ca8b3ab343377ca33bfc47ab94eef7d41b9640360a8cff2d34e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 2, 2026.
Transparency logRelease files / neveroversell-0.1.0-py3-none-any.whl
| Download URL | neveroversell-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6c17b9be26d2e0ed1918a19fccb329c931b39911301696932196c1cee2c103a4
|
|
BLAKE2b-256 checksum How to use checksums |
4d6b006ddd3f0371a7b3129b39fb9deb5b4b4aa5b76841fd69baaa967ffb099a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 2, 2026.
Transparency log