Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
280d1c4
[wip] Added polling support + indirect messages in streaming. Both po…
Jun 28, 2016
02b7f2d
[wip] Added polling support + indirect messages in streaming. Both po…
Jun 29, 2016
c4501cd
cleanup
Jun 30, 2016
ce05217
polling client no longer drifts.
Jun 30, 2016
2b74410
cleanup
Jun 30, 2016
22382ed
Remove commented code. Fix some documentation
Jun 30, 2016
9e9fe54
Move offline to config so it is set once during initialization and on…
Jun 30, 2016
222f981
Add log statements when returning default
Jun 30, 2016
ea76873
Rename
Jul 1, 2016
f29e2a0
Rename and move some things.
Jul 1, 2016
c34a29f
Rename some config params. Add Redis feature store + tests
Jul 2, 2016
d8ae8aa
update some redis-related things
Jul 2, 2016
b6b4151
Add wait loop at start
Jul 2, 2016
40f5443
clean up uris, etc
Jul 2, 2016
110499f
Rename more things. Remove some outdated twisted impls.
Jul 2, 2016
52073d8
Change client init logic to handle LDD mode. Make other things more c…
Jul 3, 2016
328a9eb
Add debug logging
Jul 3, 2016
b694fe6
Add debug logging
Jul 3, 2016
e0e9fae
Update deps
Jul 3, 2016
249162f
bump version. Add more debug logging.
Jul 3, 2016
567baed
temporary- make inmem feature store look like master
Jul 3, 2016
5fb3f59
fix bad import
Jul 3, 2016
79a6b1c
Revert
Jul 3, 2016
40c1e26
Change feature store so it lives in config
Jul 3, 2016
8510837
Remove startup wait.
Jul 3, 2016
a429301
add log statements
Jul 3, 2016
778ec2e
move feature store init
Jul 4, 2016
50b1e73
more logging
Jul 4, 2016
d85ccba
maybe
Jul 4, 2016
23547c1
Revert some things that didn't work.
Jul 4, 2016
7110730
Attempt to make event consumer behavior more consistent. temporarily …
Jul 4, 2016
4c819c5
Bump version. Rename some things.
Jul 5, 2016
ab4929c
Add start_wait.
Jul 6, 2016
4e32f00
add future
Jul 6, 2016
62ceb43
cahnge log statement.
Jul 6, 2016
739ccb1
Make python 3 happy.
Jul 6, 2016
0596d50
Make python 3 happy.
Jul 6, 2016
1350833
Start polling processor for real this time
Jul 6, 2016
f2cb7a3
Update readme
Jul 6, 2016
9c23fc4
Change redis feature store to take url
Jul 6, 2016
467ad4e
always set a feature store
Jul 6, 2016
605fb13
Address PR comments. Fix weird formatting in test file.
Jul 7, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ Development information (for developing this module itself)
pip install -r test-requirements.txt
pip install -r twisted-requirements.txt

1. Run tests:
1. Run tests: You'll need redis running locally on its default port of 6379.

$ py.test testing
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ Quick setup

pip install ldclient-py

2. Create a new LDClient with your API key:
2. Configure the library with your api key:

client = LDClient("your_api_key")
import ldclient
ldclient.api_key = "your api key"

3. Get the client:

client = ldclient.get()

Your first feature flag
-----------------------
Expand Down
3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
machine:
services:
- redis
dependencies:
pre:
- pyenv shell 2.7.10; $(pyenv which pip) install --upgrade pip setuptools
Expand Down
26 changes: 22 additions & 4 deletions demo/demo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
from __future__ import print_function
from ldclient import LDClient

import logging
import sys

import ldclient

root = logging.getLogger()
root.setLevel(logging.DEBUG)

ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
root.addHandler(ch)

if __name__ == '__main__':
apiKey = 'feefifofum'
client = LDClient(apiKey)
print(client.api_key)
ldclient._api_key = 'api_key'
ldclient.start_wait = 10
client = ldclient.get()

user = {u'key': 'userKey'}
print(client.toggle("update-app", user, False))

client.close()
34 changes: 32 additions & 2 deletions ldclient/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from .client import *
import logging

from ldclient.rwlock import ReadWriteLock
from ldclient.version import VERSION
from .client import *
from .util import log
import logging

__version__ = VERSION

Expand All @@ -11,6 +13,34 @@
"firstName", "lastName", "avatar", "name", "anonymous"]


"""Settings."""
client = None
api_key = None
start_wait = 5
config = Config()

_lock = ReadWriteLock()


def get():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This follows the model used by segment to enforce the singleton pattern. See updated readme + restwrapper PR: https://github.com/launchdarkly/python-restwrapper/pull/1/files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added double-check locking. Please run through how this can break.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me.

try:
_lock.rlock()
if client:
return client
finally:
_lock.runlock()

try:
global client
_lock.lock()
if not client:
log.debug("Initializing LaunchDarkly Client")
client = LDClient(api_key, config, start_wait)
return client
finally:
_lock.unlock()


# Add a NullHandler for Python < 2.7 compatibility
class NullHandler(logging.Handler):

Expand Down
Loading