Skip to content

File

Attention: the source File has lower priority than environment variables so any founded environment vars will be used

Create

Sample config class of the reading file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class MyConfig(ABConfig):
    __file__ = 'path/to/file'

    auth = {
        'username': str,
        'password': str
    }

    address = str
    port = int

Formats

ABConfig will try to determine the format by the file extension.

Supported:

Json
1
2
3
4
5
6
7
8
{
    "auth": {
        "username": "user",
        "password": "pass"
    },
    "address": "0.0.0.0",
    "port": 8000
}
Yaml
1
2
3
4
5
auth:
  username: user
  password: pass
address: 0.0.0.0
port: 8000
Toml
1
2
3
4
5
6
address = "0.0.0.0"
port = 8000

[auth]
username = "user"
password = "pass"

Settings

  • __file__ - the path to the file;

  • __file_required__ - require file, otherwise an exception.

Default:

1
2
3
class MyConfig(ABConfig):
    __file__ = False
    __file_required__ = False

Also read