wingify-fme-python-sdk 1.70.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. tests/data/__init__.py +13 -0
  2. tests/data/dummy_test_data_reader.py +63 -0
  3. tests/data/user_storage.py +48 -0
  4. tests/e2e/__init__.py +13 -0
  5. tests/e2e/custom_bucketing_test.py +514 -0
  6. tests/e2e/force_users_test.py +368 -0
  7. tests/e2e/get_flag_test.py +195 -0
  8. tests/unit/__init__.py +13 -0
  9. tests/unit/packages/__init__.py +13 -0
  10. tests/unit/packages/decision_maker/__init__.py +13 -0
  11. tests/unit/packages/decision_maker/decision_maker_test.py +83 -0
  12. tests/unit/packages/segmentation_evaluator/__init__.py +13 -0
  13. tests/unit/packages/segmentation_evaluator/segmentation_evaluator_test.py +284 -0
  14. tests/unit/packages/segmentation_evaluator/segmentation_manager_test.py +215 -0
  15. tests/unit/packages/segmentation_evaluator/web_testing_segment_test.py +216 -0
  16. tests/unit/services/__init__.py +0 -0
  17. tests/unit/services/hooks_manager_test.py +80 -0
  18. tests/unit/services/internal_events_sampling_service_test.py +160 -0
  19. tests/unit/settings/__init__.py +13 -0
  20. tests/unit/settings/settings_schema_validation_test.py +67 -0
  21. tests/unit/utils/__init__.py +0 -0
  22. tests/unit/utils/campaign_util_test.py +248 -0
  23. tests/unit/utils/decision_util_force_users_test.py +790 -0
  24. tests/unit/utils/log_message_test.py +65 -0
  25. tests/unit/vwo_wingify_test.py +175 -0
  26. tests/unit/wingify_client_validation_test.py +72 -0
  27. vwo/__init__.py +35 -0
  28. vwo/models/__init__.py +13 -0
  29. vwo/models/batch_event_data.py +19 -0
  30. vwo/models/user/__init__.py +13 -0
  31. vwo/models/user/context_vwo_model.py +21 -0
  32. vwo/models/user/get_flag.py +19 -0
  33. vwo/models/vwo_options_model.py +21 -0
  34. vwo/packages/__init__.py +13 -0
  35. vwo/packages/logger/__init__.py +13 -0
  36. vwo/packages/logger/enums/__init__.py +13 -0
  37. vwo/packages/logger/enums/log_level_enum.py +19 -0
  38. vwo/packages/storage/__init__.py +13 -0
  39. vwo/packages/storage/connector.py +19 -0
  40. vwo/vwo.py +58 -0
  41. vwo/vwo_builder.py +21 -0
  42. vwo/vwo_client.py +22 -0
  43. wingify/__init__.py +36 -0
  44. wingify/api/__init__.py +13 -0
  45. wingify/api/get_flag_api.py +727 -0
  46. wingify/api/set_attribute_api.py +60 -0
  47. wingify/api/track_api.py +99 -0
  48. wingify/constants/Constants.py +94 -0
  49. wingify/constants/__init__.py +13 -0
  50. wingify/constants/sampled_debug_error_template_keys.py +34 -0
  51. wingify/decorators/__init__.py +13 -0
  52. wingify/decorators/storage_decorator.py +92 -0
  53. wingify/enums/__init__.py +13 -0
  54. wingify/enums/api_enum.py +26 -0
  55. wingify/enums/campaign_type_enum.py +22 -0
  56. wingify/enums/debug_category_enum.py +24 -0
  57. wingify/enums/event_enum.py +26 -0
  58. wingify/enums/headers_enum.py +21 -0
  59. wingify/enums/hooks_enum.py +24 -0
  60. wingify/enums/status_enum.py +21 -0
  61. wingify/enums/storage_enum.py +25 -0
  62. wingify/enums/url_enum.py +29 -0
  63. wingify/models/Alias.py +60 -0
  64. wingify/models/AliasSetResponse.py +43 -0
  65. wingify/models/__init__.py +13 -0
  66. wingify/models/batch_event_data.py +68 -0
  67. wingify/models/campaign/__init__.py +13 -0
  68. wingify/models/campaign/campaign_model.py +140 -0
  69. wingify/models/campaign/feature_model.py +95 -0
  70. wingify/models/campaign/holdout_model.py +94 -0
  71. wingify/models/campaign/impact_campaign_model.py +60 -0
  72. wingify/models/campaign/metric_model.py +42 -0
  73. wingify/models/campaign/rule_model.py +42 -0
  74. wingify/models/campaign/variable_model.py +44 -0
  75. wingify/models/campaign/variation_model.py +109 -0
  76. wingify/models/gateway_service_model.py +48 -0
  77. wingify/models/schemas/__init__.py +13 -0
  78. wingify/models/schemas/campaign_group_schema.py +19 -0
  79. wingify/models/schemas/campaign_metric_schema.py +26 -0
  80. wingify/models/schemas/campaign_schema.py +37 -0
  81. wingify/models/schemas/campaign_variation_schema.py +34 -0
  82. wingify/models/schemas/empty_object_schema.py +15 -0
  83. wingify/models/schemas/feature_schema.py +38 -0
  84. wingify/models/schemas/group_schema.py +37 -0
  85. wingify/models/schemas/holdout_schema.py +29 -0
  86. wingify/models/schemas/rule_schema.py +24 -0
  87. wingify/models/schemas/settings_schema.py +47 -0
  88. wingify/models/schemas/variable_schema.py +24 -0
  89. wingify/models/settings/__init__.py +13 -0
  90. wingify/models/settings/internal_event_sampling_settings_model.py +53 -0
  91. wingify/models/settings/settings_model.py +127 -0
  92. wingify/models/storage/__init__.py +13 -0
  93. wingify/models/storage/storage_model.py +84 -0
  94. wingify/models/user/__init__.py +13 -0
  95. wingify/models/user/context_model.py +113 -0
  96. wingify/models/user/context_vwo_model.py +34 -0
  97. wingify/models/user/get_flag.py +47 -0
  98. wingify/models/vwo_options_model.py +21 -0
  99. wingify/models/wingify_options_model.py +129 -0
  100. wingify/packages/__init__.py +13 -0
  101. wingify/packages/decision_maker/__init__.py +13 -0
  102. wingify/packages/decision_maker/decision_maker.py +89 -0
  103. wingify/packages/logger/__init__.py +13 -0
  104. wingify/packages/logger/core/__init__.py +13 -0
  105. wingify/packages/logger/core/log_manager.py +123 -0
  106. wingify/packages/logger/core/log_transport_manager.py +57 -0
  107. wingify/packages/logger/enums/__init__.py +13 -0
  108. wingify/packages/logger/enums/log_level_enum.py +24 -0
  109. wingify/packages/logger/enums/log_level_number_enum.py +21 -0
  110. wingify/packages/logger/log_message_builder.py +70 -0
  111. wingify/packages/logger/logger.py +38 -0
  112. wingify/packages/logger/transports/__init__.py +13 -0
  113. wingify/packages/logger/transports/console_transport.py +43 -0
  114. wingify/packages/network_layer/__init__.py +13 -0
  115. wingify/packages/network_layer/client/__init__.py +13 -0
  116. wingify/packages/network_layer/client/network_client.py +167 -0
  117. wingify/packages/network_layer/handlers/__init__.py +13 -0
  118. wingify/packages/network_layer/handlers/request_handler.py +40 -0
  119. wingify/packages/network_layer/manager/__init__.py +13 -0
  120. wingify/packages/network_layer/manager/network_manager.py +79 -0
  121. wingify/packages/network_layer/models/__init__.py +13 -0
  122. wingify/packages/network_layer/models/global_request_model.py +70 -0
  123. wingify/packages/network_layer/models/request_model.py +133 -0
  124. wingify/packages/network_layer/models/response_model.py +55 -0
  125. wingify/packages/segmentation_evaluator/__init__.py +13 -0
  126. wingify/packages/segmentation_evaluator/core/__init__.py +13 -0
  127. wingify/packages/segmentation_evaluator/core/segmentation_manager.py +140 -0
  128. wingify/packages/segmentation_evaluator/enums/__init__.py +13 -0
  129. wingify/packages/segmentation_evaluator/enums/segment_operand_regex_enum.py +31 -0
  130. wingify/packages/segmentation_evaluator/enums/segment_operand_value_enum.py +29 -0
  131. wingify/packages/segmentation_evaluator/enums/segment_operator_value_enum.py +37 -0
  132. wingify/packages/segmentation_evaluator/evaluators/__init__.py +13 -0
  133. wingify/packages/segmentation_evaluator/evaluators/segment_evaluator.py +237 -0
  134. wingify/packages/segmentation_evaluator/evaluators/segment_operand_evaluator.py +518 -0
  135. wingify/packages/segmentation_evaluator/utils/__init__.py +13 -0
  136. wingify/packages/segmentation_evaluator/utils/segment_util.py +33 -0
  137. wingify/packages/segmentation_evaluator/utils/web_testing_segment_util.py +295 -0
  138. wingify/packages/storage/__init__.py +13 -0
  139. wingify/packages/storage/connector.py +25 -0
  140. wingify/packages/storage/storage.py +39 -0
  141. wingify/resources/__init__.py +13 -0
  142. wingify/resources/debug-messages.json +21 -0
  143. wingify/resources/error-messages.json +62 -0
  144. wingify/resources/info-message.json +47 -0
  145. wingify/resources/trace-messages.json +1 -0
  146. wingify/resources/warn-messages.json +1 -0
  147. wingify/services/__init__.py +13 -0
  148. wingify/services/batch_event_queue.py +140 -0
  149. wingify/services/campaign_decision_service.py +268 -0
  150. wingify/services/hooks_manager.py +65 -0
  151. wingify/services/internal_events_sampling_service.py +62 -0
  152. wingify/services/settings_manager.py +293 -0
  153. wingify/services/storage_service.py +58 -0
  154. wingify/services/url_service.py +51 -0
  155. wingify/utils/__init__.py +13 -0
  156. wingify/utils/aliasing_util.py +108 -0
  157. wingify/utils/brand_context.py +26 -0
  158. wingify/utils/brand_util.py +37 -0
  159. wingify/utils/campaign_util.py +592 -0
  160. wingify/utils/data_type_util.py +125 -0
  161. wingify/utils/debugger_service_util.py +58 -0
  162. wingify/utils/decision_util.py +589 -0
  163. wingify/utils/event_util.py +85 -0
  164. wingify/utils/function_util.py +188 -0
  165. wingify/utils/gateway_service_util.py +179 -0
  166. wingify/utils/holdout_util.py +264 -0
  167. wingify/utils/impression_util.py +151 -0
  168. wingify/utils/internal_events_sampling_util.py +106 -0
  169. wingify/utils/log_message_util.py +95 -0
  170. wingify/utils/meg_util.py +561 -0
  171. wingify/utils/model_utils.py +136 -0
  172. wingify/utils/network_util.py +706 -0
  173. wingify/utils/rule_evaluation_util.py +102 -0
  174. wingify/utils/settings_util.py +39 -0
  175. wingify/utils/usage_stats_util.py +116 -0
  176. wingify/utils/uuid_util.py +81 -0
  177. wingify/vwo_client.py +21 -0
  178. wingify/wingify.py +159 -0
  179. wingify/wingify_builder.py +282 -0
  180. wingify/wingify_client.py +520 -0
  181. wingify_fme_python_sdk-1.70.0.dist-info/METADATA +1415 -0
  182. wingify_fme_python_sdk-1.70.0.dist-info/RECORD +186 -0
  183. wingify_fme_python_sdk-1.70.0.dist-info/WHEEL +5 -0
  184. wingify_fme_python_sdk-1.70.0.dist-info/licenses/LICENSE +202 -0
  185. wingify_fme_python_sdk-1.70.0.dist-info/licenses/NOTICE +18 -0
  186. wingify_fme_python_sdk-1.70.0.dist-info/top_level.txt +3 -0
