File Config Package¶
The module that exposes mostly all of the package’s functionality.
Although these methods are privatized under the _file_config
namespace they
can be accessed from the imported file_config
module…
import file_config
@file_config.config
class Config(object):
name = file_config.var(str)
Submodules¶
handlers
— Dumping / Loading handlers for different formats
schema_builder
— Config JSONSchema builder
utils
- Utilities used within the module
contrib
— Additional utilities that benefit the package
-
file_config._file_config.
config
(maybe_cls=None, these=None, title=None, description=None, schema_id=None, schema_draft=None, **kwargs)[source]¶ File config class decorator.
Usage is to simply decorate a class to make it a
config
class.>>> import file_config >>> @file_config.config( title="My Config Title", description="A description about my config" ) class MyConfig(object): pass
- Parameters
maybe_cls (class) – The class to inherit from, defaults to None, optional
these (dict) – A dictionary of str to
file_config.var
to use as attribstitle (str) – The title of the config, defaults to None, optional
description (str) – A description of the config, defaults to None, optional
schema_id (str) – The JSONSchema
$id
to use when building the schema, defaults to None, optionalschema_raft (str) – The JSONSchema
$schema
to use when building the schema, defaults to None, optional
- Returns
Config wrapped class
- Return type
class
-
file_config._file_config.
from_dict
(config_cls, dictionary, validate=False)[source]¶ Loads an instance of
config_cls
from a dictionary.
-
file_config._file_config.
make_config
(name, var_dict, title=None, description=None, schema_id=None, schema_draft=None, **kwargs)[source]¶ Creates a config instance from scratch.
Usage is virtually the same as
attr.make_class()
.>>> import file_config >>> MyConfig = file_config.make_config( "MyConfig", {"name": file_config.var(str)} )
- Parameters
name (str) – The name of the config
var_dict (dict) – The dictionary of config variable definitions
title (str) – The title of the config, defaults to None, optional
description (str) – The description of the config, defaults to None, optional
schema_id (str) – The JSONSchema
$id
to use when building the schema, defaults to None, optionalschema_raft (str) – The JSONSchema
$schema
to use when building the schema, defaults to None, optional
- Returns
A new config class
- Return type
class
-
file_config._file_config.
to_dict
(instance, dict_type=<class 'collections.OrderedDict'>)[source]¶ Dumps an instance to an dictionary mapping.
-
file_config._file_config.
validate
(instance)[source]¶ Validates a given
instance
.- Parameters
instance (object) – The instance to validate
- Raises
jsonschema.exceptions.ValidationError – On failed validation
-
file_config._file_config.
var
(type=None, default=None, name=None, title=None, description=None, required=True, examples=None, encoder=None, decoder=None, min=None, max=None, unique=None, contains=None, **kwargs)[source]¶ Creates a config variable.
Use this method to create the class variables of your
config
decorated class.>>> import file_config >>> @file_config.config class MyConfig(object): name = file_config.var(str)
- Parameters
type (type) – The expected type of the variable, defaults to None, optional
default – The default value of the var, defaults to None, optional
name (str) – The serialized name of the variable, defaults to None, optional
title (str) – The validation title of the variable, defaults to None, optional
description (str) – The validation description of the variable, defaults to None, optional
required (bool) – Flag to indicate if variable is required during validation, defaults to True, optional
examples (list) – A list of validation examples, if necessary, defaults to None, optional
encoder – The encoder to use for the var, defaults to None, optional
decoder – The decoder to use for the var, defaults to None, optional
min (int) – The minimum constraint of the variable, defaults to None, optional
max (int) – The maximum constraint of the variable, defaults to None, optional
unique (bool) – Flag to indicate if variable should be unique, may not apply to all variable types, defaults to None, optional
contains – Value that list varaible should contain in validation, may not apply to all variable types, defaults to None, optional
- Returns
A new config variable
- Return type