Skip to main content

abstract_database

SQLite and PostgreSQL stores, portable schemas, and lazy connection/query helpers.

abstract_database is the connection layer of the Abstract Secure Backend stack. It resolves connection settings from your environment, manages connections to one or many databases, and provides thin helpers for tables and queries — without ever forcing a database connection before you actually need one.


Where this fits

abstract-securefiles   React/TypeScript UI components
abstract_logins        Flask blueprints: auth + secure files
abstract_queries       Domain query managers (users, uploads, ...)
abstract_database  <-- you are here: lazy PostgreSQL connection + helpers
abstract_security      Env loading, hashing, tokens, utilities

Dependencies flow downward; nothing reaches back up.


Install

pip install abstract_database

Requires Python ≥ 3.11. PostgreSQL APIs use psycopg[binary] and an existing server. The portable SQLite API uses Python’s standard library; no server is needed.


Configuration

Connection settings are read from the environment, so the package is portable across machines. Per-database keys follow <DBNAME>_<DBTYPE>_<FIELD> (upper-cased), or you can supply a single URL:

ABSTRACT_DATABASE_USER=app_user
ABSTRACT_DATABASE_PASSWORD=...
ABSTRACT_DATABASE_HOST=127.0.0.1
ABSTRACT_DATABASE_PORT=5432
ABSTRACT_DATABASE_DBNAME=app
# or:
ABSTRACT_DATABASE_URL=postgresql://app_user:...@127.0.0.1:5432/app

Optional locations:

Variable Purpose
ABSTRACT_DB_ENV_PATH Path to the .env file to read.
ABSTRACT_DB_TABLES_DIR Directory holding table-config JSON.
ABSTRACT_DB_TYPE Default db-type label (default database).

Quickstart

from abstract_database import connectionManager, get_cur_conn

# Constructing a manager does NOT open a connection.
db = connectionManager(dbName="app", dbType="database")

# The connection opens on first use; failures raise a clear ConnectionError.
cur, conn = get_cur_conn()           # RealDict cursor + connection
cur.execute("SELECT 1;")
print(cur.fetchone())
conn.close()

Portable schemas: SQLite or PostgreSQL

The new opt-in Database API creates either backend from one JSON/Python schema and provides shared CRUD, transactions/savepoints, and versioned additive upgrades. Choose the backend with a connection URL. Existing PostgreSQL APIs remain unchanged; this feature does not migrate application databases.

from abstract_database import Database

db = Database("sqlite:///catalog.sqlite3")
# Or: Database("postgresql://app_user@db-host:5432/catalog")
# db.ensure_schema(schema_dict)

See PORTABLE_DATABASE.md for the schema format, complete examples, supported migrations, and the boundaries of SQL portability.

Hugpy model database viewer (development utility)

The repository has a standalone, read-only browser for inspecting Hugpy's PostgreSQL model database. It opens on discovery_models, supports searching all columns, sorting by clicking column headers, and paging through results. Selecting a row shows an expandable, syntax-colored JSON tree with controls to expand or collapse nested values. The app-specific script is outside the abstract_database package and uses the package's generic DatabaseBrowser API.

The viewer runs as a persistent solcatcher user service on the Hugpy server and is proxied by nginx. On the LAN or WireGuard, open https://dev.hugpy.ai/modeldb/. Nginx restricts this route to LAN and WireGuard addresses.

The utility reads Hugpy's connection settings from /srv/hugpy/etc/hugpy-db.env and opens http://127.0.0.1:8765/.

Multiple databases

users = connectionManager(dbName="app",      dbType="database")
audit = connectionManager(dbName="auditlog", dbType="database")
# Distinct, independently-configured managers — no global clobbering.

Design notes

  • Lazy by default. Constructing a connectionManager never touches the database. The connection opens on first real use, so importing the package or booting an app never blocks (or fails) on an unreachable database. Table setup is deferred behind ensure_inserts().
  • Multi-DB safe. Managers are cached by connection identity (name / type / env-path / url) rather than a single global singleton, so several databases coexist cleanly. A no-argument connectionManager() still maps to one shared default.
  • Failures are visible. connect_db() raises a ConnectionError with the underlying cause instead of silently returning None and breaking three calls later.

License

MIT.

Metadata

Release files for abstract-database 0.0.2.207

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for abstract-database 0.0.2.207
File Size Uploaded Provenance Actions
abstract_database-0.0.2.207.tar.gz 100.2 kB Without provenance Details for abstract_database-0.0.2.207.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for abstract-database 0.0.2.207
File Interpreter ABI Platform Actions
abstract_database-0.0.2.207-py3-none-any.whl Python 3 none any Details for abstract_database-0.0.2.207-py3-none-any.whl

Total release size: 215.7 kB

Release files / abstract_database-0.0.2.207.tar.gz

Download URL abstract_database-0.0.2.207.tar.gz
Size 100.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9933a0c2632f950c6aa90f6da275d9287dafded8c51d399413e8c9456b998561
BLAKE2b-256 checksum
How to use checksums
5a726604c77ffd21583c40b3e34e09af3d4d6e4c1e303aeb3f9d28a3adeb259d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / abstract_database-0.0.2.207-py3-none-any.whl

Download URL abstract_database-0.0.2.207-py3-none-any.whl
Size 115.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4b9991028b0bc8ad8b5676b2bedeec77cad243ecb2ddad5746721be63e93882
BLAKE2b-256 checksum
How to use checksums
15b5e805c8cbd762ea761a1892ea8c2c7f9fe720d7f3523f123f5551114f5b7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for abstract-database 0.0.2.207

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.

Release history Release notifications | RSS feed

This release

0.0.2.207 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page