@@ -0,0 +1,102 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ from ..models.settings.settings_model import SettingsModel
17
+ from ..models.campaign.campaign_model import CampaignModel
18
+ from ..models.campaign.feature_model import FeatureModel
19
+ from ..models.user.context_model import ContextModel
20
+ from ..utils.data_type_util import is_object
21
+ from ..utils.decision_util import check_whitelisting_and_pre_seg
22
+ from ..utils.campaign_util import get_experiment_key, get_rollout_key
23
+ from ..services.storage_service import StorageService
24
+ from ..utils.network_util import get_track_user_payload_data
25
+ from typing import Dict
26
+ from ..enums.event_enum import EventEnum
27
+ from ..enums.campaign_type_enum import CampaignTypeEnum
28
+
29
+ def evaluate_rule(
30
+ settings: SettingsModel,
31
+ feature: FeatureModel,
32
+ campaign: CampaignModel,
33
+ context: ContextModel,
34
+ evaluated_feature_map: Dict,
35
+ meg_group_winner_campaigns: Dict,
36
+ storage_service: StorageService,
37
+ decision: Dict,
38
+ ) -> Dict:
39
+ """
40
+ Evaluates the rules for a given campaign and feature based on the provided context.
41
+ This function checks for whitelisting and pre-segmentation conditions, and if applicable,
42
+ sends an impression for the variation shown.
43
+
44
+ :param settings: SettingsModel object containing the settings configuration for the evaluation.
45
+ :param feature: FeatureModel object representing the feature being evaluated.
46
+ :param campaign: CampaignModel object associated with the feature.
47
+ :param context: ContextModel object representing the user context for evaluation.
48
+ :param evaluated_feature_map: A dictionary of evaluated features.
49
+ :param meg_group_winner_campaigns: A dictionary of MEG group winner campaigns.
50
+ :param storage_service: StorageService object for persistence.
51
+ :param decision: The decision object that will be updated based on the evaluation.
52
+ :return: A dictionary containing the result of the pre-segmentation and the whitelisted object, if any.
53
+ """
54
+ # Initialize payload to None
55
+ payload = None
56
+
57
+ # Perform whitelisting and pre-segmentation checks
58
+ pre_segmentation_result, whitelisted_object = check_whitelisting_and_pre_seg(
59
+ settings,
60
+ feature,
61
+ campaign,
62
+ context,
63
+ evaluated_feature_map,
64
+ meg_group_winner_campaigns,
65
+ storage_service,
66
+ decision,
67
+ )
68
+
69
+ # If pre-segmentation is successful and a whitelisted object exists, proceed to send an impression
70
+ if (
71
+ pre_segmentation_result
72
+ and is_object(whitelisted_object)
73
+ and len(whitelisted_object) > 0
74
+ ):
75
+ # Update the decision object with campaign and variation details
76
+ if campaign.get_type() == CampaignTypeEnum.ROLLOUT.value:
77
+ decision.update(
78
+ {
79
+ "rolloutId": campaign.get_id(),
80
+ "rolloutKey": get_rollout_key(campaign, feature.get_key()),
81
+ "rolloutVariationId": whitelisted_object["variationId"],
82
+ }
83
+ )
84
+ else:
85
+ decision.update(
86
+ {
87
+ "experimentId": campaign.get_id(),
88
+ "experimentKey": get_experiment_key(campaign, feature.get_key()),
89
+ "experimentVariationId": whitelisted_object["variationId"],
90
+ }
91
+ )
92
+
93
+ payload = get_track_user_payload_data(
94
+ settings,
95
+ EventEnum.VARIATION_SHOWN.value,
96
+ campaign.get_id(),
97
+ whitelisted_object["variation"].get_id(),
98
+ context,
99
+ )
100
+
101
+ # Return the results of the evaluation
102
+ return pre_segmentation_result, whitelisted_object, decision, payload
@@ -0,0 +1,39 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ from ..models.settings.settings_model import SettingsModel
17
+ from .campaign_util import set_variation_allocation
18
+ from .function_util import add_linked_campaigns_to_settings
19
+ from .gateway_service_util import add_is_gateway_service_required_flag
20
+ from typing import Any, Dict
21
+
22
+
23
+ def set_settings_and_add_campaigns_to_rules(
24
+ settings: Dict, vwo_client_instance: Any
25
+ ) -> None:
26
+ # Initialize the settings model with the provided settings
27
+ vwo_client_instance._settings = SettingsModel(settings)
28
+ vwo_client_instance.original_settings = settings
29
+ # Get the campaigns from the settings once and process each campaign
30
+ campaigns = vwo_client_instance._settings.get_campaigns()
31
+ for index, campaign in enumerate(campaigns):
32
+ set_variation_allocation(campaign)
33
+ campaigns[index] = (
34
+ campaign # Update the campaign back into the List (if necessary)
35
+ )
36
+
37
+ # Add linked campaigns to settings and set gateway service required flag
38
+ add_linked_campaigns_to_settings(vwo_client_instance._settings)
39
+ add_is_gateway_service_required_flag(vwo_client_instance._settings)
@@ -0,0 +1,116 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from typing import Dict, Any, Union
16
+ import sys
17
+ from ..constants.Constants import Constants
18
+ from ..packages.logger.enums.log_level_number_enum import LogLevelNumberEnum
19
+ from ..services.settings_manager import SettingsManager
20
+
21
+ class UsageStatsUtil:
22
+ """
23
+ Manages usage statistics for the SDK.
24
+ Tracks various features and configurations being used by the client.
25
+ Implements Singleton pattern to ensure a single instance.
26
+ """
27
+
28
+ _instance = None
29
+
30
+ def __new__(cls):
31
+ """
32
+ Ensures only one instance of UsageStatsUtil exists (Singleton pattern).
33
+ """
34
+ if cls._instance is None:
35
+ cls._instance = super(UsageStatsUtil, cls).__new__(cls)
36
+ cls._instance._usage_stats_data = {}
37
+ return cls._instance
38
+
39
+ def set_usage_stats(self, options: Dict[str, Any]) -> None:
40
+ """
41
+ Sets usage statistics based on provided options.
42
+ Maps various SDK features and configurations to boolean flags.
43
+
44
+ Args:
45
+ options (Dict[str, Any]): Configuration options for the SDK containing:
46
+ - storage: Storage service configuration
47
+ - logger: Logger configuration
48
+ - batch_event_data: Event batching configuration
49
+ - integrations: Integrations configuration
50
+ - polling_interval: Polling interval configuration
51
+ - sdk_name: SDK name configuration
52
+ """
53
+ data: Dict[str, Union[str, int]] = {}
54
+ data["a"] = SettingsManager.get_instance().get_account_id()
55
+ data["env"] = SettingsManager.get_instance().get_sdk_key()
56
+
57
+ # Map configuration options to usage stats flags
58
+ if options.get("integrations"):
59
+ data["ig"] = 1 # Integration enabled
60
+ if options.get("batch_event_data"):
61
+ data["eb"] = 1 # Event batching enabled
62
+
63
+ if options.get("gateway_service"):
64
+ data["gs"] = 1 # Gateway service enabled
65
+
66
+ # Check for custom logger
67
+ logger = options.get("logger")
68
+ if logger and (logger.get("transport") or logger.get("transports")):
69
+ data["cl"] = 1
70
+
71
+ if options.get("storage"):
72
+ data["ss"] = 1 # Storage service configured
73
+
74
+ if logger and logger.get("level"):
75
+ data["ll"] = getattr(
76
+ LogLevelNumberEnum, logger["level"].upper(), LogLevelNumberEnum.ERROR
77
+ ) # Default to -1 if level is not recognized
78
+
79
+ if options.get("poll_interval"):
80
+ data["pi"] = 1 # Polling interval configured
81
+
82
+ # Check for SDK meta event-analytics flag (_wingify_meta or legacy _vwo_meta)
83
+ sdk_meta = options.get("_wingify_meta") or options.get("_vwo_meta")
84
+ if sdk_meta and sdk_meta.get("ea"):
85
+ data["_ea"] = 1
86
+
87
+ # Add Python version if available
88
+ if hasattr(sys, "version"):
89
+ data["lv"] = sys.version
90
+
91
+ # Check threading configuration
92
+ threading_config = options.get("threading")
93
+ if not threading_config or (
94
+ threading_config and threading_config.get("enabled") is True
95
+ ):
96
+ data["th"] = 1
97
+ # Check if max_workers is passed
98
+ if threading_config and threading_config.get("max_workers"):
99
+ data["th_mps"] = threading_config["max_workers"]
100
+
101
+ self._usage_stats_data = data
102
+
103
+ def get_usage_stats(self) -> Dict[str, Union[bool, str, int]]:
104
+ """
105
+ Retrieves the current usage statistics.
106
+
107
+ Returns:
108
+ Dict[str, Union[bool, str, int]]: Dictionary containing boolean flags for various SDK features in use
109
+ """
110
+ return self._usage_stats_data
111
+
112
+ def clear_usage_stats(self) -> None:
113
+ """
114
+ Clears the usage statistics data.
115
+ """
116
+ self._usage_stats_data = {}
@@ -0,0 +1,81 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ import uuid
17
+ import re
18
+
19
+ def get_random_uuid(sdk_key: str) -> str:
20
+ """
21
+ Generates a random UUID based on an API key.
22
+
23
+ :param sdk_key: The API key used to generate a namespace for the UUID.
24
+ :return: A random UUID string.
25
+ """
26
+ # Generate a namespace based on the API key using DNS namespace
27
+ namespace = uuid.uuid5(uuid.NAMESPACE_DNS, sdk_key)
28
+ # Generate a random UUID using the namespace derived from the API key
29
+ random_uuid = uuid.uuid5(namespace, str(uuid.uuid4()))
30
+
31
+ return str(random_uuid)
32
+
33
+
34
+ def get_uuid(user_id: str, account_id: str) -> str:
35
+ """
36
+ Generates a UUID for a user based on their userId and accountId.
37
+
38
+ :param user_id: The user's ID.
39
+ :param account_id: The account ID associated with the user.
40
+ :return: A UUID string formatted without dashes and in uppercase.
41
+ """
42
+ VWO_NAMESPACE = uuid.uuid5(uuid.NAMESPACE_URL, "https://vwo.com")
43
+ # Generate a namespace UUID based on the accountId
44
+ user_id_namespace = generate_uuid(str(account_id), VWO_NAMESPACE)
45
+ # Generate a UUID based on the userId and the previously generated namespace
46
+ uuid_for_user_id_account_id = generate_uuid(user_id, uuid.UUID(user_id_namespace))
47
+ if uuid_for_user_id_account_id:
48
+ # Remove all dashes from the UUID and convert it to uppercase
49
+ desired_uuid = uuid_for_user_id_account_id.replace("-", "").upper()
50
+ return desired_uuid
51
+ return None
52
+
53
+
54
+ def generate_uuid(name: str, namespace: uuid.UUID) -> str:
55
+ """
56
+ Helper function to generate a UUID v5 based on a name and a namespace.
57
+
58
+ :param name: The name from which to generate the UUID.
59
+ :param namespace: The namespace used to generate the UUID.
60
+ :return: A UUID string.
61
+ """
62
+ # Check for valid input to prevent errors
63
+ if not name or not namespace:
64
+ return None
65
+
66
+ generated_uuid = uuid.uuid5(namespace, name)
67
+ return str(generated_uuid)
68
+
69
+ def is_web_uuid(id: str) -> bool:
70
+ """
71
+ Checks whether the given ID string matches the expected VWO web UUID format.
72
+
73
+ A valid web UUID for VWO starts with either 'D' or 'J' followed by exactly 32 hexadecimal characters (case-insensitive).
74
+ The function returns True if the string matches this pattern, and False otherwise.
75
+
76
+ :param id: The ID string to validate.
77
+ :return: True if the ID is a valid VWO web UUID, False otherwise.
78
+ """
79
+ if not isinstance(id, str):
80
+ return False
81
+ return re.match(r'^[DJ][0-9A-Fa-f]{32}$', id) is not None
wingify/vwo_client.py ADDED
@@ -0,0 +1,21 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Legacy alias — VWOClient is WingifyClient."""
16
+
17
+ from wingify.wingify_client import WingifyClient
18
+
19
+ VWOClient = WingifyClient
20
+
21
+ __all__ = ["VWOClient"]
wingify/wingify.py ADDED
@@ -0,0 +1,159 @@
1
+ # Copyright 2024-2026 Wingify Software Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ from typing import Dict, Any, Optional
17
+ import time
18
+
19
+ from wingify.wingify_builder import WingifyBuilder
20
+ from wingify.wingify_client import WingifyClient
21
+ from wingify.utils.event_util import send_sdk_init_event, send_sdk_usage_stats_event
22
+ from wingify.utils.uuid_util import get_uuid as uuid_util_get_uuid
23
+ from wingify.utils.data_type_util import is_string
24
+ from wingify.utils.brand_context import set_is_via_vwo
25
+ from wingify.utils.brand_util import get_brand
26
+ from wingify.utils.log_message_util import refresh_log_messages
27
+ from wingify.packages.logger.core.log_manager import LogManager
28
+ from wingify.services.internal_events_sampling_service import InternalEventsSamplingService
29
+
30
+
31
+ class Wingify:
32
+ """
33
+ Canonical SDK entry orchestrator. Initializes services, fetches settings,
34
+ and returns a WingifyClient singleton.
35
+ """
36
+
37
+ wingify_builder: "WingifyBuilder" = None
38
+ instance: "WingifyClient" = None
39
+
40
+ def __init__(self, options: Dict):
41
+ Wingify.set_instance(options)
42
+
43
+ @staticmethod
44
+ def set_instance(options: Dict) -> "WingifyClient":
45
+ is_via_vwo = bool(options.get("is_via_vwo", False))
46
+ set_is_via_vwo(is_via_vwo)
47
+ refresh_log_messages(is_via_vwo)
48
+ LogManager._instance = None
49
+
50
+ # Accept both Wingify and legacy VWO builder option keys
51
+ custom_builder = options.get("wingifyBuilder") or options.get("vwoBuilder")
52
+ Wingify.wingify_builder = custom_builder or WingifyBuilder(options)
53
+
54
+ Wingify.wingify_builder.set_logger().set_settings_manager().set_storage().set_network_manager().set_segmentation().init_polling().init_usage_stats()
55
+
56
+ settings = Wingify.wingify_builder.get_settings(force=False)
57
+ Wingify.instance = Wingify.wingify_builder.build(settings)
58
+ Wingify.instance.settings_fetch_time = Wingify.wingify_builder.setting_file_manager.settings_fetch_time
59
+ Wingify.instance.is_settings_valid_on_init = Wingify.wingify_builder.setting_file_manager.is_settings_valid_on_init
60
+
61
+ Wingify.wingify_builder.init_batching()
62
+ return Wingify.instance
63
+
64
+ @staticmethod
65
+ def getInstance() -> Optional["Wingify"]:
66
+ return Wingify.instance
67
+
68
+
69
+ def init(options: Dict[str, Any]) -> Optional["WingifyClient"]:
70
+ """Initialize the SDK and return a WingifyClient instance."""
71
+ options = dict(options or {})
72
+ if "is_via_vwo" not in options:
73
+ options["is_via_vwo"] = False
74
+
75
+ start_time_for_init = time.time() * 1000
76
+ brand = get_brand(options["is_via_vwo"])
77
+
78
+ if not options or "sdk_key" not in options or not options["sdk_key"]:
79
+ print(
80
+ f"SDK key is required to initialize {brand}. Please provide the sdk_key in the options.",
81
+ None,
82
+ )
83
+ return None
84
+
85
+ if not options or "account_id" not in options or not options["account_id"]:
86
+ print(
87
+ f"Account ID is required to initialize {brand}. Please provide the account_id in the options.",
88
+ None,
89
+ )
90
+ return None
91
+
92
+ if options.get("is_aliasing_enabled", False) and (
93
+ not options.get("gateway_service", None)
94
+ or not options.get("gateway_service", None).get("url")
95
+ ):
96
+ print(
97
+ "Gateway service URL is required when aliasing is enabled. Please provide the gateway_service in the options.",
98
+ None,
99
+ )
100
+ return None
101
+
102
+ try:
103
+ instance = Wingify.set_instance(options)
104
+ sdk_init_time = int((time.time() * 1000) - start_time_for_init)
105
+
106
+ was_initialized = False
107
+ if getattr(instance, '_settings', None) is not None:
108
+ sdk_meta_info = instance._settings.get_sdk_meta_info()
109
+ if sdk_meta_info:
110
+ was_initialized = sdk_meta_info.get("wasInitializedEarlier", False)
111
+
112
+ if instance.is_settings_valid_on_init and not was_initialized:
113
+ send_sdk_init_event()
114
+
115
+ usage_stats_account_id = None
116
+ if getattr(instance, '_settings', None) is not None:
117
+ usage_stats_account_id = instance._settings.get_usage_stats_account_id()
118
+
119
+ if usage_stats_account_id:
120
+ sampling_service = InternalEventsSamplingService()
121
+ if sampling_service.should_send_usage_stats_event(instance._settings):
122
+ settings_fetch_time = instance.settings_fetch_time
123
+ send_sdk_usage_stats_event(
124
+ usage_stats_account_id,
125
+ settings_fetch_time,
126
+ sdk_init_time,
127
+ options,
128
+ )
129
+
130
+ return instance
131
+ except Exception as e:
132
+ print(f"{brand} initialization failed. Error:", e)
133
+ return None
134
+
135
+
136
+ def getUUID(user_id: str, account_id: str) -> Optional[str]:
137
+ """
138
+ Generate a deterministic UUID for a given user and account combination.
139
+
140
+ :param user_id: The user's ID (must be a non-empty string).
141
+ :param account_id: The account ID (must be a non-empty string).
142
+ :return: UUID without dashes in uppercase, or None on invalid input or error.
143
+ """
144
+ api_name = "getUUID"
145
+
146
+ try:
147
+ if not is_string(user_id) or user_id == "":
148
+ print(f"userId passed to {api_name} API is not of valid type.")
149
+ return None
150
+
151
+ if not is_string(account_id) or account_id == "":
152
+ print(f"accountId passed to {api_name} API is not of valid type.")
153
+ return None
154
+
155
+ return uuid_util_get_uuid(user_id, account_id)
156
+
157
+ except Exception as error:
158
+ print(f"API - {api_name} failed to execute. Trace: {error}")
159
+ return None