55from .pollingmode import PollingMode
66
77
8+ def get (sdk_key , options = None ):
9+ """
10+ Creates a new or gets an already existing `ConfigCatClient` for the given `sdk_key`.
11+
12+ :param sdk_key: ConfigCat SDK Key to access your configuration.
13+ :param options: Configuration `ConfigCatOptions` for `ConfigCatClient`.
14+ :return: the `ConfigCatClient` instance.
15+ """
16+ return ConfigCatClient .get (sdk_key = sdk_key , options = options )
17+
18+
19+ def close_all ():
20+ """
21+ Closes all ConfigCatClient instances.
22+ """
23+ ConfigCatClient .close_all ()
24+
25+
826def create_client (sdk_key , data_governance = DataGovernance .Global ):
927 """
1028 Create an instance of ConfigCatClient and setup Auto Poll mode with default options
@@ -19,130 +37,131 @@ def create_client(sdk_key, data_governance=DataGovernance.Global):
1937
2038
2139def create_client_with_auto_poll (sdk_key , poll_interval_seconds = 60 , max_init_wait_time_seconds = 5 ,
22- on_configuration_changed_callback = None , config_cache_class = None ,
40+ on_configuration_changed_callback = None ,
41+ config_cache = None ,
2342 base_url = None , proxies = None , proxy_auth = None ,
2443 connect_timeout_seconds = 10 , read_timeout_seconds = 30 ,
2544 flag_overrides = None ,
26- data_governance = DataGovernance .Global ,
27- default_user = None ):
45+ data_governance = DataGovernance .Global ):
2846 """
2947 Create an instance of ConfigCatClient and setup Auto Poll mode with custom options
3048
3149 :param sdk_key: ConfigCat SDK Key to access your configuration.
3250 :param poll_interval_seconds: The client's poll interval in seconds. Default: 60 seconds.
33- :param on_configuration_changed_callback: You can subscribe to configuration changes with this callback
3451 :param max_init_wait_time_seconds: maximum waiting time for first configuration fetch.
35- :param config_cache_class: If you want to use custom caching instead of the client's default InMemoryConfigCache,
52+ :param on_configuration_changed_callback: You can subscribe to configuration changes with this callback
53+ :param config_cache: If you want to use custom caching instead of the client's default,
3654 You can provide an implementation of ConfigCache.
3755 :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
3856 :param proxies: Proxy addresses. e.g. { 'https': 'your_proxy_ip:your_proxy_port' }
3957 :param proxy_auth: Proxy authentication. e.g. HTTPProxyAuth('username', 'password')
4058 :param connect_timeout_seconds: The number of seconds to wait for the server to make the initial connection
4159 (i.e. completing the TCP connection handshake). Default: 10 seconds.
4260 :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
43- :param flag_overrides: An OverrideDataSource implementation used to override feature flags & settings.
61+ :param flag_overrides: An FlagOverrides implementation used to override feature flags & settings.
4462 :param data_governance:
4563 Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard: \n
4664 https://app.configcat.com/organization/data-governance \n
4765 (Only Organization Admins have access)
48- :param default_user: The default user, used as fallback when there's no user parameter is passed to the
49- ConfigCatClient.get_value, ConfigCatClient.get_all_values, etc. methods.
5066 """
5167
5268 options = ConfigCatOptions (
5369 base_url = base_url ,
54- polling_mode = PollingMode .auto_poll (auto_poll_interval_seconds = poll_interval_seconds ,
55- max_init_wait_time_seconds = max_init_wait_time_seconds ,
56- on_config_changed = on_configuration_changed_callback ),
57- config_cache = config_cache_class ,
70+ polling_mode = PollingMode .auto_poll (poll_interval_seconds = poll_interval_seconds ,
71+ max_init_wait_time_seconds = max_init_wait_time_seconds ),
72+ config_cache = config_cache ,
5873 proxies = proxies ,
5974 proxy_auth = proxy_auth ,
6075 connect_timeout_seconds = connect_timeout_seconds ,
6176 read_timeout_seconds = read_timeout_seconds ,
6277 flag_overrides = flag_overrides ,
63- data_governance = data_governance ,
64- default_user = default_user )
65- return ConfigCatClient .get (sdk_key = sdk_key , options = options )
78+ data_governance = data_governance )
79+ client = ConfigCatClient .get (sdk_key = sdk_key , options = options )
6680
81+ if on_configuration_changed_callback is not None :
82+ client .get_hooks ().add_on_config_changed (on_configuration_changed_callback )
6783
68- def create_client_with_lazy_load (sdk_key , cache_time_to_live_seconds = 60 , config_cache_class = None ,
84+ client .log .warning ('create_client_with_auto_poll is deprecated. '
85+ 'Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead' )
86+ return client
87+
88+
89+ def create_client_with_lazy_load (sdk_key , cache_time_to_live_seconds = 60 , config_cache = None ,
6990 base_url = None , proxies = None , proxy_auth = None ,
7091 connect_timeout_seconds = 10 , read_timeout_seconds = 30 ,
7192 flag_overrides = None ,
72- data_governance = DataGovernance .Global ,
73- default_user = None ):
93+ data_governance = DataGovernance .Global ):
7494 """
7595 Create an instance of ConfigCatClient and setup Lazy Load mode with custom options
7696
7797 :param sdk_key: ConfigCat SDK Key to access your configuration.
7898 :param cache_time_to_live_seconds: The cache TTL.
79- :param config_cache_class : If you want to use custom caching instead of the client's default InMemoryConfigCache ,
99+ :param config_cache : If you want to use custom caching instead of the client's default,
80100 You can provide an implementation of ConfigCache.
81101 :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
82102 :param proxies: Proxy addresses. e.g. { "https": "your_proxy_ip:your_proxy_port" }
83103 :param proxy_auth: Proxy authentication. e.g. HTTPProxyAuth('username', 'password')
84104 :param connect_timeout_seconds: The number of seconds to wait for the server to make the initial connection
85105 (i.e. completing the TCP connection handshake). Default: 10 seconds.
86106 :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
87- :param flag_overrides: An OverrideDataSource implementation used to override feature flags & settings.
107+ :param flag_overrides: An FlagOverrides implementation used to override feature flags & settings.
88108 :param data_governance:
89109 Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard: \n
90110 https://app.configcat.com/organization/data-governance \n
91111 (Only Organization Admins have access)
92- :param default_user: The default user, used as fallback when there's no user parameter is passed to the
93- ConfigCatClient.get_value, ConfigCatClient.get_all_values, etc. methods.
94112 """
95113
96114 options = ConfigCatOptions (
97115 base_url = base_url ,
98116 polling_mode = PollingMode .lazy_load (cache_refresh_interval_seconds = cache_time_to_live_seconds ),
99- config_cache = config_cache_class ,
117+ config_cache = config_cache ,
100118 proxies = proxies ,
101119 proxy_auth = proxy_auth ,
102120 connect_timeout_seconds = connect_timeout_seconds ,
103121 read_timeout_seconds = read_timeout_seconds ,
104122 flag_overrides = flag_overrides ,
105- data_governance = data_governance ,
106- default_user = default_user )
107- return ConfigCatClient .get (sdk_key = sdk_key , options = options )
123+ data_governance = data_governance )
124+ client = ConfigCatClient .get (sdk_key = sdk_key , options = options )
125+ client .log .warning ('create_client_with_lazy_load is deprecated. '
126+ 'Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead' )
127+ return client
108128
109129
110- def create_client_with_manual_poll (sdk_key , config_cache_class = None ,
130+ def create_client_with_manual_poll (sdk_key , config_cache = None ,
111131 base_url = None , proxies = None , proxy_auth = None ,
112132 connect_timeout_seconds = 10 , read_timeout_seconds = 30 ,
113133 flag_overrides = None ,
114- data_governance = DataGovernance .Global ,
115- default_user = None ):
134+ data_governance = DataGovernance .Global ):
116135 """
117136 Create an instance of ConfigCatClient and setup Manual Poll mode with custom options
118137
119138 :param sdk_key: ConfigCat SDK Key to access your configuration.
120- :param config_cache_class : If you want to use custom caching instead of the client's default InMemoryConfigCache ,
139+ :param config_cache : If you want to use custom caching instead of the client's default,
121140 You can provide an implementation of ConfigCache.
122141 :param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
123142 :param proxies: Proxy addresses. e.g. { "https": "your_proxy_ip:your_proxy_port" }
124143 :param proxy_auth: Proxy authentication. e.g. HTTPProxyAuth('username', 'password')
125144 :param connect_timeout_seconds: The number of seconds to wait for the server to make the initial connection
126145 (i.e. completing the TCP connection handshake). Default: 10 seconds.
127146 :param read_timeout_seconds: The number of seconds to wait for the server to respond before giving up. Default: 30 seconds.
128- :param flag_overrides: An OverrideDataSource implementation used to override feature flags & settings.
147+ :param flag_overrides: An FlagOverrides implementation used to override feature flags & settings.
129148 :param data_governance:
130149 Default: Global. Set this parameter to be in sync with the Data Governance preference on the Dashboard: \n
131150 https://app.configcat.com/organization/data-governance \n
132151 (Only Organization Admins have access)
133- :param default_user: The default user, used as fallback when there's no user parameter is passed to the
134- ConfigCatClient.get_value, ConfigCatClient.get_all_values, etc. methods.
135152 """
136153
137154 options = ConfigCatOptions (
138155 base_url = base_url ,
139156 polling_mode = PollingMode .manual_poll (),
140- config_cache = config_cache_class ,
157+ config_cache = config_cache ,
141158 proxies = proxies ,
142159 proxy_auth = proxy_auth ,
143160 connect_timeout_seconds = connect_timeout_seconds ,
144161 read_timeout_seconds = read_timeout_seconds ,
145162 flag_overrides = flag_overrides ,
146- data_governance = data_governance ,
147- default_user = default_user )
148- return ConfigCatClient .get (sdk_key = sdk_key , options = options )
163+ data_governance = data_governance )
164+ client = ConfigCatClient .get (sdk_key = sdk_key , options = options )
165+ client .log .warning ('create_client_with_manual_poll is deprecated. '
166+ 'Create the ConfigCat Client as a Singleton object with `configcatclient.get()` instead' )
167+ return client
0 commit comments