simplebroker-pg
Postgres backend plugin for SimpleBroker.
This package is intentionally separate from simplebroker itself. SimpleBroker
remains SQLite-first. This package adds a Postgres backend through the public
backend plugin hook.
Requirements
- Python 3.11+
- PostgreSQL
- A dedicated schema for SimpleBroker tables
public is intentionally rejected.
Exact-target broadcast requires backend API v5: SimpleBroker 5.6.1 or newer
and simplebroker-pg 3.3.1 or newer. Default selection intersects requested
names with existing queues. Python create_missing=True instead inserts into
the complete requested set, intentionally recreating a queue deleted before
the broadcast lock is acquired. Selection and insertion occur in one
PostgreSQL transaction.
SimpleBroker 7.1.0 and simplebroker-pg 3.6.0 are the first coordinated
backend API v6 set, which adds terminal activity-waiter close. Package
dependency floors are minimums; the exact runtime handshake remains
authoritative for every installed pair.
SimpleBroker 7.3.0 and simplebroker-pg 3.8.0 are the first coordinated
backend API v7 set. It adds the required monotone durable high-water advance
used by persistence restore. Package dependency floors remain minimums; the
exact runtime handshake remains authoritative for every installed pair.
Timestamp resynchronization uses a guarded compare-and-advance update. If a
concurrent allocator publishes a higher durable last_ts after repair begins,
the repair preserves that winner and refreshes its local cache from the
surviving value; it never moves PostgreSQL high-water backward.
Core Compatibility
This first-party extension moves in lockstep with the SimpleBroker backend seam, although the core and extension package version numbers do not match. The extension declares its backend API version independently, and SimpleBroker checks that handshake when it resolves the plugin. An incompatible pair fails at backend resolution with upgrade-or-pin guidance instead of running against an unknown interface. The backend API version is separate from the PostgreSQL storage schema version and is not stored in the database.
Use core and extension releases published together. The package dependency is
an install-time minimum; the runtime handshake is the authoritative interface
check. Install the extension through the core release's pg extra. See the
backend authoring guide
for the handshake boundary.
Installation
# Fresh install through SimpleBroker's convenience extra
pipx install "simplebroker[pg]"
# Add to an existing pipx-installed simplebroker (recommended)
pipx inject simplebroker simplebroker-pg
# Or install through the convenience extra in a project
uv add "simplebroker[pg]"
# Or install the extension directly with uv
uv add simplebroker-pg
# Or install the extension directly with pip
pip install simplebroker-pg
simplebroker[pg] still installs this package as a separate distribution.
Postgres support is not built into the default simplebroker install.
Python Usage
from simplebroker import Queue
from simplebroker_pg import PostgresRunner
runner = PostgresRunner(
"postgresql://postgres@127.0.0.1:54329/simplebroker_test",
schema="simplebroker_app",
)
queue = Queue("jobs", runner=runner, persistent=True)
try:
queue.write("hello")
print(queue.read())
finally:
queue.close()
runner.close()
Multi-Queue Activity Waiters
Postgres supports simplebroker.create_activity_waiter_for_queues(...) with
one process-local shared LISTEN/NOTIFY listener per DSN and schema. The waiter
wakes when any watched queue receives activity, ignores unrelated queue
notifications, and returns the same ActivityWaiter | None shape as the core
API.
Wakeups are hints. After wait(timeout) returns True, callers should still
drain queues through normal SimpleBroker reads or moves. Close the multi-queue
waiter explicitly when the watcher lifecycle ends. Its first close() is
terminal before cleanup; every later call is a no-op, including when the first
call raised. The waiter owns registrations, not the runner or shared listener,
and does not expose shutdown().
CLI Usage
Create .broker.toml in the project root, or use the configured
BROKER_PROJECT_CONFIG_PATH / BROKER_PROJECT_CONFIG_NAME location:
version = 1
backend = "postgres"
target = "postgresql://postgres@127.0.0.1:54329/simplebroker_test"
[backend_options]
schema = "simplebroker_app"
Then use the normal CLI from any child directory with project scope enabled:
broker init
broker write jobs hello
broker read jobs
You can also run entirely from environment variables without a project config:
BROKER_BACKEND=postgres \
BROKER_BACKEND_TARGET='postgresql://postgres@127.0.0.1:54329/simplebroker_test' \
BROKER_BACKEND_SCHEMA='simplebroker_app' \
BROKER_BACKEND_PASSWORD='postgres' \
broker init
Notes:
- In env-only backend configuration,
BROKER_BACKEND_TARGEToverrides the host/port/user/database parts. BROKER_BACKEND_HOST,BROKER_BACKEND_PORT,BROKER_BACKEND_USER,BROKER_BACKEND_PASSWORD, andBROKER_BACKEND_DATABASEare only used when there is no target from project config or env.- When project TOML provides the target or schema, the project file wins.
BROKER_BACKEND_PASSWORDcan still be supplied from env and is never written to project TOML. - The Postgres database must already exist.
broker initcreates the managed schema/tables inside that database; it does not create the database itself. - Missing backend/plugin errors are distinct from target/auth errors. Invalid schema names, bad passwords, malformed targets, and missing databases are reported as validation or connection failures, not as "backend not available" errors.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simplebroker_pg-3.9.1.tar.gz.
File metadata
- Download URL: simplebroker_pg-3.9.1.tar.gz
- Upload date:
- Size: 22.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c0a392746a9e4a3bf7eb7ca48ad2842ff7c4ae7168469e5afce7882ab337340
|
|
| MD5 |
482011bf996bd324d72d0142410cd6ce
|
|
| BLAKE2b-256 |
ca003aa35865a45bc47817c237f1aeb11d0960dfd068ca2551cb524f2d6fe436
|
Provenance
The following attestation bundles were made for simplebroker_pg-3.9.1.tar.gz:
Publisher:
release-gate-pg.yml on VanL/simplebroker
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simplebroker_pg-3.9.1.tar.gz -
Subject digest:
3c0a392746a9e4a3bf7eb7ca48ad2842ff7c4ae7168469e5afce7882ab337340 - Sigstore transparency entry: 2581792800
- Sigstore integration time:
-
Permalink:
VanL/simplebroker@36bc6d4d0c079928ef051ea7129c78245c2ee058 -
Branch / Tag:
refs/tags/simplebroker_pg/v3.9.1 - Owner: https://github.com/VanL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-gate-pg.yml@36bc6d4d0c079928ef051ea7129c78245c2ee058 -
Trigger Event:
push
-
Statement type:
File details
Details for the file simplebroker_pg-3.9.1-py3-none-any.whl.
File metadata
- Download URL: simplebroker_pg-3.9.1-py3-none-any.whl
- Upload date:
- Size: 29.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca1902ca4ccf01b605295d0185d1a1587806284e885c85a06e8edcdbcf58206a
|
|
| MD5 |
5c630bec198716d94ab608b6914e8c4a
|
|
| BLAKE2b-256 |
d4fe3dc8d2a5bed869d1d4faf096d5d7160c712579a09d3ac59b76550b7d4fa0
|
Provenance
The following attestation bundles were made for simplebroker_pg-3.9.1-py3-none-any.whl:
Publisher:
release-gate-pg.yml on VanL/simplebroker
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simplebroker_pg-3.9.1-py3-none-any.whl -
Subject digest:
ca1902ca4ccf01b605295d0185d1a1587806284e885c85a06e8edcdbcf58206a - Sigstore transparency entry: 2581792813
- Sigstore integration time:
-
Permalink:
VanL/simplebroker@36bc6d4d0c079928ef051ea7129c78245c2ee058 -
Branch / Tag:
refs/tags/simplebroker_pg/v3.9.1 - Owner: https://github.com/VanL
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-gate-pg.yml@36bc6d4d0c079928ef051ea7129c78245c2ee058 -
Trigger Event:
push
-
Statement type: