Cinco Config
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:
# 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)
# 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'])
Metadata
Release files for cincoconfig 0.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cincoconfig-0.9.0.tar.gz | 69.1 kB | Without provenance | Details for cincoconfig-0.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cincoconfig-0.9.0-py3-none-any.whl | Python 3 | none | any | Details for cincoconfig-0.9.0-py3-none-any.whl |
Total release size: 121.1 kB
Release files / cincoconfig-0.9.0.tar.gz
| Download URL | cincoconfig-0.9.0.tar.gz |
|---|---|
| Size | 69.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
747a2ba917e20df9496d7f46a8be1995dfdf11fe9419a8f37c6139eaa3d4484a
|
|
BLAKE2b-256 checksum How to use checksums |
e56b0ab42bde7abc69f0fe0948a43202e454e5d4a151554a16b4cf97785209ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.10.10 Windows/10
|
Release files / cincoconfig-0.9.0-py3-none-any.whl
| Download URL | cincoconfig-0.9.0-py3-none-any.whl |
|---|---|
| Size | 52.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ba200d23d74a9525405678f26e69a31457a9b7bff3c2331d3ebf747c44bf6e1f
|
|
BLAKE2b-256 checksum How to use checksums |
b7765832c10b626e5d1ade98fcc9f950dee909ad955c4208b7811ea61a18ea62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.10.10 Windows/10
|
Security for cincoconfig 0.9.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.