Skip to main content

pgserviceparser

A python package parsing the PostgreSQL connection service file.

>>> import pgserviceparser

Finding the PostgreSQL connection service file with conf_path

Returns the path found for the pg_service.conf on the system as string.

>>> pgserviceparser.conf_path()
'/home/dave/.pg_service.conf'

Listing all the services with service_names

Returns all service names in a list. Optionally you can pass a config file path. Otherwise it gets it by conf_path.

>>> pgserviceparser.service_names()
['srvce_wandplaene', 'ktn_solothurn', 'daves_bakery']

Receiving the configuration for a service with service_config

Returns the config from the given service name as a dict. Optionally you can pass a config file path. Otherwise it gets it by conf_path.

>>> pgserviceparser.service_config('daves_bakery')
{'host': 'localhost', 'port': '5432', 'dbname': 'bakery', 'user': 'dave', 'password': 'fischersfritz'}

Getting the full configuration with full_config

Returns full pgservice config as configparser.ConfigParser(). Optionally you can pass a config file path. Otherwise it gets it by conf_path.

>>> pgserviceparser.full_config()
<configparser.ConfigParser object at 0x7f4c6d66b580>

Add a new service or remove one

Add a new service:

import pgserviceparser
new_srv_settings = {"host": "localhost", "dbname": "best_database_ever", "port": 5432, "user": "ro_gis_user"}
new_srv = pgserviceparser.write_service(service_name="gis_prod_ro", settings=new_srv_settings, create_if_not_found=True)
assert isinstance(new_srv, dict)

The PG service file has now:

[gis_prod_ro]
host=localhost
dbname=best_database_ever
port=5432
user=ro_gis_user

To remove it:

pgserviceparser.remove_service("gis_prod_ro")

Contribute

Test

pip install -e .
export PGSERVICEPARSER_SRC_DIR=$pwd
python -m unittest test.test_lib

Git hooks

pip install pre-commit
pre-commit install

Build documentation

pip install -e .[docs]
mkdocs build -f docs/mkdocs.yml

Metadata

Release files for pgserviceparser 2.3.0

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

Source distribution (sdist)

Source distribution for pgserviceparser 2.3.0
File Size Uploaded
pgserviceparser-2.3.0.tar.gz 9.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pgserviceparser 2.3.0
File Interpreter ABI Platform
pgserviceparser-2.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.3 kB

Release files / pgserviceparser-2.3.0.tar.gz

Download URL pgserviceparser-2.3.0.tar.gz
Size 9.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d485e8fb89c7e0c7b7aa0d8ae21d2924dce1e49bcd6b002e586f5d9c76e30254
BLAKE2b-256 checksum
How to use checksums
678264ecda2419f9c71a67a7df9f17216d8785a9b9902f49b9f183a85e21496d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 10, 2025.

Transparency log

Release files / pgserviceparser-2.3.0-py3-none-any.whl

Download URL pgserviceparser-2.3.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f5a6e98421e79bcfff3c59577679babbb78c3c91f50e63006c2efbdd7b10e613
BLAKE2b-256 checksum
How to use checksums
30322a47d6195b759d3e801652a406ef2ab30d80eab1ccf58f63a9bf4bc5d245
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.0.1 CPython/3.12.8

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 10, 2025.

Transparency log

Release history Release notifications | RSS feed

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

This release

2.3.0 This release

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

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