ConfigCat SDK for Python provides easy integration for your application to ConfigCat. It's a feature flag and configuration management service that lets you separate releases from deployments, enabling remote control over features. The library is actively maintained, with the current version being 10.0.0, and receives regular updates including new features and compatibility improvements.
pip install configcat-clientVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the ConfigCat client, retrieve a feature flag's value, and safely close the client. It also shows how to get a value for a specific user using a `User` object. Remember to replace `YOUR_SDK_KEY_HERE` with your actual ConfigCat SDK Key, ideally loaded from an environment variable.
Upgrade to Python 3.8 or newer. Ensure your CI/CD pipelines and deployment environments use a supported Python version.
Replace calls to removed `create_client` functions with `client = configcatclient.get(sdk_key)`. Update `client.stop()` calls to `client.close()`.
If using local flag overrides, convert your config JSON files from v5 to v6 using the ConfigCat CLI tool. Update any code expecting `User` custom attributes to be strictly strings.
Initialize the client once at application startup using `client = configcatclient.get(SDK_KEY)` and reuse this instance across your application rather than creating new ones.
Ensure `client.close()` is called for individual clients, or `configcatclient.close_all()` is called to shut down all clients, typically in a `finally` block or application shutdown hook.
Validate your SDK key format (it's a 22-character string consisting of Latin letters, numbers, and hyphens) before passing it to `configcatclient.get()`, or handle `ConfigCatClientException` gracefully.
Install the package using pip: `pip install configcat-client`
Ensure your SDK Key is correct and that the `data_governance` option (e.g., `PollingMode.auto_poll(data_governance=DataGovernance.EU_ONLY)`) matches your project's settings in the ConfigCat Dashboard. For example:
```python
from configcatclient import ConfigCatOptions, PollingMode, DataGovernance
import configcatclient
# Correct SDK Key and Data Governance (example)
client = configcatclient.get(
'YOUR_SDK_KEY',
ConfigCatOptions(
polling_mode=PollingMode.auto_poll(),
data_governance=DataGovernance.GLOBAL # Or DataGovernance.EU_ONLY
)
)
# Remember to close the client when your application exits
# configcatclient.close_all()
```Check your network connectivity, ensure that `cdn.configcat.com`, `cdn-eu.configcat.com`, and `cdn-global.configcat.com` are whitelisted in your firewall, and verify the ConfigCat Service Status Monitor for any outages. You can also configure a longer `connect_timeout_seconds` in `ConfigCatOptions` if you suspect transient network delays:
```python
from configcatclient import ConfigCatOptions, PollingMode
import configcatclient
client = configcatclient.get(
'YOUR_SDK_KEY',
ConfigCatOptions(
polling_mode=PollingMode.auto_poll(),
connect_timeout_seconds=30 # Increase timeout (default is 10)
)
)
```Pass a `User` object with relevant attributes to the evaluation methods (`get_value`, `get_value_details`, etc.) to enable proper targeting. For example:
```python
from configcatclient import ConfigCatClient, User
client = ConfigCatClient.get('YOUR_SDK_KEY')
user = User(
identifier='user_id_123',
email='test@example.com',
country='US'
)
is_feature_enabled = client.get_value('your_setting_key', False, user)
# Don't forget to close the client when your application exits
# client.close()
```