You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This open source library allows you to A/B Test your Website at server-side.
8
+
## Overview
9
+
10
+
The **VWO Feature Management and Experimentation SDK** (VWO FME Python SDK) enables python developers to integrate feature flagging and experimentation into their applications. This SDK provides full control over feature rollout, A/B testing, and event tracking, allowing teams to manage features dynamically and gain insights into user behavior.
9
11
10
12
## Requirements
11
13
@@ -19,9 +21,10 @@ It's recommended you use [virtualenv](https://virtualenv.pypa.io/en/latest/) to
19
21
pip install vwo-fme-python-sdk
20
22
```
21
23
22
-
## Basic usage
24
+
## Basic Usage Example
23
25
24
-
```python
26
+
The following example demonstrates initializing the SDK with a VWO account ID and SDK key, setting a user context, checking if a feature flag is enabled, and tracking a custom event.
|`account_id`| VWO Account ID for authentication. | Yes | str |`'123456'`|
60
+
|`sdk_key`| SDK key corresponding to the specific environment to initialize the VWO SDK Client. You can get this key from VWO Application. | Yes | str |`'32-alpha-numeric-sdk-key'`|
61
+
|`poll_interval`| Time interval for fetching updates from VWO servers (in milliseconds). | No | int |`60_000`|
62
+
|`gateway_service`| Configuration for integrating VWO Gateway Service. Service. | No | Dictionary | see [Gateway](#gateway) section |
63
+
|`storage`| Custom storage connector for persisting user decisions and campaign data. data. | No | Dictionary | See [Storage](#storage) section |
64
+
|`logger`| Toggle log levels for more insights or for debugging purposes. You can also customize your own transport in order to have better control over log messages. | No | Dictionary | See [Logger](#logger) section |
65
+
|`integrations`| Callback function for integrating with third-party analytics services. | No | Function | See [Integrations](#integrations) section |
66
+
67
+
### User Context
68
+
69
+
The `context` uniquely identifies users and is crucial for consistent feature rollouts. A typical `context` is a dictionary that includes an `id` key for identifying the user. It can also include other attributes that can be used for targeting and segmentation, such as `custom_variables`, `user_agent`, and `ip_address`.
70
+
71
+
#### Parameters Table
72
+
73
+
The following table explains all the parameters in the `context` dictionary:
|`id`| Unique identifier for the user. | Yes | str |
78
+
|`custom_variables`| Custom attributes for targeting. | No | Dict |
79
+
|`user_agent`| User agent string for identifying the user's browser and operating system. | No | str |
80
+
|`ip_address`| IP address of the user. | No | str |
81
+
82
+
#### Example
83
+
84
+
```python
85
+
context = {
86
+
'id': 'unique_user_id',
87
+
'custom_variables': {
88
+
'age': 25,
89
+
'location': 'US'
90
+
},
91
+
'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
92
+
'ip_address': '1.1.1.1'
93
+
}
94
+
```
95
+
96
+
### Basic Feature Flagging
97
+
98
+
Feature Flags serve as the foundation for all testing, personalization, and rollout rules within FME.
99
+
To implement a feature flag, first use the `get_flag()` method to retrieve the flag configuration.
100
+
The `get_flag()` method provides a simple way to check if a feature is enabled for a specific user and access its variables. It returns a `GetFlag` object that contains methods like `is_enabled()` for checking the feature's status and `get_variable()` for retrieving any associated variables.
Feature flags can be enhanced with connected metrics to track key performance indicators (KPIs) for your features. These metrics help measure the effectiveness of your testing rules by comparing control versus variation performance, and evaluate the impact of personalization and rollout campaigns. Use the `track_event()` method to track custom events like conversions, user interactions, and other important metrics:
User attributes provide rich contextual information about users, enabling powerful personalization. The `set_attribute()` method in VWOClient provides a simple way to associate these attributes with users in VWO for advanced segmentation. The method accepts an attribute key, value, and dictionary containing the user information. Here's what you need to know about the method parameters:
The `poll_interval` is an optional parameter that allows the SDK to automatically fetch and update settings from the VWO server at specified intervals. Setting this parameter ensures your application always uses the latest configuration.
158
+
159
+
```python
160
+
options = {
161
+
'sdk_key': '32-alpha-numeric-sdk-key', # SDK Key
162
+
'account_id': '123456', # VWO Account ID
163
+
'poll_interval': 60000# Set the poll interval to 60 seconds
164
+
}
165
+
166
+
vwo_client = init(options)
167
+
```
168
+
169
+
### Gateway
170
+
171
+
The VWO FME Gateway Service is an optional but powerful component that enhances VWO's Feature Management and Experimentation (FME) SDKs. It acts as a critical intermediary for pre-segmentation capabilities based on user location and user agent (UA). By deploying this service within your infrastructure, you benefit from minimal latency and strengthened security for all FME operations.
172
+
173
+
#### Why Use a Gateway?
174
+
175
+
The Gateway Service is required in the following scenarios:
176
+
177
+
- When using pre-segmentation features based on user location or user agent.
178
+
- For applications requiring advanced targeting capabilities.
179
+
- It's mandatory when using any thin-client SDK (e.g., Go).
180
+
181
+
#### How to Use the Gateway
182
+
183
+
The gateway can be customized by passing the `gateway_service` parameter in the `init` configuration.
184
+
185
+
```python
186
+
options = {
187
+
'sdk_key': '32-alpha-numeric-sdk-key', # SDK Key
188
+
'account_id': '123456', # VWO Account ID
189
+
'gateway_service': {
190
+
'url': 'http://custom.gateway.com'
191
+
}
192
+
}
193
+
vwo_client = init(options)
48
194
```
49
195
50
-
-**Storage**
196
+
### Storage
197
+
198
+
The SDK operates in a stateless mode by default, meaning each `get_flag` call triggers a fresh evaluation of the flag against the current user context.
199
+
200
+
To optimize performance and maintain consistency, you can implement a custom storage mechanism by passing a `storage` parameter during initialization. This allows you to persist feature flag decisions in your preferred database system (like Redis, MongoDB, or any other data store).
201
+
202
+
Key benefits of implementing storage:
203
+
204
+
- Improved performance by caching decisions
205
+
- Consistent user experience across sessions
206
+
- Reduced load on your application
207
+
208
+
The storage mechanism ensures that once a decision is made for a user, it remains consistent even if campaign settings are modified in the VWO Application. This is particularly useful for maintaining a stable user experience during A/B tests and feature rollouts.
51
209
52
210
```python
53
211
from vwo import StorageConnector
@@ -56,7 +214,7 @@ class UserStorage(StorageConnector):
|`level`| Log level to control verbosity of logs | Yes | str |`ERROR`|
245
+
|`prefix`| Custom prefix for log messages | No | str |`VWO-SDK`|
246
+
247
+
#### Example 1: Set log level to control verbosity of logs
80
248
81
249
```python
82
-
from vwo import LogLevelEnum
83
250
options = {
84
-
'sdk_key': '32-alpha-numeric-sdk-key', # SDK Key
85
251
'account_id': '123456', # VWO Account ID
252
+
'sdk_key': '32-alpha-numeric-sdk-key', # SDK Key
86
253
'logger': {
87
-
'level': LogLevelEnum.DEBUG,
88
-
'prefix': 'VWO-FME-PYTHON-SDK'
254
+
'level': 'DEBUG'
89
255
}
90
256
}
91
-
92
257
vwo_client = init(options)
93
258
```
94
259
95
-
-**Polling support**
260
+
#### Example 2: Add custom prefix to log messages for easier identification
96
261
97
262
```python
98
263
options = {
99
-
'sdk_key': '32-alpha-numeric-sdk-key', # SDK Key
100
264
'account_id': '123456', # VWO Account ID
101
-
'poll_interval': 5000# in milliseconds
265
+
'sdk_key': '32-alpha-numeric-sdk-key', # SDK Key
266
+
'logger': {
267
+
'level': 'DEBUG',
268
+
'prefix': 'CUSTOM LOG PREFIX'
269
+
}
102
270
}
271
+
vwo_client = init(options)
272
+
```
273
+
274
+
### Integrations
275
+
VWO FME SDKs provide seamless integration with third-party tools like analytics platforms, monitoring services, customer data platforms (CDPs), and messaging systems. This is achieved through a simple yet powerful callback mechanism that receives VWO-specific properties and can forward them to any third-party tool of your choice.
103
276
277
+
```python
278
+
defcallback(properties):
279
+
# properties will contain all the required VWO specific information
The version history tracks changes, improvements, and bug fixes in each version. For a full history, see the [CHANGELOG.md](https://github.com/wingify/vwo-fme-python-sdk/blob/master/CHANGELOG.md).
126
311
127
312
## Contributing
128
313
129
-
Please go through our [contributing guidelines](https://github.com/wingify/vwo-fme-python-sdk/blob/master/CONTRIBUTING.md)
314
+
We welcome contributions to improve this SDK! Please read our [contributing guidelines](https://github.com/wingify/vwo-fme-python-sdk/blob/master/CONTRIBUTING.md) before submitting a PR.
130
315
131
316
132
317
## Code of Conduct
133
318
134
-
[Code of Conduct](https://github.com/wingify/vwo-fme-python-sdk/blob/master/CODE_OF_CONDUCT.md)
319
+
Our [Code of Conduct](https://github.com/wingify/vwo-fme-python-sdk/blob/master/CODE_OF_CONDUCT.md) outlines expectations for all contributors and maintainers.
0 commit comments