Skip to main content

Library for simple PostgreSQL connection and transaction management

Project description

zpgdb - Python library for simple PostgreSQL connection and transaction management

zpgdb is a small library to ease the management of PostgreSQL database connection between your app modules and packages, and provides a simple context manager to wrap code that should run database commands inside a transaction, with automatic commit or rollback.

Database connections are reused and one connection is opened by thread. Only one connection type is permitted at this time (eg, the same host, port, user and password and database).

Persistent connections are tested before used for commands, and they are automatically reopened in case they were lost, dealing with PostgreSQL restarts transparently.

How to install

pip install zpgdb

How to use

# You can import the module on every package/module you want to share
# the database connection.
import zpgdb as db

# The access configuration needs to be done only one time, preferably
# inside your __main__ block.
db.config_connection(host, port, user, password, database)

# You can get the connection object directly. `getdb()` will start a
# new connection if there is no connection opened with the actual thread.
dbh = db.getdb()

# Or you can start a context manager getting a cursor, with automatic
# commit on finish, or rollback in case there is a exception thrown.
with db.trans() as c:
	c.execute('...')
	c.execute('...')
	for row in c:
		...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zpgdb-0.5.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zpgdb-0.5.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file zpgdb-0.5.0.tar.gz.

File metadata

  • Download URL: zpgdb-0.5.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for zpgdb-0.5.0.tar.gz
Algorithm Hash digest
SHA256 68111c15503a7d9975e378f787772fadd110d4571671027ad7ff93e228465a62
MD5 cd4962dda8534b7df965122e4342a899
BLAKE2b-256 0b43dd448e7d6911ce7d43c794fc3013b0271ff0843c401bd6c000958c5d33c4

See more details on using hashes here.

File details

Details for the file zpgdb-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: zpgdb-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.2

File hashes

Hashes for zpgdb-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 473c2812763f171c99bf234be481b7f76b1d82da22f60201f7bd3a5acc35639e
MD5 f2a0efc507fc86af64d4f89aad14e816
BLAKE2b-256 a4a089c48e8d0206f6d13a91b914d1a6135fbda791b728fe997b2c27915dd1d9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page