{"id":16750100,"url":"https://github.com/alexferl/vyper","last_synced_at":"2025-05-15T16:07:10.679Z","repository":{"id":43004973,"uuid":"62637407","full_name":"alexferl/vyper","owner":"alexferl","description":"Python configuration with (more) fangs","archived":false,"fork":false,"pushed_at":"2025-01-13T18:11:44.000Z","size":247,"stargazers_count":148,"open_issues_count":8,"forks_count":22,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-12T03:54:43.800Z","etag":null,"topics":["12-factor","config-management","configuration-management","python-configuration","python3","vyper","vyper-config"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexferl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-07-05T13:04:15.000Z","updated_at":"2025-03-17T13:28:49.000Z","dependencies_parsed_at":"2024-07-16T00:29:54.775Z","dependency_job_id":"8b7f5e3c-a12e-4ed2-8bbd-98b14193239c","html_url":"https://github.com/alexferl/vyper","commit_stats":{"total_commits":121,"total_committers":18,"mean_commits":6.722222222222222,"dds":0.6363636363636364,"last_synced_commit":"a0a6ea7f84544e598dd326a5fe8389346f59c64d"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fvyper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fvyper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fvyper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexferl%2Fvyper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexferl","download_url":"https://codeload.github.com/alexferl/vyper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254374475,"owners_count":22060611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["12-factor","config-management","configuration-management","python-configuration","python3","vyper","vyper-config"],"created_at":"2024-10-13T02:27:03.382Z","updated_at":"2025-05-15T16:07:10.653Z","avatar_url":"https://github.com/alexferl.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vyper [![codecov](https://codecov.io/gh/alexferl/vyper/branch/master/graph/badge.svg)](https://codecov.io/gh/alexferl/vyper)\n\nPython configuration with (more) fangs! Python port of the very awesome [Viper](https://github.com/spf13/viper) for Go.\n\n## PyPI name change\nThe package changed name on pypi from `vyper` to `vyper-config` on August 20th 2018.\nThe `vyper` name is now used by the following [project](https://github.com/ethereum/vyper).\nThe `vyper-config` package is available on [PyPI](https://pypi.org/project/vyper-config/).\n\n## What is Vyper?\n\nVyper is a complete configuration solution for Python applications including 12 factor apps. It is designed\nto work within an application, and can handle all types of configuration needs and formats. It supports:\n\n* setting defaults\n* reading from JSON, TOML, and YAML config files\n* live watching and re-reading of config files (optional)\n* reading from environment variables\n* reading from remote config systems (etcd, Consul or ZooKeeper)\n* live watching and re-reading of remote config files (optional)\n* reading from command line arguments\n* reading from buffer\n* setting explicit values\n\nVyper can be thought of as a registry for all of your applications\nconfiguration needs.\n\n## Why Vyper?\n\nWhen building a modern application, you don’t want to worry about\nconfiguration file formats; you want to focus on building awesome software.\nVyper is here to help with that.\n\nVyper does the following for you:\n\n1. Find, load, and unmarshall a configuration file in JSON, TOML, or YAML format.\n2. Provide a mechanism to set default values for your different\n   configuration options.\n3. Provide a mechanism to set override values for options specified through\n   command line arguments.\n4. Provide an alias system to easily rename parameters without breaking existing\n   code.\n5. Make it easy to tell the difference between when a user has provided a\n   command line or config file which is the same as the default.\n\nVyper uses the following precedence order. Each item takes precedence over the\nitem below it:\n\n * explicit call to set\n * argument\n * environment variable\n * config\n * key/value store\n * default\n\nVyper configuration keys are case insensitive.\n\n## Putting Values into Vyper\n\n### Establishing Defaults\n\nA good configuration system will support default values. A default value is not\nrequired for a key, but it's useful in the event that a key hasn't been set via\nconfig file, environment variable, remote configuration or argument.\n\nExamples:\n\n```python\nv.set_default('ContentDir', 'content')\nv.set_default('LayoutDir', 'layouts')\nv.set_default('Taxonomies', {'tag': 'tags', 'category': 'categories'})\n```\n\n### Reading Config Files\n\nVyper requires minimal configuration so it knows where to look for config files.\nVyper supports JSON, TOML and YAML files. Vyper can search multiple paths, but\ncurrently a single Vyper instance only supports a single configuration file.\nVyper does not default to any configuration search paths leaving defaults decision\nto an application.\n\nHere is an example of how to use Vyper to search for and read a configuration file.\nNone of the specific paths are required, but at least one path should be provided\nwhere a configuration file is expected.\n\n```python\nv.set_config_name('config')  # name of config file (without extension)\nv.add_config_path('/etc/appname/')  # path to look for the config file in\nv.add_config_path('$HOME/.appname')  # call multiple times to add many search paths\nv.add_config_path('.')  # optionally look for config in the working directory\nv.read_in_config()  # Find and read the config file\n```\n\n### Watching and re-reading config files\n\nVyper supports the ability to have your application live read a config file while running.\n\nGone are the days of needing to restart a server to have a config take effect,\nvyper powered applications can read an update to a config file while running and\nnot miss a beat.\n\nSimply tell the Vyper instance to watch_config().\nOptionally you can provide a function for Vyper to run each time a change occurs.\n\n**Make sure you add all of the config_paths prior to calling `watch_config()`**\n\n```python\nv.watch_config()\ndef f():\n    print('Config file changed')\nv.on_config_change(f)\n```\n\n### Reading Config from buffer\n\nVyper pre-defines many configuration sources such as files, environment\nvariables, arguments, and remote K/V store, but you are not bound to them. You can\nalso implement your own required configuration source and feed it to Vyper.\n\n```python\nv.set_config_type('yaml')  # or v.set_config_type('YAML')\n\n# any approach to require this configuration into your program.\nyaml_example = '''\nHacker: true\nname: steve\nhobbies:\n- skateboarding\n- snowboarding\n- go\nclothing:\n  jacket: leather\n  trousers: denim\nage: 35\neyes : brown\nbeard: true\n'''\n\nv.read_config(yaml_example)\n\nv.get('name')  # this would be 'steve'\n```\n\n### Setting Overrides\n\nThese could be from a command line argument, or from your own application logic.\n\n```python\nv.set('Verbose', True)\nv.set('LogFile', log_file)\n```\n\n### Registering and Using Aliases\n\nAliases permit a single value to be referenced by multiple keys\n\n```python\nv.register_alias('loud', 'Verbose')\n\nv.set('verbose', True)  # same result as next line\nv.set('loud', True)  # same result as prior line\n\nv.get_bool('loud')  # True\nv.get_bool('verbose')  # True\n```\n\n### Working with Environment Variables\n\nVyper has full support for environment variables. This enables 12 factor\napplications out of the box. There are four methods that exist to aid working\nwith ENV:\n\n * `automatic_env()`\n * `bind_env(string)`\n * `set_env_prefix(string)`\n * `set_env_replacer(string)`\n\n_When working with ENV variables, it’s important to recognize that Vyper\ntreats ENV variables as case sensitive._\n\nVyper provides a mechanism to try to ensure that ENV variables are unique. By\nusing `set_env_prefix()`, you can tell Vyper to use add a prefix while reading from\nthe environment variables. Both `bind_env()` and `automatic_env()` will use this\nprefix.\n\n`bind_env()` takes one or two parameters. The first parameter is the key name, the\nsecond is the name of the environment variable. The name of the environment\nvariable is case sensitive. If the ENV variable name is not provided, then\nVyper will automatically assume that the key name matches the ENV variable name,\nbut the ENV variable is IN ALL CAPS. When you explicitly provide the ENV\nvariable name, it **does not** automatically add the prefix.\n\nOne important thing to recognize when working with ENV variables is that the\nvalue will be read each time it is accessed. Vyper does not fix the value when\nthe `bind_env()` is called.\n\n`automatic_env()` is a powerful helper especially when combined with\n`set_env_prefix()`. When called, Vyper will check for an environment variable any\ntime a `v.get()` request is made. It will apply the following rules. It will\ncheck for a environment variable with a name matching the key uppercased and\nprefixed with the `env_prefix()` if set.\n\n`set_env_replacer()` allows you to use a `str` object to rewrite Env\nkeys to an extent. This is useful if you want to use `-` or something in your\n`get()` calls, but want your environmental variables to use `_` delimiters. An\nexample of using it can be found in `tests/test_vyper.py`.\n\n#### Env example\n\n```python\nv.set_env_prefix('spf')  # will be uppercased automatically\nv.bind_env('id')\n\nos.environ['SPF_ID'] = '13'  # typically done outside of the app\n\nid = v.get('id')  # 13\n```\n\n### Working with command line arguments\n\nVyper has the ability to bind to command line arguments.\nSpecifically, Vyper supports `argparse`.\nSee [doc](docs.python.org/3.7/library/argparse.html#argparse.ArgumentParser)\nfor more details.\n\nThe values are set when the binding method is called.\n\nAs it deals with command line arguments, the `bind_args()` method needs to be called passing\nan instance of argparse.ArgumentParser(). The method also sets defaults based on what you pass\nvia `add_argument()` `default` parameter.\n\nNote: If you don't specify a default, the values will be set to `None`.\n\n```python\np = argparse.ArgumentParser(description=\"Application settings\")\np.add_argument('--app-name', type=str, help='Application and process name')\np.add_argument('--env', type=str, choices=['dev', 'pre-prod', 'prod'], help='Application env')\np.add_argument('--port', type=int, default=5000, help='Application port')\np.add_argument('--password', type=str, help='Application password')\nv.bind_args(p)\n\n# \"your_app.py\", \"--app-name=cmd-app\", \"--env=prod\"\n\napp_name = v.get('app_name')  # 'cmd-app'\nenv = v.get('env')            # 'prod'\nport = v.get('port')          # 5000\npassword = v.get('password')  # `None`\n```\n\n## Getting Values From Vyper\n\nIn Vyper, there are a few ways to get a value depending on the value's type.\nThe following functions and methods exist:\n\n * `get(key)`\n * `get_bool(key) : bool`\n * `get_float(key) : float`\n * `get_int(key) : int`\n * `get_string(key) : str`\n * `is_set(key) : bool`\n\nOne important thing to recognize is that each get function will return a zero\nvalue if it’s not found. To check if a given key exists, the `is_set()` method\nhas been provided.\n\nExample:\n```python\nv.get_string('logfile')  # case-insensitive Setting \u0026 Getting\nif v.get_bool('verbose'):\n    print('verbose enabled')\n```\n### Accessing nested keys\n\nThe accessor methods also accept formatted paths to deeply nested keys. For\nexample, if the following JSON file is loaded:\n\n```json\n{\n    \"host\": {\n        \"address\": \"localhost\",\n        \"port\": 5799\n    },\n    \"datastore\": {\n        \"metric\": {\n            \"host\": \"127.0.0.1\",\n            \"port\": 3099\n        },\n        \"warehouse\": {\n            \"host\": \"198.0.0.1\",\n            \"port\": 2112\n        }\n    }\n}\n\n```\n\nVyper can access a nested field by passing a `.` delimited path of keys:\n\n```python\nv.get_string('datastore.metric.host')  # returns '127.0.0.1'\n```\n\nThis obeys the precedence rules established above; the search for the root key\n(in this example, `datastore`) will cascade through the remaining configuration\nregistries until found. The search for the sub-keys (`metric` and `host`),\nhowever, will not.\n\nFor example, if the `metric` key was not defined in the configuration loaded\nfrom file, but was defined in the defaults, Vyper would return the zero value.\n\nOn the other hand, if the primary key was not defined, Vyper would go through\nthe remaining registries looking for it.\n\nLastly, if there exists a key that matches the delimited key path, its value\nwill be returned instead. E.g.\n\n```json\n{\n    \"datastore.metric.host\": \"0.0.0.0\",\n    \"host\": {\n        \"address\": \"localhost\",\n        \"port\": 5799\n    },\n    \"datastore\": {\n        \"metric\": {\n            \"host\": \"127.0.0.1\",\n            \"port\": 3099\n        },\n        \"warehouse\": {\n            \"host\": \"198.0.0.1\",\n            \"port\": 2112\n        }\n    }\n}\n\nv.get_string('datastore.metric.host')  # returns '0.0.0.0'\n```\n\n## Vyper or Vypers?\n\nVyper comes ready to use out of the box. There is no configuration or\ninitialization needed to begin using Vyper. Since most applications will want\nto use a single central repository for their configuration, the vyper package\nprovides this. It is similar to a singleton.\n\nIn all of the examples above, they demonstrate using vyper in it's singleton\nstyle approach.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexferl%2Fvyper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexferl%2Fvyper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexferl%2Fvyper/lists"}