Skip to main content

A package parsing the PostgreSQL connection service file

Project description

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 .[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

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

pgserviceparser-3.0.0.tar.gz (353.1 kB view details)

Uploaded Source

Built Distribution

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

pgserviceparser-3.0.0-py3-none-any.whl (287.4 kB view details)

Uploaded Python 3

File details

Details for the file pgserviceparser-3.0.0.tar.gz.

File metadata

  • Download URL: pgserviceparser-3.0.0.tar.gz
  • Upload date:
  • Size: 353.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pgserviceparser-3.0.0.tar.gz
Algorithm Hash digest
SHA256 8ea08c7a41ee018e9f2ce70939dd7e8aa5ddfed16dd52ade37cc175a2e60fbee
MD5 cf8e6718af9a775f9e51ee0f8441435f
BLAKE2b-256 a5b4deca86cd7ba9f1a10163b0c1e2ac3a7e24fbb93c151436f80fc4cb0b64de

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgserviceparser-3.0.0.tar.gz:

Publisher: release.yml on opengisch/pgserviceparser

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pgserviceparser-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: pgserviceparser-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 287.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pgserviceparser-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0ba1078bb16cac346d70e603dfbbad4bf2c1ccb29d0f9fc5d121399bdd69811
MD5 a78c41f3eeb8b3bdd6be98d68c3c467b
BLAKE2b-256 60fc3eee30455f3c5add45eee99cbdab4fe25584970e084faf667b6c8ab1f9b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pgserviceparser-3.0.0-py3-none-any.whl:

Publisher: release.yml on opengisch/pgserviceparser

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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