pgserviceparser


Namepgserviceparser JSON
Version 2.2.1 PyPI version JSON
download
home_pageNone
SummaryA package parsing the PostgreSQL connection service file
upload_time2024-08-07 22:08:34
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT 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/3d/ab/68d1160786b12420677f9bdda54b9ad71a524aeb0b777802e6dd59b3fe7a/pgserviceparser-2.2.1.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.2.1",
    "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": "7619286bf07d4d7ea3c21177dbbf2c615570fbf119b8094affd809a66c43013e",
                "md5": "e768acb048da1007b9a42f77d39f741a",
                "sha256": "87a03b22e59a6f782fb5c7f24099fb0fc9bcf3ee2e412a4cf9d67cc075eec5ec"
            },
            "downloads": -1,
            "filename": "pgserviceparser-2.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e768acb048da1007b9a42f77d39f741a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 5062,
            "upload_time": "2024-08-07T22:08:33",
            "upload_time_iso_8601": "2024-08-07T22:08:33.532426Z",
            "url": "https://files.pythonhosted.org/packages/76/19/286bf07d4d7ea3c21177dbbf2c615570fbf119b8094affd809a66c43013e/pgserviceparser-2.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3dab68d1160786b12420677f9bdda54b9ad71a524aeb0b777802e6dd59b3fe7a",
                "md5": "2ea32d06cfad276bd57635b63784b9d8",
                "sha256": "be39689680e97caed90cf55c3cfde2fadcd43640341e2fa5a1a6e29e2f14ebcc"
            },
            "downloads": -1,
            "filename": "pgserviceparser-2.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2ea32d06cfad276bd57635b63784b9d8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 8204,
            "upload_time": "2024-08-07T22:08:34",
            "upload_time_iso_8601": "2024-08-07T22:08:34.619427Z",
            "url": "https://files.pythonhosted.org/packages/3d/ab/68d1160786b12420677f9bdda54b9ad71a524aeb0b777802e6dd59b3fe7a/pgserviceparser-2.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-07 22:08:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "opengisch",
    "github_project": "pgserviceparser",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pgserviceparser"
}
        
Elapsed time: 0.35845s