Name | pit-viper JSON |
Version |
1.1.0
JSON |
| download |
home_page | https://github.com/leoschleier/pit-viper |
Summary | Pit-Viper is a Python package that offers configuration management capabilities like the Viper package in Golang. |
upload_time | 2024-08-23 13:39:16 |
maintainer | None |
docs_url | None |
author | Leo Schleier |
requires_python | <4.0,>=3.11 |
license | MIT |
keywords |
pit-viper
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# pit-viper
Pit-Viper is a Python package that offers configuration management capabilities
like the Viper package in Golang.
## Table of Contents
1. [Installation](#installation)
2. [Usage](#usage)
3. [Development](#development)
## Installation
You can install `pit-viper` using `pip`:
```bash
pip install pit-viper
```
## Usage
### Environment Variables
The `pit-viper` package provides the `auto_env` function that loads environment
variables from a `.env` file. The function returns a `dict` of all existing
environment variables.
```python
from pit import viper
env = viper.auto_env()
```
We recommend accessing your environment variables via `viper.get`.
```python
from pit import viper
# Bind environment variables
viper.auto_env()
bar = viper.get("foo")
```
With this, you could also use`viper.set` to specify default parameters up
front.
**Note**: Changes to the environment following the first import of `pit-viper`
will not be reflected in the package's record of environment variables.
Prefixes are commonly being used to prevent name collisions in environment
variables. You can specify a prefix as follows:
```python
from pit import viper
viper.set_env_prefix("pf")
# Bind environment variables
viper.auto_env() # PF_FOO = "bar"
bar = viper.get("foo") # "bar"
```
We provide you with the option to overwrite env keys when querying
environment variables. For example, you might want to overwrite a `.`
used for retrieving parameters from a config with a `_` when accessing
environment variables. This can be useful for creating a mapping between
env keys and config keys.
```python
from pit import viper
# Bind environment variables
viper.auto_env() # MY_FOO = "bar"
viper.set_env_key_replacer({".": "_"})
bar = viper.get("my.foo") # "bar"
```
### Config Files
Config files are another config source for `pit-viper`. The package supports
loading, accessing, and setting defaults for a config. Supported file formats
are JSON, TOML, and YAML.
```python
from pathlib import Path
from pit import viper
MY_CONFIG_DIR = Path() / "config"
viper.set_config_path(MY_CONFIG_DIR)
viper.set_config_name("my_config")
viper.set_config_type("toml")
viper.set("foo", "default-value")
viper.load_config()
bar = viper.get("foo")
nested_parameter = viper.get("my.nested.parameter")
```
**Note**: After loading the environment varibles with `viper.auto_env`, every
call of `viper.get` will try to retrieve the parameter from the environment
variables before performing a lookup in the parameters of the config file.
## Development
We use [Poetry](https://github.com/python-poetry/poetry) for packaging and
dependency management.
We recommend creating your virtual environment in a directory named `.venv` in
the project's root directory. This ensures that all scripts and git hooks
relying on the Python environment will work properly. Therefore, after
installing Poetry, consider running the command below to configure Poetry for
the present project.
```bash
poetry config virtualenvs.in-project true --local
```
Afterward, you can run the `install` command to install the dependencies
(including development requirements) specified in the `pyproject.toml` or
`poetry.lock` file.
```bash
poetry install
```
For a more comprehensive description of the Poetry setup and commands, see
their [documentation](https://python-poetry.org/docs).
The `pit-viper` package is intended to be
[PEP 561](https://peps.python.org/pep-0561/) compatible. For this reason, we
use a pre-commit hook that validates the code on every commit. The code
validation runs tests and performs checks using Ruff, Mypy, and Pyright.
Execute `scripts/setup` to add the validation as your pre-commit hook for this
project.
Raw data
{
"_id": null,
"home_page": "https://github.com/leoschleier/pit-viper",
"name": "pit-viper",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": "pit-viper",
"author": "Leo Schleier",
"author_email": "43878374+leoschleier@users.noreply.github.com",
"download_url": "https://files.pythonhosted.org/packages/99/83/8fb312104f9fd55232330eda3f0452578e9b63623cee5c35ce62837b8997/pit_viper-1.1.0.tar.gz",
"platform": null,
"description": "# pit-viper\n\nPit-Viper is a Python package that offers configuration management capabilities\nlike the Viper package in Golang.\n\n## Table of Contents\n\n1. [Installation](#installation)\n\n2. [Usage](#usage)\n\n3. [Development](#development)\n\n## Installation\n\nYou can install `pit-viper` using `pip`:\n\n```bash\npip install pit-viper\n```\n\n## Usage\n\n### Environment Variables\n\nThe `pit-viper` package provides the `auto_env` function that loads environment\nvariables from a `.env` file. The function returns a `dict` of all existing\nenvironment variables.\n\n```python\nfrom pit import viper\n\nenv = viper.auto_env()\n```\n\nWe recommend accessing your environment variables via `viper.get`.\n\n```python\nfrom pit import viper\n\n# Bind environment variables\nviper.auto_env()\n\nbar = viper.get(\"foo\")\n```\n\nWith this, you could also use`viper.set` to specify default parameters up\nfront.\n\n**Note**: Changes to the environment following the first import of `pit-viper`\nwill not be reflected in the package's record of environment variables.\n\nPrefixes are commonly being used to prevent name collisions in environment\nvariables. You can specify a prefix as follows:\n\n```python\nfrom pit import viper\n\nviper.set_env_prefix(\"pf\")\n\n# Bind environment variables \nviper.auto_env() # PF_FOO = \"bar\" \n\nbar = viper.get(\"foo\") # \"bar\"\n```\n\nWe provide you with the option to overwrite env keys when querying\nenvironment variables. For example, you might want to overwrite a `.`\nused for retrieving parameters from a config with a `_` when accessing\nenvironment variables. This can be useful for creating a mapping between\nenv keys and config keys.\n\n```python\nfrom pit import viper\n\n# Bind environment variables \nviper.auto_env() # MY_FOO = \"bar\" \n\nviper.set_env_key_replacer({\".\": \"_\"})\n\nbar = viper.get(\"my.foo\") # \"bar\"\n```\n\n### Config Files\n\nConfig files are another config source for `pit-viper`. The package supports\nloading, accessing, and setting defaults for a config. Supported file formats\nare JSON, TOML, and YAML.\n\n```python\nfrom pathlib import Path\nfrom pit import viper\n\nMY_CONFIG_DIR = Path() / \"config\"\n\nviper.set_config_path(MY_CONFIG_DIR)\nviper.set_config_name(\"my_config\")\nviper.set_config_type(\"toml\")\n\nviper.set(\"foo\", \"default-value\")\n\nviper.load_config()\n\nbar = viper.get(\"foo\")\nnested_parameter = viper.get(\"my.nested.parameter\")\n```\n\n**Note**: After loading the environment varibles with `viper.auto_env`, every\ncall of `viper.get` will try to retrieve the parameter from the environment\nvariables before performing a lookup in the parameters of the config file.\n\n## Development\n\nWe use [Poetry](https://github.com/python-poetry/poetry) for packaging and\ndependency management.\nWe recommend creating your virtual environment in a directory named `.venv` in\nthe project's root directory. This ensures that all scripts and git hooks\nrelying on the Python environment will work properly. Therefore, after\ninstalling Poetry, consider running the command below to configure Poetry for\nthe present project.\n\n```bash\npoetry config virtualenvs.in-project true --local \n```\n\nAfterward, you can run the `install` command to install the dependencies\n(including development requirements) specified in the `pyproject.toml` or\n`poetry.lock` file.\n\n```bash\npoetry install\n```\n\nFor a more comprehensive description of the Poetry setup and commands, see\ntheir [documentation](https://python-poetry.org/docs).\n\nThe `pit-viper` package is intended to be\n[PEP 561](https://peps.python.org/pep-0561/) compatible. For this reason, we\nuse a pre-commit hook that validates the code on every commit. The code\nvalidation runs tests and performs checks using Ruff, Mypy, and Pyright.\nExecute `scripts/setup` to add the validation as your pre-commit hook for this\nproject.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Pit-Viper is a Python package that offers configuration management capabilities like the Viper package in Golang.",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://github.com/leoschleier/pit-viper"
},
"split_keywords": [
"pit-viper"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "052ecb611d52121a12b66d5716a472d69c6f60ec6116e92b36e06aae08838405",
"md5": "931f1a6ef62b5be59d47538e3bef542b",
"sha256": "2677433a570ca0f307fde5767a736909ca81f0647155eb2b2167d1911004a26f"
},
"downloads": -1,
"filename": "pit_viper-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "931f1a6ef62b5be59d47538e3bef542b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 7806,
"upload_time": "2024-08-23T13:39:15",
"upload_time_iso_8601": "2024-08-23T13:39:15.538606Z",
"url": "https://files.pythonhosted.org/packages/05/2e/cb611d52121a12b66d5716a472d69c6f60ec6116e92b36e06aae08838405/pit_viper-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "99838fb312104f9fd55232330eda3f0452578e9b63623cee5c35ce62837b8997",
"md5": "16e5928355bb4669b177cce964495280",
"sha256": "446c7e9953a5ec64990fc31a290722cd394970ab1878347c533c88b8cbb1a91b"
},
"downloads": -1,
"filename": "pit_viper-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "16e5928355bb4669b177cce964495280",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 6435,
"upload_time": "2024-08-23T13:39:16",
"upload_time_iso_8601": "2024-08-23T13:39:16.423639Z",
"url": "https://files.pythonhosted.org/packages/99/83/8fb312104f9fd55232330eda3f0452578e9b63623cee5c35ce62837b8997/pit_viper-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-23 13:39:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "leoschleier",
"github_project": "pit-viper",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pit-viper"
}