p_config package

Submodules

p_config.converter module

class p_config.converter.CSV(cast_func=<class 'str'>, delimiter_pattern=', ')[source]

Bases: p_config.converter.Converter

Convert csv like string into list.

For example: you have ‘a.com,b.com,c.com’ as raw value and you can get [‘a.com’, ‘b.com’, ‘c.com’] via CSV.

>>> CSV(delimiter_pattern='[,|]').convert('a.com,b.com|c.com')
['a.com', 'b.com', 'c.com']
convert(value)[source]
class p_config.converter.Converter[source]

Bases: object

Convert raw value to expected format.

For example: when you get port value from os.environ, you may get a ‘80’, then you have to convert it into int.

convert(value)[source]

p_config.core module

core

class p_config.core.Config(config_file=None, **defaults)[source]

Bases: object

get(key, default=None)[source]
load(file_obj)[source]

Same as load_file.

load_dict(dct)[source]
load_env()[source]
load_file(value, format='yaml')[source]

Load config from a json or yaml file.

load_json_file(value)[source]

Load config from json file.

load_yaml_file(value)[source]

Load config from yaml file.

set_cast_func(key, cast_func)[source]
set_converter(key, convert_func)[source]
class p_config.core.ConfigMeta(name, bases, attrs)[source]

Bases: type

p_config.utils module

Package utility

class p_config.utils.Dict(**kwargs)[source]

Bases: collections.UserDict

Support access key via attribute style.

>>> d = Dict(bar='foo')
>>> d.bar == 'foo'
True
p_config.utils.open_file(value)[source]

Receive a file_obj or filename, return a file_obj.

Module contents

Top-level package for p_config.

class p_config.Config(config_file=None, **defaults)[source]

Bases: object

get(key, default=None)[source]
load(file_obj)[source]

Same as load_file.

load_dict(dct)[source]
load_env()[source]
load_file(value, format='yaml')[source]

Load config from a json or yaml file.

load_json_file(value)[source]

Load config from json file.

load_yaml_file(value)[source]

Load config from yaml file.

set_cast_func(key, cast_func)[source]
set_converter(key, convert_func)[source]
class p_config.Converter[source]

Bases: object

Convert raw value to expected format.

For example: when you get port value from os.environ, you may get a ‘80’, then you have to convert it into int.

convert(value)[source]