About
dbsetupmate is a Python package and CLI, which overtakes a role of a database mate. Primary purpose is to create and maintain database schemas and users.
Install
Installation using uv
uv pip install dbsetupmate
Copy sample.env to .env and adjust the POSTGRESQL_* values.
Using Python package as CLI
- Show the available commands and options
dbsetupmate --help - Create a database together with its owner and login user
dbsetupmate --env-file .env postgresql create-db --new-db-name course_db_01 --new-db-user course_user_01 - Next free generated database name
dbsetupmate --env-file .env postgresql show-next-db-name - Create the shared database
dbsetupmate --env-file .env postgresql create-shared-db - Read-only user for the shared database
dbsetupmate --env-file .env postgresql create-shared-user-readonly - Grant an existing user read-only access to the shared database
dbsetupmate --env-file .env postgresql grant-shared-access --user-name course_user_01 - Revoke that access again
dbsetupmate --env-file .env postgresql revoke-shared-access --user-name course_user_01 - List the databases, the users and the resolved settings
dbsetupmate --env-file .env postgresql show-dbs dbsetupmate --env-file .env postgresql show-users dbsetupmate --env-file .env postgresql show-config - Change a user password
dbsetupmate --env-file .env postgresql set-user-password --user-name course_user_01 - Drop a database together with its roles
dbsetupmate --env-file .env postgresql drop-db --db-name course_db_01 --db-user course_user_01 - Drop a user
dbsetupmate --env-file .env postgresql drop-user --user-name course_user_01 - There is also a
dry-runoption for all commandsdbsetupmate --env-file .env --dry-run postgresql create-db
P.S. The password is prompted for when --new-db-password or --password is omitted.
Commands exit 1 on failure. drop-db and drop-user ask for confirmation; pass --yes to skip it.
Using Python package
Here is a example how to use dbsetupmate as Python library.
from dbsetupmate import PostgresMate, PostgreSQLConfig, DBSetupMateException
mate = PostgresMate(PostgreSQLConfig(host="db.internal", admin_password="..."))
try:
created = mate.create_db("course_db_01", "course_user_01", "s3cret")
except DBSetupMateException as ex:
print(ex)
PostgreSQLConfig.from_env() reads the POSTGRESQL_* variables instead. Failures raise a
subclass of DBSetupMateException, never a bool.
A fuller workflow — create a user, ensure the shared database exists, and grant that user read-only access to it:
from dbsetupmate import PostgresMate, PostgreSQLConfig, DBSetupMateException
mate = PostgresMate(PostgreSQLConfig.from_env())
config = mate.config
try:
# 1. Create a user together with its own database.
mate.create_db("course_db_01", "course_user_01", "s3cret")
# 2. + 3. Create the shared database only if it is not there yet.
if not mate.database_exists(config.shared_db):
mate.create_shared_db()
# 4. Give the new user read-only access to the shared database.
mate.grant_shared_access("course_user_01")
except DBSetupMateException as ex:
print(ex)
Development: Setup
This guide walks through setting up the project for local development using uv.
- Create a new virtual environment in a
.venvdirectory and activates it.uv venv - Activate the environment (macOS/Linux):
source .venv/bin/activate - Activate the environment (Windows):
call .venv/Scripts/activate.bat - Install package in editable mode with dev dependencies
Installing the package in editable mode (
-e) is the key to development.uv pip install -e . --group dev
Development: Running Tests
task py:pytest # unit tests, no database needed
task py:pytest-integration # against live PostgreSQL 15..18 (see compose-tests.yaml)
License
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 dbsetupmate-0.8.0.tar.gz.
File metadata
- Download URL: dbsetupmate-0.8.0.tar.gz
- Upload date:
- Size: 35.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a33186f36dfef69e5880dea2e6398731b766d620736e4b37b4f8e85498630eb2
|
|
| MD5 |
fae3408281fce4c75d112bd7c576c4db
|
|
| BLAKE2b-256 |
dda151c9404978eb1a248f909157ef08512bf64528450415ca690de00d5f7416
|
Provenance
The following attestation bundles were made for dbsetupmate-0.8.0.tar.gz:
Publisher:
publish-to-pypi.yml on vdmitriyev/dbsetupmate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dbsetupmate-0.8.0.tar.gz -
Subject digest:
a33186f36dfef69e5880dea2e6398731b766d620736e4b37b4f8e85498630eb2 - Sigstore transparency entry: 2414066708
- Sigstore integration time:
-
Permalink:
vdmitriyev/dbsetupmate@2f72bd4a8b49082c15828a4495960c752b8e71f5 -
Branch / Tag:
refs/tags/0.8.0 - Owner: https://github.com/vdmitriyev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@2f72bd4a8b49082c15828a4495960c752b8e71f5 -
Trigger Event:
push
-
Statement type:
File details
Details for the file dbsetupmate-0.8.0-py3-none-any.whl.
File metadata
- Download URL: dbsetupmate-0.8.0-py3-none-any.whl
- Upload date:
- Size: 30.8 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 |
d506d5103af73641cae6513ffbe7ac6bd099c8f0257d32cb016d8c1d533df863
|
|
| MD5 |
8362d445a07505480afc3ba097adb312
|
|
| BLAKE2b-256 |
7662de707f169692233960bc187671550869b7206bf35a382633c7e7eca23563
|
Provenance
The following attestation bundles were made for dbsetupmate-0.8.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on vdmitriyev/dbsetupmate
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dbsetupmate-0.8.0-py3-none-any.whl -
Subject digest:
d506d5103af73641cae6513ffbe7ac6bd099c8f0257d32cb016d8c1d533df863 - Sigstore transparency entry: 2414066758
- Sigstore integration time:
-
Permalink:
vdmitriyev/dbsetupmate@2f72bd4a8b49082c15828a4495960c752b8e71f5 -
Branch / Tag:
refs/tags/0.8.0 - Owner: https://github.com/vdmitriyev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@2f72bd4a8b49082c15828a4495960c752b8e71f5 -
Trigger Event:
push
-
Statement type: