cincoconfig


Namecincoconfig JSON
Version 0.9.0 PyPI version JSON
download
home_pagehttps://github.com/ameily/cincoconfig
SummaryUniversal configuration file parser
upload_time2023-04-23 18:53:35
maintainer
docs_urlNone
authorAdam Meily
requires_python>=3.7,<4.0
licenseISC
keywords config configuration
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Cinco Config

[![Build Status](https://travis-ci.com/ameily/cincoconfig.svg?branch=master)](https://travis-ci.com/github/ameily/cincoconfig)
[![Coverage Status](https://coveralls.io/repos/github/ameily/cincoconfig/badge.svg?branch=master)](https://coveralls.io/github/ameily/cincoconfig?branch=master)
[![Docs Status](https://readthedocs.org/projects/cincoconfig/badge/)](https://cincoconfig.readthedocs.io/en/latest/)

Next generation universal configuration file parser. The config file structure is defined
programmatically and expressively, no need to create classes and inheritance.

Let's get right to it:

```python
# app_config.py
import getpass
from cincoconfig import *

# first, define the configuration's schema -- the fields available that
# customize the application's or library's behavior
schema = Schema()
schema.mode = ApplicationModeField(default='production')

# nested configurations are built on the fly
# http is now a subconfig
schema.http.port = PortField(default=8080, required=True)

# each field has its own validation rules that are run anytime the config
# value is loaded from disk or modified by the user.
# here, this field only accepts IPv4 network addresses and the user is
# required to define this field in the configuration file.
schema.http.address = IPv4AddressField(default='127.0.0.1', required=True)

schema.http.ssl.enabled = BoolField(default=False)
schema.http.ssl.cafile = FilenameField()
schema.http.ssl.keyfile = FilenameField()
schema.http.ssl.certfile = FilenameField()

schema.db.host = HostnameField(allow_ipv4=True, required=True, default='localhost')
schema.db.port = PortField(default=27017, required=True)
schema.db.name = StringField(default='my_app', required=True)
schema.db.user = StringField(default='admin')

# some configuration values are sensitive, such as credentials, so
# cincoconfig provides config value encryption when the value is
# saved to disk via the SecureField
schema.db.password = SecureField()

# get a field programmatically
print(schema['db.host']) # >>> schema.db.host

# once a schema is defined, build the actual configuration object
# that can load config files from disk and interact with the values
config = schema()

# print the http port
print(config.http.port) # >>> 8080

# print the http port programmatically
print(config['http.port']) # >>> 8080

config.db.password = getpass.getpass("Enter Password: ") # < 'password'

# set a config value manually
if config.mode == 'production':
    config.db.name = config.db.name + '_production'

print(config.dumps(format='json', pretty=True).decode())
# {
#   "mode": "production",
#   "http": {
#     "port": 8080,
#     "address": "127.0.0.1"
#     "ssl": {
#       "enabled": false
#     }
#   },
#   "db": {
#     "host": "localhost",
#     "port": 27017,
#     "name": "my_app_production",
#     "user": "admin",
#     "password": {
#       "method": "best",
#       "ciphertext": "<ciphertext>"
#     }
#   }
# }
```

### Override Configuration with Command Line Arguments (argparse)

```python
# config.py
schema = Schema()
schema.mode = ApplicationModeField(default='production', modes=['production', 'debug'])
schema.http.port = PortField(default=8080, required=True)
schema.http.address = IPv4AddressField(default='127.0.0.1', required=True)

config = schema()

# __main__.py
import argparse
from .config import config, schema

parser = schema.generate_argparse_parser()
#
# The generate_argparse_parser() method auto generates the parser using --long-opts. For this
# configuration, the returned parser is equivalent to:
#
# parser = argparse.ArgumentParser()
#
# parser.add_argument('--http-address', action='store', dest='http.address')
# parser.add_argument('--http-port', action='store', dest='http.port')
# parser.add_argument('--mode', action='store', dest='mode')
#

# new args can be added to the parser
parser.add_argument('-c', '--config', action='store')
args = parser.parse_args()
if args.config:
    config.load(args.config, format='json')

# update the configuration with arguments specified via the command line
config.cmdline_args_override(args, ignore=['config'])
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ameily/cincoconfig",
    "name": "cincoconfig",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7,<4.0",
    "maintainer_email": "",
    "keywords": "config,configuration",
    "author": "Adam Meily",
    "author_email": "meily.adam@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e5/6b/0ab42bde7abc69f0fe0948a43202e454e5d4a151554a16b4cf97785209ac/cincoconfig-0.9.0.tar.gz",
    "platform": null,
    "description": "# Cinco Config\n\n[![Build Status](https://travis-ci.com/ameily/cincoconfig.svg?branch=master)](https://travis-ci.com/github/ameily/cincoconfig)\n[![Coverage Status](https://coveralls.io/repos/github/ameily/cincoconfig/badge.svg?branch=master)](https://coveralls.io/github/ameily/cincoconfig?branch=master)\n[![Docs Status](https://readthedocs.org/projects/cincoconfig/badge/)](https://cincoconfig.readthedocs.io/en/latest/)\n\nNext generation universal configuration file parser. The config file structure is defined\nprogrammatically and expressively, no need to create classes and inheritance.\n\nLet's get right to it:\n\n```python\n# app_config.py\nimport getpass\nfrom cincoconfig import *\n\n# first, define the configuration's schema -- the fields available that\n# customize the application's or library's behavior\nschema = Schema()\nschema.mode = ApplicationModeField(default='production')\n\n# nested configurations are built on the fly\n# http is now a subconfig\nschema.http.port = PortField(default=8080, required=True)\n\n# each field has its own validation rules that are run anytime the config\n# value is loaded from disk or modified by the user.\n# here, this field only accepts IPv4 network addresses and the user is\n# required to define this field in the configuration file.\nschema.http.address = IPv4AddressField(default='127.0.0.1', required=True)\n\nschema.http.ssl.enabled = BoolField(default=False)\nschema.http.ssl.cafile = FilenameField()\nschema.http.ssl.keyfile = FilenameField()\nschema.http.ssl.certfile = FilenameField()\n\nschema.db.host = HostnameField(allow_ipv4=True, required=True, default='localhost')\nschema.db.port = PortField(default=27017, required=True)\nschema.db.name = StringField(default='my_app', required=True)\nschema.db.user = StringField(default='admin')\n\n# some configuration values are sensitive, such as credentials, so\n# cincoconfig provides config value encryption when the value is\n# saved to disk via the SecureField\nschema.db.password = SecureField()\n\n# get a field programmatically\nprint(schema['db.host']) # >>> schema.db.host\n\n# once a schema is defined, build the actual configuration object\n# that can load config files from disk and interact with the values\nconfig = schema()\n\n# print the http port\nprint(config.http.port) # >>> 8080\n\n# print the http port programmatically\nprint(config['http.port']) # >>> 8080\n\nconfig.db.password = getpass.getpass(\"Enter Password: \") # < 'password'\n\n# set a config value manually\nif config.mode == 'production':\n    config.db.name = config.db.name + '_production'\n\nprint(config.dumps(format='json', pretty=True).decode())\n# {\n#   \"mode\": \"production\",\n#   \"http\": {\n#     \"port\": 8080,\n#     \"address\": \"127.0.0.1\"\n#     \"ssl\": {\n#       \"enabled\": false\n#     }\n#   },\n#   \"db\": {\n#     \"host\": \"localhost\",\n#     \"port\": 27017,\n#     \"name\": \"my_app_production\",\n#     \"user\": \"admin\",\n#     \"password\": {\n#       \"method\": \"best\",\n#       \"ciphertext\": \"<ciphertext>\"\n#     }\n#   }\n# }\n```\n\n### Override Configuration with Command Line Arguments (argparse)\n\n```python\n# config.py\nschema = Schema()\nschema.mode = ApplicationModeField(default='production', modes=['production', 'debug'])\nschema.http.port = PortField(default=8080, required=True)\nschema.http.address = IPv4AddressField(default='127.0.0.1', required=True)\n\nconfig = schema()\n\n# __main__.py\nimport argparse\nfrom .config import config, schema\n\nparser = schema.generate_argparse_parser()\n#\n# The generate_argparse_parser() method auto generates the parser using --long-opts. For this\n# configuration, the returned parser is equivalent to:\n#\n# parser = argparse.ArgumentParser()\n#\n# parser.add_argument('--http-address', action='store', dest='http.address')\n# parser.add_argument('--http-port', action='store', dest='http.port')\n# parser.add_argument('--mode', action='store', dest='mode')\n#\n\n# new args can be added to the parser\nparser.add_argument('-c', '--config', action='store')\nargs = parser.parse_args()\nif args.config:\n    config.load(args.config, format='json')\n\n# update the configuration with arguments specified via the command line\nconfig.cmdline_args_override(args, ignore=['config'])\n```\n",
    "bugtrack_url": null,
    "license": "ISC",
    "summary": "Universal configuration file parser",
    "version": "0.9.0",
    "split_keywords": [
        "config",
        "configuration"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b7765832c10b626e5d1ade98fcc9f950dee909ad955c4208b7811ea61a18ea62",
                "md5": "d992afbe867abae691203a16a38c24ca",
                "sha256": "ba200d23d74a9525405678f26e69a31457a9b7bff3c2331d3ebf747c44bf6e1f"
            },
            "downloads": -1,
            "filename": "cincoconfig-0.9.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d992afbe867abae691203a16a38c24ca",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7,<4.0",
            "size": 51994,
            "upload_time": "2023-04-23T18:53:33",
            "upload_time_iso_8601": "2023-04-23T18:53:33.454590Z",
            "url": "https://files.pythonhosted.org/packages/b7/76/5832c10b626e5d1ade98fcc9f950dee909ad955c4208b7811ea61a18ea62/cincoconfig-0.9.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e56b0ab42bde7abc69f0fe0948a43202e454e5d4a151554a16b4cf97785209ac",
                "md5": "43dcb22feb09f4d6b727cbc945a9859d",
                "sha256": "747a2ba917e20df9496d7f46a8be1995dfdf11fe9419a8f37c6139eaa3d4484a"
            },
            "downloads": -1,
            "filename": "cincoconfig-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "43dcb22feb09f4d6b727cbc945a9859d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7,<4.0",
            "size": 69114,
            "upload_time": "2023-04-23T18:53:35",
            "upload_time_iso_8601": "2023-04-23T18:53:35.293523Z",
            "url": "https://files.pythonhosted.org/packages/e5/6b/0ab42bde7abc69f0fe0948a43202e454e5d4a151554a16b4cf97785209ac/cincoconfig-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-23 18:53:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "ameily",
    "github_project": "cincoconfig",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cincoconfig"
}
        
Elapsed time: 0.68743s