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'

Knowing how the service file path is determined with conf_path_source

Returns whether the path comes from the PGSERVICEFILE or PGSYSCONFDIR environment variable, or is the platform default.

>>> pgserviceparser.conf_path_source()
<ConfPathSource.DEFAULT: 'DEFAULT'>

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. Like libpq, if a service or a setting within a service is duplicated, only the first occurrence is used.

>>> 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")

Disable a service and restore it

A service can be disabled by commenting it out, the rest of the file is left untouched:

pgserviceparser.disable_service("gis_prod_ro")
#[gis_prod_ro]
#host=localhost
#dbname=best_database_ever
#port=5432
#user=ro_gis_user

Disabled services are kept when the service file is written. To list them, get their settings and restore them:

>>> pgserviceparser.disabled_service_names()
['gis_prod_ro']
>>> pgserviceparser.disabled_service_config("gis_prod_ro")
{'host': 'localhost', 'dbname': 'best_database_ever', 'port': '5432', 'user': 'ro_gis_user'}
>>> pgserviceparser.enable_service("gis_prod_ro")
True

Contribute

Test

pip install -e .[dev]
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 3.1.1

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 3.1.1
File Size Uploaded Provenance Actions
pgserviceparser-3.1.1.tar.gz 632.3 kB With provenance Details for pgserviceparser-3.1.1.tar.gz

Built distribution (wheel)

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

Total release size: 927.4 kB

Release files / pgserviceparser-3.1.1.tar.gz

Download URL pgserviceparser-3.1.1.tar.gz
Size 632.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5629a493a8e4a818ecf8d06bd875b7ae411340c3af62236c552490262d81ede6
BLAKE2b-256 checksum
How to use checksums
5e6d4b7f2121a6c4fc8def50a54ea08347e9cdca331f022792120a9cc2475de1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 2, 2026.

Transparency log

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

Download URL pgserviceparser-3.1.1-py3-none-any.whl
Size 295.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80c1b3bc12f6aea66930a4a985c3c63cf3763c0440a46d913893cc59baa3629e
BLAKE2b-256 checksum
How to use checksums
5048355f44ca0fbbc6a22717cf735e6a218939f7134dfddd324acaa45470cff8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 2, 2026.

Transparency log

Security for pgserviceparser 3.1.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pgserviceparser-3.1.1.tar.gz

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 Nov 2, 2026.

Transparency log

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.

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