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
Copy file name to clipboardExpand all lines: Detailed-README.md
+114Lines changed: 114 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,120 @@ The following snippet shows you how to create a basic client using the default c
32
32
'SOME_TREATMENT'
33
33
```
34
34
35
+
## Logging
36
+
Split SDK uses logging module from Python.
37
+
38
+
### Logging sample
39
+
```python
40
+
import logging
41
+
logging.basicConfig(level=logging.DEBUG)
42
+
```
43
+
44
+
## Cache
45
+
Split SDK depends on the popular [redis-py](https://github.com/andymccurdy/redis-py) library.
46
+
47
+
### Cache Adapter
48
+
The redis-py library is supported as the python interface to the Redis key-value store. This library uses a connection pool to manage connections to a Redis server. For further information about how to configure the ```redis-py``` client, please take a look on [redis-py official docs](https://github.com/andymccurdy/redis-py)
49
+
50
+
For ```redis``` and their dependencies such as ```jsonpickle``` you can use ```pip``` running the command ```pip install splitio_client[redis,cpphash]==5.5.0```
51
+
52
+
#### Provided redis-py connection - sample code
53
+
```python
54
+
#Default imports
55
+
from__future__import print_function
56
+
57
+
import sys
58
+
59
+
from splitio import get_factory
60
+
from splitio.exceptions import TimeoutException
61
+
62
+
# redis-py options
63
+
'''The options below, will be loaded as:
64
+
r = redis.StrictRedis(host='localhost', port=6379, db=0, prefix='')
65
+
'''
66
+
config = {
67
+
'redisDb' : 0,
68
+
'redisHost' : 'localhost',
69
+
'redisPosrt': 6379,
70
+
'redisPrefix': ''
71
+
}
72
+
73
+
# Create the Split Client instance.
74
+
try:
75
+
factory = get_factory('API_KEY', config=config)
76
+
split = factory.client()
77
+
except TimeoutException:
78
+
sys.exit()
79
+
```
80
+
81
+
#### Provided redis-py connection - sample code for Sentinel Support
Split SDKs send impression data back to Split servers periodically and as a result of evaluating splits. In order to additionally send this information to a location of your choice, you could define and attach an Impression Listener. For that purpose, SDK's options have a parameter called `impressionListener` where an implementation of `ImpressionListener` could be added. This implementation **must** define the `log_impression` method and it will receive data in the following schema:
115
+
116
+
| Name | Type | Description |
117
+
| --- | --- | --- |
118
+
| impression | Impression | Impression object that has the feature_name, treatment result, label, etc. |
119
+
| attributes | Array | A list of attributes passed by the client. |
120
+
| instance-id | String | Corresponds to the IP of the machine where the SDK is running. |
121
+
| sdk-language-version | String | Indicates the version of the sdk. In this case the language will be python plus the version of it. |
122
+
123
+
### Implementing custom Impression Listener
124
+
Below you could find an example of how implement a custom Impression Listener:
125
+
```python
126
+
# Import ImpressionListener interface
127
+
from splitio.impressions import ImpressionListener
128
+
129
+
# Implementation Sample for a Custom Impression Listener
130
+
classCustomImpressionListener(ImpressionListener)
131
+
{
132
+
deflog_impression(self, data):
133
+
# Custom behavior
134
+
}
135
+
```
136
+
137
+
### Attaching custom Impression Listener
138
+
```python
139
+
factory = get_factory(
140
+
'YOUR_API_KEY',
141
+
config={
142
+
# ...
143
+
'impressionListener': CustomImpressionListener()
144
+
},
145
+
# ...
146
+
)
147
+
split = factory.client()
148
+
35
149
## Additional information
36
150
37
151
You can get more information on how to use this package in the included documentation.
0 commit comments