Skip to content

Singleton

Create singleton instance with default values

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
from config import create_config_client


c1 = create_config_client(app_name='foo', label='main')
c2 = create_config_client(
    app_name='foo',
    label='main',
    profile='dev,docker,cloud'
)

print(id(c1))
print(id(c2))

Create singleton instance with custom values

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
from config import create_config_client


c1 = create_config_client(
    app_name='foo',
    label='main',
    profile="development,docker,cloud"
)
c2 = create_config_client(
    app_name='myD-app',
    label='main',
    profile="development"
)

print(id(c1))
print(id(c2))

Singleton instance with decorator

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from config import config_client
from config.core import singleton


@singleton
@config_client(app_name="foo", label='main')
def my_test(config=None):
    print(config)
    return config

c1 = my_test()
c2 = my_test()
print(id(c1))
print(id(c2))