Parse PostgreSQL DSNs into PG* environment variables with export helpers.
Project description
pgdsn2env
Parse PostgreSQL DSN strings into PG* environment variables and emit shell-friendly outputs.
Install
uv add pgdsn2env
# or
pip install pgdsn2env
Optional DSN parsers:
uv add "pgdsn2env[psycopg3]"
# or
uv add "pgdsn2env[psycopg2]"
# or
pip install "pgdsn2env[psycopg3]"
# or
pip install "pgdsn2env[psycopg2]"
CLI usage
# Basic
❯ pgdsn2env "postgresql://user@location:5432/test"
export PGDATABASE=test
export PGHOST=location
export PGPORT=5432
export PGUSER=user
# With Keyword/Value Connection Strings, in JSON format
❯ pgdsn2env "host=localhost port=5432 dbname=mydb user=postgres password=secret" --format json
{"PGDATABASE": "mydb", "PGHOST": "localhost", "PGPASSWORD": "secret", "PGPORT": "5432", "PGUSER": "postgres"}
# Invoked as Python module, with advanced params
❯ python -m pgdsn2env --format dotenv "postgresql://postgres:secret@localhost:5432/mydb?sslmode=require&application_name=myapp"
PGAPPNAME=myapp
PGDATABASE=mydb
PGHOST=localhost
PGPASSWORD=secret
PGPORT=5432
PGSSLMODE=require
PGUSER=postgres
Python usage
from pgdsn2env import pg_dsn_to_env
pg_env = pg_dsn_to_env("postgresql://user@location:5432/test")
print(pg_env) # {'PGHOST': 'location', 'PGPORT': '5432', 'PGDATABASE': 'test', 'PGUSER': 'user'}
Recipes
Set PG* environment variables in your current shell:
source <(pgdsn2env "$DATABASE_URL")
Then verify the variables are set:
echo $PGHOST $PGPORT $PGDATABASE $PGUSER
Notes
- A DSN parser is required: install either
psycopgorpsycopg2. - Only parameters present in the DSN are emitted.
- Values are shell-quoted in CLI output.
Project details
Release history Release notifications | RSS feed
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 pgdsn2env-1.0.1.tar.gz.
File metadata
- Download URL: pgdsn2env-1.0.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a77c7e94bb0f5fe0f6a6fb314219d3a4ef47df53a0090a6d3f454bf716fff15c
|
|
| MD5 |
962860cf915c0c2ceeda089e61ea34d3
|
|
| BLAKE2b-256 |
95d1a56cae2e79936beb78d722955574af5b949ec2a0543963123398616d813f
|
Provenance
The following attestation bundles were made for pgdsn2env-1.0.1.tar.gz:
Publisher:
cd.yml on kafai-lam/pgdsn2env
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgdsn2env-1.0.1.tar.gz -
Subject digest:
a77c7e94bb0f5fe0f6a6fb314219d3a4ef47df53a0090a6d3f454bf716fff15c - Sigstore transparency entry: 856548165
- Sigstore integration time:
-
Permalink:
kafai-lam/pgdsn2env@e4a704dc20a74723ed608cffa82ba08af3789999 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kafai-lam
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@e4a704dc20a74723ed608cffa82ba08af3789999 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pgdsn2env-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pgdsn2env-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ace72663766fe2f7384e844f6399207cb37e172b67d96f54b1f14c09a83ac3e
|
|
| MD5 |
87b60faa18a4f3f13a0ea41ebd43cecc
|
|
| BLAKE2b-256 |
ef1494a57dcf792ded7f4b54418126ab88470a63651574ef3a5a9af0433aedf0
|
Provenance
The following attestation bundles were made for pgdsn2env-1.0.1-py3-none-any.whl:
Publisher:
cd.yml on kafai-lam/pgdsn2env
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pgdsn2env-1.0.1-py3-none-any.whl -
Subject digest:
0ace72663766fe2f7384e844f6399207cb37e172b67d96f54b1f14c09a83ac3e - Sigstore transparency entry: 856548205
- Sigstore integration time:
-
Permalink:
kafai-lam/pgdsn2env@e4a704dc20a74723ed608cffa82ba08af3789999 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/kafai-lam
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@e4a704dc20a74723ed608cffa82ba08af3789999 -
Trigger Event:
push
-
Statement type: