ABSmartly 0.1.2__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.
- absmartly-0.1.2.dist-info/LICENSE +8 -0
- absmartly-0.1.2.dist-info/METADATA +261 -0
- absmartly-0.1.2.dist-info/RECORD +71 -0
- absmartly-0.1.2.dist-info/WHEEL +5 -0
- absmartly-0.1.2.dist-info/top_level.txt +1 -0
- sdk/__init__.py +0 -0
- sdk/absmarly.py +67 -0
- sdk/absmartly_config.py +17 -0
- sdk/audience_deserializer.py +12 -0
- sdk/audience_matcher.py +31 -0
- sdk/client.py +56 -0
- sdk/client_config.py +18 -0
- sdk/context.py +780 -0
- sdk/context_config.py +13 -0
- sdk/context_data_deserializer.py +13 -0
- sdk/context_data_provider.py +12 -0
- sdk/context_event_handler.py +14 -0
- sdk/context_event_logger.py +19 -0
- sdk/context_event_serializer.py +10 -0
- sdk/default_audience_deserializer.py +17 -0
- sdk/default_context_data_deserializer.py +18 -0
- sdk/default_context_data_provider.py +15 -0
- sdk/default_context_event_handler.py +19 -0
- sdk/default_context_event_serializer.py +11 -0
- sdk/default_http_client.py +63 -0
- sdk/default_http_client_config.py +6 -0
- sdk/default_variable_parser.py +20 -0
- sdk/http_client.py +29 -0
- sdk/internal/__init__.py +0 -0
- sdk/internal/buffers.py +28 -0
- sdk/internal/lock/__init__.py +0 -0
- sdk/internal/lock/atomic_bool.py +18 -0
- sdk/internal/lock/atomic_int.py +24 -0
- sdk/internal/lock/concurrency.py +57 -0
- sdk/internal/lock/read_write_lock.py +30 -0
- sdk/internal/murmur32.py +82 -0
- sdk/internal/variant_assigner.py +36 -0
- sdk/json/__init__.py +0 -0
- sdk/json/attribute.py +7 -0
- sdk/json/context_data.py +7 -0
- sdk/json/experiement_application.py +5 -0
- sdk/json/experiment.py +22 -0
- sdk/json/experiment_variant.py +6 -0
- sdk/json/exposure.py +15 -0
- sdk/json/goal_achievement.py +7 -0
- sdk/json/publish_event.py +15 -0
- sdk/json/unit.py +6 -0
- sdk/jsonexpr/evaluator.py +30 -0
- sdk/jsonexpr/expr_evaluator.py +107 -0
- sdk/jsonexpr/json_expr.py +42 -0
- sdk/jsonexpr/operator.py +10 -0
- sdk/jsonexpr/operators/and_combinator.py +11 -0
- sdk/jsonexpr/operators/binary_operator.py +19 -0
- sdk/jsonexpr/operators/boolean_combinator.py +17 -0
- sdk/jsonexpr/operators/equals_operator.py +11 -0
- sdk/jsonexpr/operators/greater_than_operator.py +8 -0
- sdk/jsonexpr/operators/greater_than_or_equal_operator.py +8 -0
- sdk/jsonexpr/operators/in_operator.py +16 -0
- sdk/jsonexpr/operators/less_than_operator.py +8 -0
- sdk/jsonexpr/operators/less_than_or_equal_operator.py +9 -0
- sdk/jsonexpr/operators/match_operator.py +15 -0
- sdk/jsonexpr/operators/not_operator.py +8 -0
- sdk/jsonexpr/operators/null_operator.py +7 -0
- sdk/jsonexpr/operators/or_combinator.py +10 -0
- sdk/jsonexpr/operators/unary_operator.py +14 -0
- sdk/jsonexpr/operators/value_operator.py +7 -0
- sdk/jsonexpr/operators/var_operator.py +12 -0
- sdk/time/clock.py +8 -0
- sdk/time/fixed_clock.py +9 -0
- sdk/time/system_clock_utc.py +8 -0
- sdk/variable_parser.py +13 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright © 2022 <copyright holders>
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: absmartly
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: ABSmartly Python SDK lib
|
|
5
|
+
Author-email: ABSmartly <pram@gmail.com>
|
|
6
|
+
License: The MIT License (MIT)
|
|
7
|
+
Copyright © 2022 <copyright holders>
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
14
|
+
Project-URL: Homepage, https://github.com/absmartly/python3-sdk
|
|
15
|
+
Keywords: sdk,asbmartly
|
|
16
|
+
Classifier: Development Status :: 1 - Planning
|
|
17
|
+
Classifier: Intended Audience :: Science/Research
|
|
18
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
19
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
20
|
+
Classifier: Programming Language :: Python :: 2
|
|
21
|
+
Classifier: Programming Language :: Python :: 2.7
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.4
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.5
|
|
25
|
+
Requires-Python: >=3.9
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: requests (>=2.28.1)
|
|
29
|
+
Requires-Dist: urllib3 (>=1.26.12)
|
|
30
|
+
Requires-Dist: jsons (>=1.6.3)
|
|
31
|
+
Requires-Dist: tomli ; python_version < "3.11"
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: black ; extra == 'dev'
|
|
34
|
+
Requires-Dist: bumpver ; extra == 'dev'
|
|
35
|
+
Requires-Dist: isort ; extra == 'dev'
|
|
36
|
+
Requires-Dist: pip-tools ; extra == 'dev'
|
|
37
|
+
Requires-Dist: pytest ; extra == 'dev'
|
|
38
|
+
|
|
39
|
+
# A/B Smartly SDK
|
|
40
|
+
|
|
41
|
+
A/B Smartly - Python SDK
|
|
42
|
+
|
|
43
|
+
## Compatibility
|
|
44
|
+
|
|
45
|
+
The A/B Smartly Python SDK is compatible with Python 3.
|
|
46
|
+
It provides both a blocking and an asynchronous interfaces.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## Installation
|
|
50
|
+
|
|
51
|
+
### Python Modules
|
|
52
|
+
setuptools~=60.2.0
|
|
53
|
+
requests~=2.28.1
|
|
54
|
+
urllib3~=1.26.12
|
|
55
|
+
jsons~=1.6.3
|
|
56
|
+
|
|
57
|
+
### Dependencies
|
|
58
|
+
sh ./run.sh
|
|
59
|
+
|
|
60
|
+
## Getting Started
|
|
61
|
+
|
|
62
|
+
Please follow the [installation](#installation) instructions before trying the following code:
|
|
63
|
+
|
|
64
|
+
#### Initialization
|
|
65
|
+
This example assumes an Api Key, an Application, and an Environment have been created in the A/B Smartly web console.
|
|
66
|
+
```python
|
|
67
|
+
|
|
68
|
+
def main():
|
|
69
|
+
client_config = ClientConfig()
|
|
70
|
+
client_config.endpoint = "https://sandbox.test.io/v1"
|
|
71
|
+
client_config.api_key = "test"
|
|
72
|
+
client_config.application = "www"
|
|
73
|
+
client_config.environment = "prod"
|
|
74
|
+
|
|
75
|
+
default_client_config = DefaultHTTPClientConfig()
|
|
76
|
+
default_client = DefaultHTTPClient(default_client_config)
|
|
77
|
+
sdk_config = ABSmartlyConfig()
|
|
78
|
+
sdk_config.client = Client(client_config, default_client)
|
|
79
|
+
sdk = ABSmartly(sdk_config)
|
|
80
|
+
|
|
81
|
+
context_config = ContextConfig()
|
|
82
|
+
ctx = sdk.create_context(context_config)
|
|
83
|
+
|
|
84
|
+
# ...
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
#### Creating a new Context synchronously
|
|
89
|
+
```python
|
|
90
|
+
# define a new context request
|
|
91
|
+
context_config = ContextConfig()
|
|
92
|
+
context_config.publish_delay = 10
|
|
93
|
+
context_config.refresh_interval = 5
|
|
94
|
+
context_config.units = {"session_id": "bf06d8cb5d8137290c4abb64155584fbdb64d8",
|
|
95
|
+
"user_id": "12345"}
|
|
96
|
+
|
|
97
|
+
context_config = ContextConfig()
|
|
98
|
+
ctx = sdk.create_context(context_config)
|
|
99
|
+
ctx.wait_until_ready()
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
#### Creating a new Context asynchronously
|
|
103
|
+
```python
|
|
104
|
+
# define a new context request
|
|
105
|
+
context_config = ContextConfig()
|
|
106
|
+
context_config.publish_delay = 10
|
|
107
|
+
context_config.refresh_interval = 5
|
|
108
|
+
context_config.units = {"session_id": "bf06d8cb5d8137290c4abb64155584fbdb64d8",
|
|
109
|
+
"user_id": "12345"}
|
|
110
|
+
|
|
111
|
+
context_config = ContextConfig()
|
|
112
|
+
ctx = sdk.create_context(context_config)
|
|
113
|
+
ctx.wait_until_ready_async()
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
#### Setting extra units for a context
|
|
117
|
+
You can add additional units to a context by calling the `set_unit()` or the `set_units()` method.
|
|
118
|
+
This method may be used for example, when a user logs in to your application, and you want to use the new unit type to the context.
|
|
119
|
+
Please note that **you cannot override an already set unit type** as that would be a change of identity, and will throw an exception. In this case, you must create a new context instead.
|
|
120
|
+
The `SetUnit()` and `SetUnits()` methods can be called before the context is ready.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
context.set_unit("db_user_id", "1000013")
|
|
124
|
+
|
|
125
|
+
context.set_units({
|
|
126
|
+
"db_user_id": "1000013"
|
|
127
|
+
})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
#### Setting context attributes
|
|
131
|
+
The `set_attributes()` and `set_attributes()` methods can be called before the context is ready.
|
|
132
|
+
```python
|
|
133
|
+
context.set_attributes("user_agent", req.get_header("User-Agent"))
|
|
134
|
+
|
|
135
|
+
context.set_attributes({
|
|
136
|
+
"customer_age": "new_customer"
|
|
137
|
+
})
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### Selecting a treatment
|
|
141
|
+
```python
|
|
142
|
+
res, _ = context.get_treatment("exp_test_experiment")
|
|
143
|
+
if res == 0:
|
|
144
|
+
# user is in control group (variant 0)
|
|
145
|
+
else:
|
|
146
|
+
# user is in treatment group
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### Tracking a goal achievement
|
|
150
|
+
Goals are created in the A/B Smartly web console.
|
|
151
|
+
```python
|
|
152
|
+
context.track("payment", {
|
|
153
|
+
"item_count": 1,
|
|
154
|
+
"total_amount": 1999.99
|
|
155
|
+
})
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### Publishing pending data
|
|
159
|
+
Sometimes it is necessary to ensure all events have been published to the A/B Smartly collector, before proceeding.
|
|
160
|
+
You can explicitly call the `publish()` or `publish_async()` methods.
|
|
161
|
+
```python
|
|
162
|
+
context.publish()
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
#### Finalizing
|
|
166
|
+
The `close()` and `close_async()` methods will ensure all events have been published to the A/B Smartly collector, like `publish()`, and will also "seal" the context, throwing an error if any method that could generate an event is called.
|
|
167
|
+
```python
|
|
168
|
+
context.close()
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Refreshing the context with fresh experiment data
|
|
172
|
+
For long-running contexts, the context is usually created once when the application is first started.
|
|
173
|
+
However, any experiments being tracked in your production code, but started after the context was created, will not be triggered.
|
|
174
|
+
To mitigate this, we can use the `set_refresh_interval()` method on the context config.
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
default_client_config = DefaultHTTPClientConfig()
|
|
178
|
+
default_client_config.refresh_interval = 5
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Alternatively, the `refresh()` method can be called manually.
|
|
182
|
+
The `refresh()` method pulls updated experiment data from the A/B Smartly collector and will trigger recently started experiments when `get_treatment()` is called again.
|
|
183
|
+
```python
|
|
184
|
+
context.refresh()
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
#### Using a custom Event Logger
|
|
188
|
+
The A/B Smartly SDK can be instantiated with an event logger used for all contexts.
|
|
189
|
+
In addition, an event logger can be specified when creating a particular context, in the `ContextConfig`.
|
|
190
|
+
```python
|
|
191
|
+
class EventType(Enum):
|
|
192
|
+
ERROR = "error"
|
|
193
|
+
READY = "ready"
|
|
194
|
+
REFRESH = "refresh"
|
|
195
|
+
PUBLISH = "publish"
|
|
196
|
+
EXPOSURE = "exposure"
|
|
197
|
+
GOAL = "goal"
|
|
198
|
+
CLOSE = "close"
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
class ContextEventLogger:
|
|
202
|
+
|
|
203
|
+
@abstractmethod
|
|
204
|
+
def handle_event(self, event_type: EventType, data: object):
|
|
205
|
+
raise NotImplementedError
|
|
206
|
+
```
|
|
207
|
+
The data parameter depends on the type of event.
|
|
208
|
+
Currently, the SDK logs the following events:
|
|
209
|
+
|
|
210
|
+
| event | when | data |
|
|
211
|
+
|:---: |------------------------------------------------------------|---|
|
|
212
|
+
| `Error` | `Context` receives an error | `Throwable` object |
|
|
213
|
+
| `Ready` | `Context` turns ready | `ContextData` used to initialize the context |
|
|
214
|
+
| `Refresh` | `Context.refresh()` method succeeds | `ContextData` used to refresh the context |
|
|
215
|
+
| `Publish` | `Context.publish()` method succeeds | `PublishEvent` sent to the A/B Smartly event collector |
|
|
216
|
+
| `Exposure` | `Context.getTreatment()` method succeeds on first exposure | `Exposure` enqueued for publishing |
|
|
217
|
+
| `Goal` | `Context.track()` method succeeds | `GoalAchievement` enqueued for publishing |
|
|
218
|
+
| `Close` | `Context.close()` method succeeds the first time | `null` |
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
#### Peek at treatment variants
|
|
222
|
+
Although generally not recommended, it is sometimes necessary to peek at a treatment or variable without triggering an exposure.
|
|
223
|
+
The A/B Smartly SDK provides a `peek_treament()` method for that.
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
res = context.peek_treamnet("exp_test_experiment")
|
|
227
|
+
if res == 0:
|
|
228
|
+
# user is in control group (variant 0)
|
|
229
|
+
else:
|
|
230
|
+
# user is in treatment group
|
|
231
|
+
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
##### Peeking at variables
|
|
235
|
+
```python
|
|
236
|
+
variable = context.peek_variable("my_variable")
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
#### Overriding treatment variants
|
|
240
|
+
During development, for example, it is useful to force a treatment for an experiment. This can be achieved with the `override()` and/or `overrides()` methods.
|
|
241
|
+
The `set_override()` and `set_overrides()` methods can be called before the context is ready.
|
|
242
|
+
```python
|
|
243
|
+
context.set_override("exp_test_experiment", 1) # force variant 1 of treatment
|
|
244
|
+
context.set_overrides({
|
|
245
|
+
"exp_test_experiment": 1,
|
|
246
|
+
"exp_another_experiment": 0
|
|
247
|
+
})
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
## About A/B Smartly
|
|
251
|
+
**A/B Smartly** is the leading provider of state-of-the-art, on-premises, full-stack experimentation platforms for engineering and product teams that want to confidently deploy features as fast as they can develop them.
|
|
252
|
+
A/B Smartly's real-time analytics helps engineering and product teams ensure that new features will improve the customer experience without breaking or degrading performance and/or business metrics.
|
|
253
|
+
|
|
254
|
+
### Have a look at our growing list of clients and SDKs:
|
|
255
|
+
- [Java SDK](https://www.github.com/absmartly/java-sdk)
|
|
256
|
+
- [JavaScript SDK](https://www.github.com/absmartly/javascript-sdk)
|
|
257
|
+
- [PHP SDK](https://www.github.com/absmartly/php-sdk)
|
|
258
|
+
- [Swift SDK](https://www.github.com/absmartly/swift-sdk)
|
|
259
|
+
- [Vue2 SDK](https://www.github.com/absmartly/vue2-sdk)
|
|
260
|
+
- [Go SDK](https://www.github.com/absmartly/go-sdk)
|
|
261
|
+
- [Ruby SDK](https://www.github.com/absmartly/ruby-sdk)
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
sdk/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
sdk/absmarly.py,sha256=TsNycohd4DcJU_7prmYi_Gnn_RacqNxnkMEolNlgDm4,2852
|
|
3
|
+
sdk/absmartly_config.py,sha256=R2sQ2c9LpncGT3FsRs7uFeH5GKWVzjjHCpfUT-T-L9s,706
|
|
4
|
+
sdk/audience_deserializer.py,sha256=ZWsUL9pdLLRmTqkbQT7HOso4O0U-WfGHtTe9AKWhwsE,290
|
|
5
|
+
sdk/audience_matcher.py,sha256=lLqZcqGytL9-FzSOCw2G7uNxOV4NOljlSAShnSqcAvQ,1083
|
|
6
|
+
sdk/client.py,sha256=EzHh1la84XiDKK14wKWLR2sdBzihUX9RY6CcZn83bns,2052
|
|
7
|
+
sdk/client_config.py,sha256=-veoD7VokVxRZIAS7EOctzRnLNsPS0WfzGW7ylcFNQA,704
|
|
8
|
+
sdk/context.py,sha256=upPvFx1xOOFMM4_xOEvZOvtLBvLGuOD_nKuHx8T6-4A,29012
|
|
9
|
+
sdk/context_config.py,sha256=3TONztXlxDxEgjdG0YCGKgQxeCcyzhmR9J1wfbP9Mt0,332
|
|
10
|
+
sdk/context_data_deserializer.py,sha256=uNANbShE6AVqPKyQDo2JpC8O0AzSZJ5DfCySqQS5w40,313
|
|
11
|
+
sdk/context_data_provider.py,sha256=ywJTbDmdjsnFUKfm_zkCMHOaI2dQCOEVLlfCLAUvA6I,293
|
|
12
|
+
sdk/context_event_handler.py,sha256=_VXQ21bgO4j2QHQYWqv5QdBAW1P6nZF7SuezEqdebl4,376
|
|
13
|
+
sdk/context_event_logger.py,sha256=DnadySTIXFd6MXMdQz1xvZ_YEvSzrlPNPMe3RHp2pFM,378
|
|
14
|
+
sdk/context_event_serializer.py,sha256=_UYXXUPCWPC8fDMLVMs6i68p9VMMdIB1GGwuI80bvCA,234
|
|
15
|
+
sdk/default_audience_deserializer.py,sha256=0Le8rMVjeBdL8LH_YKeVahHo8ZpGT6pQ772eXbkOk5U,465
|
|
16
|
+
sdk/default_context_data_deserializer.py,sha256=ejGHpQRIZjbg6GzlWG_ap-B7JwoOcnY_7kdyQwo1IDU,538
|
|
17
|
+
sdk/default_context_data_provider.py,sha256=-aHqS16MfzubPNbTzhHhBVlJiQC3bfJ0eEsKAAbKVL8,440
|
|
18
|
+
sdk/default_context_event_handler.py,sha256=6BRp2NOyZ8p1af2oYgeza1QhmCpNqIYOGoZJrdn0oZk,578
|
|
19
|
+
sdk/default_context_event_serializer.py,sha256=xtMb4a4gilXgWYyYJKiLKy7ZcpLAdR5y9rrD345B28o,378
|
|
20
|
+
sdk/default_http_client.py,sha256=EwFwaoY4KVnmHGx-LbDDpbuNF6c3S3KxRHDIpr7DP0k,2579
|
|
21
|
+
sdk/default_http_client_config.py,sha256=BO3_3a_SZM_B9nfmJUXIeMjHSTroTU8LMADmjMBjJ2k,209
|
|
22
|
+
sdk/default_variable_parser.py,sha256=B3p6sEh5691zBK8CF6f2GBC0idskbHpmuDHsz8cABuw,495
|
|
23
|
+
sdk/http_client.py,sha256=Z0emh_gcVOQd1MiIQMlew_QcXSN3sfRAcmJ-IVvIOVM,634
|
|
24
|
+
sdk/variable_parser.py,sha256=D4Nc1P_Bzo4DmvUCu_7Lzl7FblbYHimCa88BGxK6HdU,304
|
|
25
|
+
sdk/internal/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
|
+
sdk/internal/buffers.py,sha256=IbGEXqe0I5OzZ7QXyBXNGIg6ZF7LFmzR006tvNi2GT4,795
|
|
27
|
+
sdk/internal/murmur32.py,sha256=V7DrTVtLHcgF4Pjs-ZfNXlwCKS2EHEphYxtNHdN60UU,1781
|
|
28
|
+
sdk/internal/variant_assigner.py,sha256=LsE9jvBNcC_XIlpJCoj_Jz8uuCaA_UYmw1ANNjsBnBU,1084
|
|
29
|
+
sdk/internal/lock/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
30
|
+
sdk/internal/lock/atomic_bool.py,sha256=9tsWfz0Dmu3HjRF-LdIsSicmC7w7UrU_t4WN0jnnR8o,457
|
|
31
|
+
sdk/internal/lock/atomic_int.py,sha256=rq9yRmNHRQOMI-UTO6z0Dz1F9jnhTC9b8Bhcuu9i260,488
|
|
32
|
+
sdk/internal/lock/concurrency.py,sha256=hDwnY7NPFPbru_vBXAt0E-mMT-2OUPOEHCvP7gexgus,1472
|
|
33
|
+
sdk/internal/lock/read_write_lock.py,sha256=pE1Y5OkiXxbGRQ1o1CIhtuCp238DS28KbCHBs8gEVts,688
|
|
34
|
+
sdk/json/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
35
|
+
sdk/json/attribute.py,sha256=CNnCVAu82ESdSVBk9xJyLQGjDgBLPTh_BocjeABz3kY,121
|
|
36
|
+
sdk/json/context_data.py,sha256=8uHeUX0C9tdDzSZkz7Cc7JuBm6rsnYsNNAf6hTOTYgM,137
|
|
37
|
+
sdk/json/experiement_application.py,sha256=YN_ypTW1sVb5eUs12elHpH7UbLRIl7ZxelC5UugCATU,83
|
|
38
|
+
sdk/json/experiment.py,sha256=9c4LZYFC93LXB74P_8_qZVuTMJ5Fm1PXwX1BAQiDVYw,844
|
|
39
|
+
sdk/json/experiment_variant.py,sha256=iXQycLk81wNpYeN8GiEm77OE1A8tRT1-OrLgyh0LLyo,119
|
|
40
|
+
sdk/json/exposure.py,sha256=vB7xPAp-GRrYj0OjhZ19k2mT3-vT-VH2cuK2Q3i26tM,489
|
|
41
|
+
sdk/json/goal_achievement.py,sha256=LC7jNKytiPrUammB1vrRuBd6uqwLzL2dp0gBQwh9ApE,137
|
|
42
|
+
sdk/json/publish_event.py,sha256=c8eBD3ocbH2sCqM6nHOnBGs8UDa3PCP5MFcDQtLX7ro,499
|
|
43
|
+
sdk/json/unit.py,sha256=v_UFXKpvgyMIktMg9EP3NqkYyDFltyjqJlelAhW3mQE,103
|
|
44
|
+
sdk/jsonexpr/evaluator.py,sha256=v-_KclKzEcH4sdViRB7SwjOPN1pYR-EscmJAUfS6Mis,719
|
|
45
|
+
sdk/jsonexpr/expr_evaluator.py,sha256=o_QoiNR6wltZ6X3EfiNi2hQVk_yO_Otxm-wv-bHzFjo,3252
|
|
46
|
+
sdk/jsonexpr/json_expr.py,sha256=9jq7RfPBK3YGrjYE1_PsRTxaRQbwYdGWnBjJrt9DXu4,1770
|
|
47
|
+
sdk/jsonexpr/operator.py,sha256=vH--qkdPGCXBPwGDCrkZVvwWoyydqmRPvp0e5PEbtN0,210
|
|
48
|
+
sdk/jsonexpr/operators/and_combinator.py,sha256=_FiO3R37P_Gb0KdP_uao36FCWzLc4lS5EyGDzTGwk4E,366
|
|
49
|
+
sdk/jsonexpr/operators/binary_operator.py,sha256=xvKY7R1g_9vm8_tMQ9mxYvVvsliDhNgsJPAU3nsBQK4,668
|
|
50
|
+
sdk/jsonexpr/operators/boolean_combinator.py,sha256=QptWQ5yN-de5xT2jUct0pvRlR1je1U6NYehzbnEu8xI,448
|
|
51
|
+
sdk/jsonexpr/operators/equals_operator.py,sha256=XEIlS3juE1-hxW_9j6Wj1N0ICWLOB83p4hR34y4hmMI,366
|
|
52
|
+
sdk/jsonexpr/operators/greater_than_operator.py,sha256=x4bB7EhVY3g_sRawBBNCSJHOubQ-kG1G1l-pu2f7InM,329
|
|
53
|
+
sdk/jsonexpr/operators/greater_than_or_equal_operator.py,sha256=Kc2KaPq59xZ-qNbWDFjluoLBeOJYdBGo3Em44j5YyRY,337
|
|
54
|
+
sdk/jsonexpr/operators/in_operator.py,sha256=32y6NTlVQPmAXgDK34GL5Ff7s3UhnW2nMlfBYFRsfxA,635
|
|
55
|
+
sdk/jsonexpr/operators/less_than_operator.py,sha256=zfylm190ACoKHoAYHnj6ItG6UbWd83uwckknt991Me0,326
|
|
56
|
+
sdk/jsonexpr/operators/less_than_or_equal_operator.py,sha256=2EANR03NPFFypdBNIYDhiKYR7ML2YpzeN8U0EXc3CfE,335
|
|
57
|
+
sdk/jsonexpr/operators/match_operator.py,sha256=ish9ENwVTWiqZYJgV8BmANytNOUIXH3qu-JRGda9xn4,510
|
|
58
|
+
sdk/jsonexpr/operators/not_operator.py,sha256=Q_6-fFBzKZaO-gzTMnWJ3zUVFoUSbu_ibRQ5Bh3IiIE,298
|
|
59
|
+
sdk/jsonexpr/operators/null_operator.py,sha256=aL4mZji3ob3ncg9Xp-t6k4UByiow3CO4N4bYm3jael0,229
|
|
60
|
+
sdk/jsonexpr/operators/or_combinator.py,sha256=XnC9EnOacNZhWFHEF3CGeMHcZSn9RBD4SeYzlio0UGM,367
|
|
61
|
+
sdk/jsonexpr/operators/unary_operator.py,sha256=5tP_votU5WHwmA1lgKhjBj-5gpKzd_THJfEDBfNJ3eo,405
|
|
62
|
+
sdk/jsonexpr/operators/value_operator.py,sha256=_z1F1FZR1tBeM2vSliaWO7SpkyppzPbrP7GWk36GhU4,203
|
|
63
|
+
sdk/jsonexpr/operators/var_operator.py,sha256=7fMJKXk5Luceif1729EAmYThw20VjVc6vYjwb-plb6M,401
|
|
64
|
+
sdk/time/clock.py,sha256=CN38j_SELxYyokl28lHnNr8N0T0TeCsGd6IKrDSwo6A,123
|
|
65
|
+
sdk/time/fixed_clock.py,sha256=ZJwVGL5YMiaQO6b4dzZSCo2aFLIFc3hD5gFgEjDZXYs,174
|
|
66
|
+
sdk/time/system_clock_utc.py,sha256=gOaNiFP_IsxCXVj2lX38Ih5UAMMLTjsJxXNJWFQ6VzM,155
|
|
67
|
+
absmartly-0.1.2.dist-info/LICENSE,sha256=j53v47_mQxYWiYmDDUB5OlB08lqLE_O7iwk5FKfCf3M,1091
|
|
68
|
+
absmartly-0.1.2.dist-info/METADATA,sha256=xZMrips-cNV95iy9zP343Go076NYRfykPA4t1GIaErw,10339
|
|
69
|
+
absmartly-0.1.2.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
|
70
|
+
absmartly-0.1.2.dist-info/top_level.txt,sha256=JuXS55gRP3EzGKmJgbLfVfUolO3cM_u69k3qvutnBuw,4
|
|
71
|
+
absmartly-0.1.2.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sdk
|
sdk/__init__.py
ADDED
|
File without changes
|
sdk/absmarly.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from concurrent.futures import Future
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from sdk.absmartly_config import ABSmartlyConfig
|
|
5
|
+
from sdk.audience_matcher import AudienceMatcher
|
|
6
|
+
from sdk.context import Context
|
|
7
|
+
from sdk.context_config import ContextConfig
|
|
8
|
+
from sdk.default_audience_deserializer import DefaultAudienceDeserializer
|
|
9
|
+
from sdk.default_context_data_provider import DefaultContextDataProvider
|
|
10
|
+
from sdk.default_context_event_handler import DefaultContextEventHandler
|
|
11
|
+
from sdk.default_variable_parser import DefaultVariableParser
|
|
12
|
+
from sdk.json.context_data import ContextData
|
|
13
|
+
from sdk.time.system_clock_utc import SystemClockUTC
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class ABSmartly:
|
|
17
|
+
|
|
18
|
+
def __init__(self, config: ABSmartlyConfig):
|
|
19
|
+
self.context_data_provider = config.context_data_provider
|
|
20
|
+
self.context_event_handler = config.context_event_handler
|
|
21
|
+
self.context_event_logger = config.context_event_logger
|
|
22
|
+
self.variable_parser = config.variable_parser
|
|
23
|
+
self.audience_deserializer = config.audience_deserializer
|
|
24
|
+
|
|
25
|
+
if self.context_data_provider is None or \
|
|
26
|
+
self.context_event_handler is None:
|
|
27
|
+
self.client = config.client
|
|
28
|
+
|
|
29
|
+
if self.context_data_provider is None:
|
|
30
|
+
self.context_data_provider = \
|
|
31
|
+
DefaultContextDataProvider(self.client)
|
|
32
|
+
|
|
33
|
+
if self.context_event_handler is None:
|
|
34
|
+
self.context_event_handler = \
|
|
35
|
+
DefaultContextEventHandler(self.client)
|
|
36
|
+
|
|
37
|
+
if self.variable_parser is None:
|
|
38
|
+
self.variable_parser = DefaultVariableParser()
|
|
39
|
+
|
|
40
|
+
if self.audience_deserializer is None:
|
|
41
|
+
self.audience_deserializer = DefaultAudienceDeserializer()
|
|
42
|
+
|
|
43
|
+
def get_context_data(self) -> Future[Optional[ContextData]]:
|
|
44
|
+
return self.context_data_provider.get_context_data()
|
|
45
|
+
|
|
46
|
+
def create_context(self, config: ContextConfig) -> Context:
|
|
47
|
+
return Context(SystemClockUTC(),
|
|
48
|
+
config,
|
|
49
|
+
self.context_data_provider.get_context_data(),
|
|
50
|
+
self.context_data_provider,
|
|
51
|
+
self.context_event_handler,
|
|
52
|
+
self.context_event_logger,
|
|
53
|
+
self.variable_parser,
|
|
54
|
+
AudienceMatcher(self.audience_deserializer))
|
|
55
|
+
|
|
56
|
+
def create_context_with(self,
|
|
57
|
+
config: ContextConfig,
|
|
58
|
+
data: ContextData) -> Context:
|
|
59
|
+
future_data = Future()
|
|
60
|
+
future_data.set_result(data)
|
|
61
|
+
return Context(SystemClockUTC(), config,
|
|
62
|
+
future_data,
|
|
63
|
+
self.context_data_provider,
|
|
64
|
+
self.context_event_handler,
|
|
65
|
+
self.context_event_logger,
|
|
66
|
+
self.variable_parser,
|
|
67
|
+
AudienceMatcher(self.audience_deserializer))
|
sdk/absmartly_config.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from sdk.audience_deserializer import AudienceDeserializer
|
|
4
|
+
from sdk.client import Client
|
|
5
|
+
from sdk.context_data_provider import ContextDataProvider
|
|
6
|
+
from sdk.context_event_handler import ContextEventHandler
|
|
7
|
+
from sdk.context_event_logger import ContextEventLogger
|
|
8
|
+
from sdk.variable_parser import VariableParser
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ABSmartlyConfig:
|
|
12
|
+
context_data_provider: Optional[ContextDataProvider] = None
|
|
13
|
+
context_event_handler: Optional[ContextEventHandler] = None
|
|
14
|
+
context_event_logger: Optional[ContextEventLogger] = None
|
|
15
|
+
audience_deserializer: Optional[AudienceDeserializer] = None
|
|
16
|
+
client: Optional[Client] = None
|
|
17
|
+
variable_parser: Optional[VariableParser] = None
|
sdk/audience_matcher.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from sdk.audience_deserializer import AudienceDeserializer
|
|
4
|
+
from sdk.jsonexpr.json_expr import JsonExpr
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Result:
|
|
8
|
+
def __init__(self, result: bool):
|
|
9
|
+
self.result = result
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class AudienceMatcher:
|
|
13
|
+
|
|
14
|
+
def __init__(self, deserializer: AudienceDeserializer):
|
|
15
|
+
self.deserializer = deserializer
|
|
16
|
+
self.json_expr = JsonExpr()
|
|
17
|
+
|
|
18
|
+
def evaluate(self, audience: str, attributes: dict) -> Optional[Result]:
|
|
19
|
+
bytes_arr = bytes(audience, encoding="utf-8")
|
|
20
|
+
audience_map = self.deserializer.deserialize(bytes_arr,
|
|
21
|
+
0,
|
|
22
|
+
len(bytes_arr))
|
|
23
|
+
if audience_map is not None:
|
|
24
|
+
if "filter" in audience_map:
|
|
25
|
+
fl = audience_map["filter"]
|
|
26
|
+
if type(fl) is dict or type(fl) is list:
|
|
27
|
+
expr = self.json_expr.evaluate_boolean_expr(fl,
|
|
28
|
+
attributes)
|
|
29
|
+
return Result(expr)
|
|
30
|
+
|
|
31
|
+
return None
|
sdk/client.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from sdk.client_config import ClientConfig
|
|
2
|
+
from sdk.http_client import HTTPClient
|
|
3
|
+
from sdk.json.publish_event import PublishEvent
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Client:
|
|
7
|
+
|
|
8
|
+
def __init__(self, config: ClientConfig, http_client: HTTPClient):
|
|
9
|
+
self.serializer = config.serializer
|
|
10
|
+
self.deserializer = config.deserializer
|
|
11
|
+
self.executor = config.executor
|
|
12
|
+
endpoint = config.endpoint
|
|
13
|
+
api_key = config.api_key
|
|
14
|
+
application = config.application
|
|
15
|
+
environment = config.environment
|
|
16
|
+
|
|
17
|
+
self.url = endpoint + "/context"
|
|
18
|
+
self.http_client = http_client
|
|
19
|
+
|
|
20
|
+
self.headers = {"X-API-Key": api_key,
|
|
21
|
+
"X-Application": application,
|
|
22
|
+
"X-Environment": environment,
|
|
23
|
+
"X-Application-Version": '0',
|
|
24
|
+
"X-Agent": "absmartly-python-sdk"}
|
|
25
|
+
self.query = {"application": application,
|
|
26
|
+
"environment": environment}
|
|
27
|
+
|
|
28
|
+
def get_context_data(self):
|
|
29
|
+
return self.executor.submit(self.send_get, self.url, self.query, {})
|
|
30
|
+
|
|
31
|
+
def send_get(self, url: str, query: dict, headers: dict):
|
|
32
|
+
response = self.http_client.get(url, query, headers)
|
|
33
|
+
if response.status_code // 100 == 2:
|
|
34
|
+
content = response.content
|
|
35
|
+
return self.deserializer.deserialize(content, 0, len(content))
|
|
36
|
+
return response.raise_for_status()
|
|
37
|
+
|
|
38
|
+
def publish(self, event: PublishEvent):
|
|
39
|
+
return self.executor.submit(
|
|
40
|
+
self.send_put,
|
|
41
|
+
self.url,
|
|
42
|
+
{},
|
|
43
|
+
self.headers,
|
|
44
|
+
event)
|
|
45
|
+
|
|
46
|
+
def send_put(self,
|
|
47
|
+
url: str,
|
|
48
|
+
query: dict,
|
|
49
|
+
headers: dict,
|
|
50
|
+
event: PublishEvent):
|
|
51
|
+
content = self.serializer.serialize(event)
|
|
52
|
+
response = self.http_client.put(url, query, headers, content)
|
|
53
|
+
if response.status_code // 100 == 2:
|
|
54
|
+
content = response.content
|
|
55
|
+
return self.deserializer.deserialize(content, 0, len(content))
|
|
56
|
+
return response.raise_for_status()
|
sdk/client_config.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
3
|
+
|
|
4
|
+
from sdk.default_context_data_deserializer import \
|
|
5
|
+
DefaultContextDataDeserializer
|
|
6
|
+
from sdk.default_context_event_serializer import \
|
|
7
|
+
DefaultContextEventSerializer
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ClientConfig:
|
|
11
|
+
def __init__(self, prefix=""):
|
|
12
|
+
self.executor = ThreadPoolExecutor()
|
|
13
|
+
self.endpoint = os.environ.get(prefix + "endpoint")
|
|
14
|
+
self.environment = os.environ.get(prefix + "environment")
|
|
15
|
+
self.application = os.environ.get(prefix + "application")
|
|
16
|
+
self.api_key = os.environ.get(prefix + "api_key")
|
|
17
|
+
self.serializer = DefaultContextEventSerializer()
|
|
18
|
+
self.deserializer = DefaultContextDataDeserializer()
|