A python package parsing the PostgreSQL connection service file.
>>> import pgserviceparser
Returns the path found for the pg_service.conf on the system as string.
>>> pgserviceparser.conf_path()
'/home/dave/.pg_service.conf'
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']
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'}
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:
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")
pip install -e .
export PGSERVICEPARSER_SRC_DIR=$pwd
python -m unittest test.test_lib
pip install pre-commit
pre-commit install
pip install -e .[docs]
mkdocs build -f docs/mkdocs.yml