Usage¶
Creation¶
The easiest way of using schema_config
is to just load the schema from a string:
from schema_config import Configurator
schema = """
{
"type": "object",
"properties": {
"port": {
"type": "number"
}
},
required: ["port"]
}
"""
config_gen = Configurator.from_string(schema)
Or combined with resource_string()
:
from pkg_resources import resource_string
from schema_config import Configurator
schema = resource_string(__name__, "config.schema.json")
config_gen = Configurator.from_string(schema)
Or you can load the schema from a file:
from schema_config import Configurator
config_gen = Configurator.from_file("./config.schema.json")
The last option is to feed it a dict
directly:
from schema_config import Configurator
schema = {
"type": "object",
"properties": {
"port": {
"type": "number"
}
},
required: ["port"]
}
config_gen = Configurator(schema)
Plugins¶
Plugins can be added like this:
from schema_config import EnvPlugin
config_gen.add_plugin(EnvPlugin())
Config¶
Finally you can load the config like that:
config = config_gen.load_config()
Read about Plugins or the The Configuration class