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 .
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-2.2.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

pgserviceparser-2.2.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pgserviceparser-2.2.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for pgserviceparser-2.2.1.tar.gz
Algorithm Hash digest
SHA256 be39689680e97caed90cf55c3cfde2fadcd43640341e2fa5a1a6e29e2f14ebcc
MD5 2ea32d06cfad276bd57635b63784b9d8
BLAKE2b-256 3dab68d1160786b12420677f9bdda54b9ad71a524aeb0b777802e6dd59b3fe7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pgserviceparser-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 87a03b22e59a6f782fb5c7f24099fb0fc9bcf3ee2e412a4cf9d67cc075eec5ec
MD5 e768acb048da1007b9a42f77d39f741a
BLAKE2b-256 7619286bf07d4d7ea3c21177dbbf2c615570fbf119b8094affd809a66c43013e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page