Skip to content

Commit

Permalink
Update documentation and clean up some old dependencies. (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanklee86 authored Apr 7, 2023
1 parent 1fcedbf commit 1018068
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v5.6.0
* (Major) Add support for event callbacks.

## v5.5.0
* (Minor) SDK now warns when multiple instances are created
* (Bugfix) Fix an issue where the NOT_IN operator behaves incorrectly when inverted and no context is passed

## v5.4.1
* (Bugfix) Fix an issue where custom stickiness fail to calculate correctly
* (Bugfix) Fix floats not working correctly in constraints
Expand Down
5 changes: 4 additions & 1 deletion UnleashClient/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class BaseCache(abc.ABC):
"""
Abstract base class for caches used for UnleashClient.
If implementing your own bootstrapping methods, you must set the `bootstrapped` attribute to True after configuration is set.
If implementing your own bootstrapping methods:
- Add your custom bootstrap method.
- You must set the `bootstrapped` attribute to True after configuration is set.
"""
bootstrapped = False

Expand Down
6 changes: 6 additions & 0 deletions UnleashClient/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@


class UnleashEventType(Enum):
"""
Indicates what kind of event was triggered.
"""
FEATURE_FLAG = "feature_flag"
VARIANT = "variant"


@dataclass
class UnleashEvent:
"""
Dataclass capturing information from an Unleash feature flag or variant check.
"""
event_type: UnleashEventType
event_id: UUID
context: dict
Expand Down
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"sphinx.ext.autosectionlabel",
"sphinx.ext.autosummary",
"sphinx.ext.githubpages",
"m2r2"
"m2r2",
"enum_tools.autoenum"
]

# Add any paths that contain templates here, relative to this directory.
Expand Down
2 changes: 1 addition & 1 deletion docs/customcache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Implementing a custom cache
#######################################

- Create a custom cache object by sub-classing the BaseCache object.
- Overwrite all the methods from the base class.
- Overwrite all the methods from the base class. You can also add custom bootstraping methods!

.. code-block:: python
Expand Down
35 changes: 35 additions & 0 deletions docs/eventcallbacks.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
****************************************
Event Callbacks
****************************************

The Unleash Python client support event callbacks!

1. Create a function with the type `Callable[[UnleashEvent]]` and pass it to the Unleash client at initialization.
2. Enable `impression data <https://docs.getunleash.io/reference/impression-data#enabling-impression-data>`_ on feature flag configuration.

Example code using `blinker <https://github.com/pallets-eco/blinker>`_:

.. code-block:: python
from blinker import ignal
from UnleashClient import UnleashClient
from UnleashClient.events import UnleashEvent
send_data = signal('send-data')
@send_data.connect
def receive_data(sender, **kw):
print("Caught signal from %r, data %r" % (sender, kw))
return kw
def example_callback(event: UnleashEvent):
send_data.send('anonymous', data=event)
# Set up Unleash
client = UnleashClient(
"https://unleash.herokuapp.com/api",
"My Program"
event_callback=example_callback
)
client.initialize_client()
client.is_enabled("testFlag")
2 changes: 2 additions & 0 deletions docs/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
Events
****************************************

.. autoenum :: UnleashClient.events.UnleashEventType
.. autoclass:: UnleashClient.events.UnleashEvent
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Documentation for Unleash's Python client. See the sidebar for more topics!

customstrategies
customcache
eventcallbacks
development
wsgi
celery
Expand Down
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ python-dateutil
semver

# Development packages
bumpversion
coveralls
mimesis
mkdocs
mypy
pur
pylint
pytest
pytest-cov
Expand All @@ -32,3 +29,4 @@ tox
types-requests
twine
blinker
enum-tools[sphinx]

0 comments on commit 1018068

Please sign in to comment.