Name | pgserviceparser JSON |
Version |
2.3.0
JSON |
| download |
home_page | None |
Summary | A package parsing the PostgreSQL connection service file |
upload_time | 2025-01-10 12:42:15 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT License |
keywords |
postgres
service
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# pgserviceparser
A python package parsing the PostgreSQL connection service file.
```python
>>> 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.
```python
>>> 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`.
```python
>>> 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`.
```python
>>> 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()](https://docs.python.org/3/library/configparser.html).
Optionally you can pass a config file path. Otherwise it gets it by `conf_path`.
```python
>>> pgserviceparser.full_config()
<configparser.ConfigParser object at 0x7f4c6d66b580>
```
## Add a new service or remove one
Add a new service:
```python
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:
```ini
[gis_prod_ro]
host=localhost
dbname=best_database_ever
port=5432
user=ro_gis_user
```
To remove it:
```python
pgserviceparser.remove_service("gis_prod_ro")
```
----
## Contribute
### Test
```sh
pip install -e .
export PGSERVICEPARSER_SRC_DIR=$pwd
python -m unittest test.test_lib
```
### Git hooks
```sh
pip install pre-commit
pre-commit install
```
### Build documentation
```sh
pip install -e .[docs]
mkdocs build -f docs/mkdocs.yml
```
Raw data
{
"_id": null,
"home_page": null,
"name": "pgserviceparser",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "postgres, service",
"author": null,
"author_email": "David Signer <info@opengis.ch>, Julien Moura <julien.moura@oslandia.com>, Germ\u00e1n Carrillo <info@opengis.ch>, Denis Rouzaud <info@opengis.ch>",
"download_url": "https://files.pythonhosted.org/packages/67/82/64ecda2419f9c71a67a7df9f17216d8785a9b9902f49b9f183a85e21496d/pgserviceparser-2.3.0.tar.gz",
"platform": null,
"description": "# pgserviceparser\n\nA python package parsing the PostgreSQL connection service file.\n\n```python\n>>> import pgserviceparser\n```\n\n## Finding the PostgreSQL connection service file with `conf_path`\n\nReturns the path found for the pg_service.conf on the system as string.\n\n```python\n>>> pgserviceparser.conf_path()\n'/home/dave/.pg_service.conf'\n```\n\n## Listing all the services with `service_names`\n\nReturns all service names in a list.\nOptionally you can pass a config file path. Otherwise it gets it by `conf_path`.\n\n```python\n>>> pgserviceparser.service_names()\n['srvce_wandplaene', 'ktn_solothurn', 'daves_bakery']\n\n```\n\n## Receiving the configuration for a service with `service_config`\n\nReturns the config from the given service name as a dict.\nOptionally you can pass a config file path. Otherwise it gets it by `conf_path`.\n\n```python\n>>> pgserviceparser.service_config('daves_bakery')\n{'host': 'localhost', 'port': '5432', 'dbname': 'bakery', 'user': 'dave', 'password': 'fischersfritz'}\n```\n\n## Getting the full configuration with `full_config`\n\nReturns full pgservice config as [configparser.ConfigParser()](https://docs.python.org/3/library/configparser.html).\nOptionally you can pass a config file path. Otherwise it gets it by `conf_path`.\n\n```python\n>>> pgserviceparser.full_config()\n<configparser.ConfigParser object at 0x7f4c6d66b580>\n```\n\n## Add a new service or remove one\n\nAdd a new service:\n\n```python\nimport pgserviceparser\nnew_srv_settings = {\"host\": \"localhost\", \"dbname\": \"best_database_ever\", \"port\": 5432, \"user\": \"ro_gis_user\"}\nnew_srv = pgserviceparser.write_service(service_name=\"gis_prod_ro\", settings=new_srv_settings, create_if_not_found=True)\nassert isinstance(new_srv, dict)\n```\n\nThe PG service file has now:\n\n```ini\n[gis_prod_ro]\nhost=localhost\ndbname=best_database_ever\nport=5432\nuser=ro_gis_user\n```\n\nTo remove it:\n\n```python\npgserviceparser.remove_service(\"gis_prod_ro\")\n```\n\n----\n\n## Contribute\n\n### Test\n\n```sh\npip install -e .\nexport PGSERVICEPARSER_SRC_DIR=$pwd\npython -m unittest test.test_lib\n```\n\n### Git hooks\n\n```sh\npip install pre-commit\npre-commit install\n```\n\n### Build documentation\n\n```sh\npip install -e .[docs]\nmkdocs build -f docs/mkdocs.yml\n```\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "A package parsing the PostgreSQL connection service file",
"version": "2.3.0",
"project_urls": {
"homepage": "https://opengisch.github.io/pgserviceparser/",
"repository": "https://github.com/opengisch/pgserviceparser",
"tracker": "https://github.com/opengisch/pgserviceparser/issues"
},
"split_keywords": [
"postgres",
" service"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "30322a47d6195b759d3e801652a406ef2ab30d80eab1ccf58f63a9bf4bc5d245",
"md5": "cee5e0d55e082ff0842e4ec218196edb",
"sha256": "f5a6e98421e79bcfff3c59577679babbb78c3c91f50e63006c2efbdd7b10e613"
},
"downloads": -1,
"filename": "pgserviceparser-2.3.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cee5e0d55e082ff0842e4ec218196edb",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 5224,
"upload_time": "2025-01-10T12:42:12",
"upload_time_iso_8601": "2025-01-10T12:42:12.596464Z",
"url": "https://files.pythonhosted.org/packages/30/32/2a47d6195b759d3e801652a406ef2ab30d80eab1ccf58f63a9bf4bc5d245/pgserviceparser-2.3.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "678264ecda2419f9c71a67a7df9f17216d8785a9b9902f49b9f183a85e21496d",
"md5": "d9ad0a38fbd5652c493c58a097995bc7",
"sha256": "d485e8fb89c7e0c7b7aa0d8ae21d2924dce1e49bcd6b002e586f5d9c76e30254"
},
"downloads": -1,
"filename": "pgserviceparser-2.3.0.tar.gz",
"has_sig": false,
"md5_digest": "d9ad0a38fbd5652c493c58a097995bc7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 9028,
"upload_time": "2025-01-10T12:42:15",
"upload_time_iso_8601": "2025-01-10T12:42:15.004955Z",
"url": "https://files.pythonhosted.org/packages/67/82/64ecda2419f9c71a67a7df9f17216d8785a9b9902f49b9f183a85e21496d/pgserviceparser-2.3.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-10 12:42:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "opengisch",
"github_project": "pgserviceparser",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pgserviceparser"
}