tinyconf package

Submodules

tinyconf.deserializers module

class tinyconf.deserializers.Deserializer

Bases: object

Base class for deserializers

class tinyconf.deserializers.IniDeserializer(*args, file: Optional[io.IOBase] = None, filename: Optional[str] = None, string: str = '', section: Optional[str] = None, **kwargs)

Bases: tinyconf.deserializers.Deserializer

Class representing a deserializer for an INI file.

Parameters:
  • *args – All unnamed arguments are passed to the underlying ConfigParser
  • filename (Optional[str]) – Load a file object by name as a config file
  • file (Optional[IOBase]) – Load a file object as a config file. Please note- the file will not be automatically closed.
  • string (Optional[str]) – Load a string as a config file
  • section (Optional[str]) – Which section should be loaded. Default is None. If None, will load sections based on tinyconf.section.Section objects within model.
  • **kwargs – All other named arguments are passed to the underlying ConfigParser
class tinyconf.deserializers.EnvDeserializer(*args, **kwargs)

Bases: tinyconf.deserializers.Deserializer

Deserializes from the operating system environment variables

tinyconf.fields module

class tinyconf.fields.Field(name: Optional[str] = None, *, strict: bool = False, default: Any = None, **kwargs)

Bases: object

Field type that deserializes directly into a str

Parameters:
  • name (Optional[str]) – The name of the field within the config. If not provided, uses the attribute name from within the Deserializer
  • strict (bool) – Whether the field is strictly required. Defauls to False Will cause deserialization to raise MissingFieldData if an item is missing
  • default – Specify a default value if the config doesn’t specify a value, or the value specified fails validation.
valid

If the field data is valid

Type:bool
name

The name of the field (if specified)

exception MissingFieldData

Bases: Exception

Exception for when a field marked as strict is set as None

value

Used during deserialization

validate()

Used during deserialization to determine if there are any issues with a field’s contents

class tinyconf.fields.IntegerField(name: Optional[str] = None, *, strict: bool = False, default: Any = None, **kwargs)

Bases: tinyconf.fields.Field

Field derivative that deserializes an integer

exception InvalidInteger

Bases: Exception

Exception raised when the field contents are not a valid integer

class tinyconf.fields.FloatField(name: Optional[str] = None, *, strict: bool = False, default: Any = None, **kwargs)

Bases: tinyconf.fields.Field

Field derivative that deserializes a floating point value

exception InvalidFloat

Bases: Exception

Exception raised when the field contents are not a valid float

class tinyconf.fields.BooleanField(name: Optional[str] = None, *, strict: bool = False, default: Any = None, **kwargs)

Bases: tinyconf.fields.Field

Field derivative that deserializes some sort of boolean value

Parameters:comparators (List[str]) – Specifies what the value should be compared with. Defaults to [‘1’, ‘y’, ‘yes’, ‘t’, ‘true’]
class tinyconf.fields.ListField(name: Optional[str] = None, *, strict: bool = False, default: Any = None, **kwargs)

Bases: tinyconf.fields.Field

Field derivative that deserializes a list value

Parameters:
  • delimiter (str) – Specifies the list delimiter. Defaults to ","
  • filter (Optional[FunctionType]) – Specifies a filtering function to be applied to the contents. Default lambda x: True
  • map (Optional[FunctionType]) – Specifies a function to map across every element. Default lambda x: x

tinyconf.section module

class tinyconf.section.Section(*args, name: Optional[str] = None)

Bases: object

Sections help to tell the models where config options can be found within INI files.

Parameters:
  • name (Optional[str]:) – The name of the section. Defaults to the attribute name.
  • * – All other attributes should be the fields belonging to the section.

Example:

class Config(IniDeserializer):
    token = IntegerField()
    username = Field()

    username_mysql = Field(name='username')
    passwd = Field()
    host = Field()

    client = Field()

    DEFAULT = Section(token, username)
    MYSQL = Section(username_mysql, passwd, host)
    PASSMARK = Section(client)

config = Config(string='''
[DEFAULT]
token = 1234
username = hello

[MYSQL]
username = jude
passwd = 12345
;host = j.net

[PASSMARK]
client = fred''')

Module contents