Skip to content

Commit

Permalink
Merge pull request #7 from configcat/sdkkey
Browse files Browse the repository at this point in the history
Sdkkey
  • Loading branch information
ConfigCat authored Apr 9, 2020
2 parents 781ada7 + 2754e0c commit e5c61cc
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 68 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ pip install configcat-client
import configcatclient
```

### 3. Go to <a href="https://app.configcat.com/connect" target="_blank">Connect your application</a> tab to get your *API Key*:
![API-KEY](https://raw.githubusercontent.com/ConfigCat/python-sdk/master/media/readme01.png "API-KEY")
### 3. Go to <a href="https://app.configcat.com/sdkkey" target="_blank">Connect your application</a> tab to get your *SDK Key*:
![SDK-KEY](https://raw.githubusercontent.com/ConfigCat/python-sdk/master/media/readme01.png "SDK-KEY")

### 4. Create a *ConfigCat* client instance:

```python
configcat_client = configcatclient.create_client('#YOUR-API-KEY#')
configcat_client = configcatclient.create_client('#YOUR-SDK-KEY#')
```
> We strongly recommend using the *ConfigCat Client* as a Singleton object in your application.
Expand Down Expand Up @@ -74,8 +74,8 @@ else:
## Polling Modes
The ConfigCat SDK supports 3 different polling mechanisms to acquire the setting values from ConfigCat. After latest setting values are downloaded, they are stored in the internal cache then all requests are served from there. Read more about Polling Modes and how to use them at [ConfigCat Docs](https://configcat.com/docs/sdk-reference/python/).

## Support
If you need help how to use this SDK feel free to to contact the ConfigCat Staff on https://configcat.com. We're happy to help.
## Need help?
https://configcat.com/support

## Contributing
Contributions are welcome.
Expand Down
36 changes: 18 additions & 18 deletions configcatclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
from .interfaces import ConfigCatClientException


def create_client(api_key):
def create_client(sdk_key):
"""
Create an instance of ConfigCatClient and setup Auto Poll mode with default options
:param api_key: ConfigCat ApiKey to access your configuration.
:param sdk_key: ConfigCat SDK Key to access your configuration.
"""
return create_client_with_auto_poll(api_key)
return create_client_with_auto_poll(sdk_key)


def create_client_with_auto_poll(api_key, poll_interval_seconds=60, max_init_wait_time_seconds=5,
def create_client_with_auto_poll(sdk_key, poll_interval_seconds=60, max_init_wait_time_seconds=5,
on_configuration_changed_callback=None, config_cache_class=None,
base_url=None, proxies=None, proxy_auth=None):
"""
Create an instance of ConfigCatClient and setup Auto Poll mode with custom options
:param api_key: ConfigCat ApiKey to access your configuration.
:param sdk_key: ConfigCat SDK Key to access your configuration.
:param poll_interval_seconds: The client's poll interval in seconds. Default: 60 seconds.
:param on_configuration_changed_callback: You can subscribe to configuration changes with this callback
:param max_init_wait_time_seconds: maximum waiting time for first configuration fetch in polling mode.
Expand All @@ -28,25 +28,25 @@ def create_client_with_auto_poll(api_key, poll_interval_seconds=60, max_init_wai
:param proxy_auth: Proxy authentication. e.g. HTTPProxyAuth('username', 'password')
"""

if api_key is None:
raise ConfigCatClientException('API Key is required.')
if sdk_key is None:
raise ConfigCatClientException('SDK Key is required.')

if poll_interval_seconds < 1:
poll_interval_seconds = 1

if max_init_wait_time_seconds < 0:
max_init_wait_time_seconds = 0

return ConfigCatClient(api_key, poll_interval_seconds, max_init_wait_time_seconds,
return ConfigCatClient(sdk_key, poll_interval_seconds, max_init_wait_time_seconds,
on_configuration_changed_callback, 0, config_cache_class, base_url, proxies, proxy_auth)


def create_client_with_lazy_load(api_key, cache_time_to_live_seconds=60, config_cache_class=None,
def create_client_with_lazy_load(sdk_key, cache_time_to_live_seconds=60, config_cache_class=None,
base_url=None, proxies=None, proxy_auth=None):
"""
Create an instance of ConfigCatClient and setup Lazy Load mode with custom options
:param api_key: ConfigCat ApiKey to access your configuration.
:param sdk_key: ConfigCat SDK Key to access your configuration.
:param cache_time_to_live_seconds: The cache TTL.
:param config_cache_class: If you want to use custom caching instead of the client's default InMemoryConfigCache,
You can provide an implementation of ConfigCache.
Expand All @@ -55,30 +55,30 @@ def create_client_with_lazy_load(api_key, cache_time_to_live_seconds=60, config_
:param proxy_auth: Proxy authentication. e.g. HTTPProxyAuth('username', 'password')
"""

if api_key is None:
raise ConfigCatClientException('API Key is required.')
if sdk_key is None:
raise ConfigCatClientException('SDK Key is required.')

if cache_time_to_live_seconds < 1:
cache_time_to_live_seconds = 1

return ConfigCatClient(api_key, 0, 0, None, cache_time_to_live_seconds, config_cache_class, base_url,
return ConfigCatClient(sdk_key, 0, 0, None, cache_time_to_live_seconds, config_cache_class, base_url,
proxies, proxy_auth)


def create_client_with_manual_poll(api_key, config_cache_class=None,
def create_client_with_manual_poll(sdk_key, config_cache_class=None,
base_url=None, proxies=None, proxy_auth=None):
"""
Create an instance of ConfigCatClient and setup Manual Poll mode with custom options
:param api_key: ConfigCat ApiKey to access your configuration.
:param sdk_key: ConfigCat SDK Key to access your configuration.
:param config_cache_class: If you want to use custom caching instead of the client's default InMemoryConfigCache,
You can provide an implementation of ConfigCache.
:param base_url: You can set a base_url if you want to use a proxy server between your application and ConfigCat
:param proxies: Proxy addresses. e.g. { "https": "your_proxy_ip:your_proxy_port" }
:param proxy_auth: Proxy authentication. e.g. HTTPProxyAuth('username', 'password')
"""

if api_key is None:
raise ConfigCatClientException('API Key is required.')
if sdk_key is None:
raise ConfigCatClientException('SDK Key is required.')

return ConfigCatClient(api_key, 0, 0, None, 0, config_cache_class, base_url, proxies, proxy_auth)
return ConfigCatClient(sdk_key, 0, 0, None, 0, config_cache_class, base_url, proxies, proxy_auth)
2 changes: 1 addition & 1 deletion configcatclient/autopollingcachepolicy.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def force_refresh(self):
if not self._initialized and old_configuration is not None:
self._initialized = True
except HTTPError as e:
log.error('Double-check your API KEY at https://app.configcat.com/apikey.'
log.error('Double-check your SDK Key at https://app.configcat.com/sdkkey.'
' Received unexpected response: %s' % str(e.response))
except:
log.exception(sys.exc_info()[0])
Expand Down
14 changes: 7 additions & 7 deletions configcatclient/configcatclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
class ConfigCatClient(object):

def __init__(self,
api_key,
sdk_key,
poll_interval_seconds=60,
max_init_wait_time_seconds=5,
on_configuration_changed_callback=None,
Expand All @@ -24,10 +24,10 @@ def __init__(self,
proxies=None,
proxy_auth=None):

if api_key is None:
raise ConfigCatClientException('API Key is required.')
if sdk_key is None:
raise ConfigCatClientException('SDK Key is required.')

self._api_key = api_key
self._sdk_key = sdk_key
self._rollout_evaluator = RolloutEvaluator()

if config_cache_class:
Expand All @@ -36,16 +36,16 @@ def __init__(self,
self._config_cache = InMemoryConfigCache()

if poll_interval_seconds > 0:
self._config_fetcher = ConfigFetcher(api_key, 'p', base_url, proxies, proxy_auth)
self._config_fetcher = ConfigFetcher(sdk_key, 'p', base_url, proxies, proxy_auth)
self._cache_policy = AutoPollingCachePolicy(self._config_fetcher, self._config_cache,
poll_interval_seconds, max_init_wait_time_seconds,
on_configuration_changed_callback)
elif cache_time_to_live_seconds > 0:
self._config_fetcher = ConfigFetcher(api_key, 'l', base_url, proxies, proxy_auth)
self._config_fetcher = ConfigFetcher(sdk_key, 'l', base_url, proxies, proxy_auth)
self._cache_policy = LazyLoadingCachePolicy(self._config_fetcher, self._config_cache,
cache_time_to_live_seconds)
else:
self._config_fetcher = ConfigFetcher(api_key, 'm', base_url, proxies, proxy_auth)
self._config_fetcher = ConfigFetcher(sdk_key, 'm', base_url, proxies, proxy_auth)
self._cache_policy = ManualPollingCachePolicy(self._config_fetcher, self._config_cache)

def get_value(self, key, default_value, user=None):
Expand Down
6 changes: 3 additions & 3 deletions configcatclient/configfetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def is_not_modified(self):

class ConfigFetcher(object):

def __init__(self, api_key, mode, base_url=None, proxies=None, proxy_auth=None):
self._api_key = api_key
def __init__(self, sdk_key, mode, base_url=None, proxies=None, proxy_auth=None):
self._sdk_key = sdk_key
self._proxies = proxies
self._proxy_auth = proxy_auth
self._etag = ''
Expand All @@ -56,7 +56,7 @@ def get_configuration_json(self):
"""
:return: Returns the FetchResponse object contains configuration json Dictionary
"""
uri = self._base_url + '/' + BASE_PATH + self._api_key + BASE_EXTENSION
uri = self._base_url + '/' + BASE_PATH + self._sdk_key + BASE_EXTENSION
headers = self._headers
if self._etag:
headers['If-None-Match'] = self._etag
Expand Down
2 changes: 1 addition & 1 deletion configcatclient/lazyloadingcachepolicy.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def force_refresh(self):
self._lock.release_write()

except HTTPError as e:
log.error('Double-check your API KEY at https://app.configcat.com/apikey.'
log.error('Double-check your SDK Key at https://app.configcat.com/sdkkey.'
' Received unexpected response: %s' % str(e.response))
except:
log.exception(sys.exc_info()[0])
Expand Down
2 changes: 1 addition & 1 deletion configcatclient/manualpollingcachepolicy.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def force_refresh(self):
self._lock.release_write()

except HTTPError as e:
log.error('Double-check your API KEY at https://app.configcat.com/apikey.'
log.error('Double-check your SDK Key at https://app.configcat.com/sdkkey.'
' Received unexpected response: [%s]' % str(e.response))
except:
log.exception(sys.exc_info()[0])
Expand Down
2 changes: 1 addition & 1 deletion configcatclienttests/test_configcatclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


class ConfigCatClientTests(unittest.TestCase):
def test_without_api_key(self):
def test_without_sdk_key(self):
try:
ConfigCatClient(None)
self.fail('Expected ConfigCatClientException')
Expand Down
6 changes: 3 additions & 3 deletions configcatclienttests/test_configfetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_simple_fetch_success(self):
response_mock.json.return_value = test_json
response_mock.status_code = 200
response_mock.headers = {}
fetcher = ConfigFetcher(api_key='', mode='m')
fetcher = ConfigFetcher(sdk_key='', mode='m')
fetch_response = fetcher.get_configuration_json()
self.assertTrue(fetch_response.is_fetched())
self.assertEqual(test_json, fetch_response.json())
Expand All @@ -33,7 +33,7 @@ def test_fetch_not_modified_etag(self):
with mock.patch.object(requests, 'get') as request_get:
etag = 'test'
test_json = {"test": "json"}
fetcher = ConfigFetcher(api_key='', mode='m')
fetcher = ConfigFetcher(sdk_key='', mode='m')

response_mock = Mock()
response_mock.json.return_value = test_json
Expand All @@ -59,7 +59,7 @@ def test_fetch_not_modified_etag(self):
self.assertEqual(request_headers.get('If-None-Match'), etag)

def test_server_side_etag(self):
fetcher = ConfigFetcher(api_key='PKDVCLf-Hq-h-kCzMp-L7Q/HhOWfwVtZ0mb30i9wi17GQ',
fetcher = ConfigFetcher(sdk_key='PKDVCLf-Hq-h-kCzMp-L7Q/HhOWfwVtZ0mb30i9wi17GQ',
mode='m', base_url='https://cdn-li-fra-1.configcat.com')
fetch_response = fetcher.get_configuration_json()
self.assertTrue(fetch_response.is_fetched())
Expand Down
Loading

0 comments on commit e5c61cc

Please sign in to comment.