Netherframe PostgreSQL Backend
PostgreSQL backend implementation for Netherframe: state in PostgreSQL, with a state lock and conditional writes for hybrid execution.
Features
- PostgreSQL State Storage: Store infrastructure state in PostgreSQL with JSONB columns for optimal querying
- State Locking: one lock per state (
state_id), held by a hybrid run from planning through approval to the end of apply (see Locking) - ACID Transactions: Leverage PostgreSQL's ACID guarantees for state consistency
- Connection Pooling: Efficient connection management for high-performance operations
- Hybrid Mode Support: Works with both synthesis mode (Terraform) and hybrid execution mode
- Conditional Writes: a write replaces only the state version its run read (the state row is locked
FOR UPDATEwhile compared and written) - Force-Unlock and Checkpoints: a crashed run's lock is released by its ID (
nf state force-unlock); pre-apply checkpoints are rows of their own
Installation
pip install netherframe.backends.postgresql
Configuration
from nf.backends.postgresql import PostgreSQLBackend
# Basic configuration
backend = PostgreSQLBackend(
nf_scope=stack,
host="localhost",
port=5432,
database="netherframe_state",
username="nf_user",
password="your_password",
)
# Advanced configuration with SSL and custom schema
backend = PostgreSQLBackend(
nf_scope=stack,
host="db.example.com",
port=5432,
database="infrastructure",
username="nf_user",
password="your_password",
schema="netherframe",
ssl_mode="require",
table_prefix="nf_",
pool_size=10,
max_overflow=20,
)
Schema
The backend creates the following tables:
nf_states: Main state storage with JSONB datanf_locks: State locks, one perstate_idnf_resource_locks: Locks taken through the resource-lock API (see below); hybrid execution does not use them
Locking
Hybrid execution locks the whole state, as Terraform does; it does not lock individual resources:
applytakes the lock on itsstate_idbefore planning and holds it through the approval prompt to the end of the apply;planholds it while planning.- A second run on the same state does not wait: it fails to take the lock
(
Failed to acquire state lock) and logs who holds it. Concurrent applies on one state are therefore serialized, never interleaved. - Every state write is conditional: it replaces only the state version
(
serialandlineage) the run read, with the row lockedFOR UPDATEwhile it is compared and written. A saved plan is rejected if state changed since it was created. - The lock expires
lock_timeoutseconds (default 300) after its holder last renewed it; a running holder renews it in the background.nf state force-unlockreleases the lock of a crashed run at once.
Changes that must be applied independently, at the same time, need separate
states: give each independently deployed app its own state_id.
Resource-Lock API
The backend also has acquire_resource_lock, release_resource_lock,
release_all_resource_locks and resource_lock_context: shared and exclusive
locks on a resource id, with timeouts, stored in nf_resource_locks (see
example_usage.py). Netherframe's hybrid execution never calls them, and they
do not let two runs apply to one state at once. They are only useful to
coordinate your own tooling.
Settings
Each connection setting is a flag of nf, else a key of [tool.nf.config] in
pyproject.toml, else the backend's argument, else the default. Nothing is read from the
environment.
--postgresql-host/postgresql_host: Database host (default: localhost)--postgresql-port/postgresql_port: Database port (default: 5432)--postgresql-database/postgresql_database: Database name--postgresql-username/postgresql_username: Database username--postgresql-ssl-mode/postgresql_ssl_mode: SSL mode (disable, allow, prefer, require, verify-ca, verify-full)--postgresql-password-file/postgresql_password_file: File holding the database password (a mounted secret). The password is never a flag. In code,PostgreSQLBackendalso takespassword=, andPostgreSQLGraphBackendtakespassword_file=orpassword_source=(a callable).
[tool.nf.config]
postgresql_host = "db.internal"
postgresql_database = "netherframe"
postgresql_username = "nf_apply"
postgresql_password_file = "/run/secrets/postgresql-password"
See the Settings reference.
Metadata
Release files for netherframe.backends.postgresql 0.4.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 | Provenance | Actions |
|---|---|---|---|---|
| netherframe_backends_postgresql-0.4.0.tar.gz | 91.9 kB | Without provenance | Details for netherframe_backends_postgresql-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| netherframe_backends_postgresql-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for netherframe_backends_postgresql-0.4.0-py3-none-any.whl |
Total release size: 204.7 kB
Release files / netherframe_backends_postgresql-0.4.0.tar.gz
| Download URL | netherframe_backends_postgresql-0.4.0.tar.gz |
|---|---|
| Size | 91.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5bc49697db97744bae45dc1d6d1535331eba8bdd7956530bbbf8a8d6f186e42d
|
|
BLAKE2b-256 checksum How to use checksums |
354023b19413a653eed00ee68ead4a7063805c4839a7e1be970a34805aeca79a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / netherframe_backends_postgresql-0.4.0-py3-none-any.whl
| Download URL | netherframe_backends_postgresql-0.4.0-py3-none-any.whl |
|---|---|
| Size | 112.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5089085f8d3d79be59bbe42b5735803e766939e6aa86a2fa18045151fd498133
|
|
BLAKE2b-256 checksum How to use checksums |
ff00f7495659dbcf596faa98d00263e0e28b4219206c1dbb5f22a6073136773c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.9 {"installer":{"name":"uv","version":"0.13.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for netherframe.backends.postgresql 0.4.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.