Skip to content

Commit 74bbc18

Browse files
authored
Merge pull request keenlabs#122 from keenlabs/jm_DocBugs
Fix up some documentation bugs.
2 parents fbe6c46 + 9692c54 commit 74bbc18

File tree

3 files changed

+71
-42
lines changed

3 files changed

+71
-42
lines changed

README.rst

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ keys (if you need an account, `sign up here <https://keen.io/>`_ - it's free).
3030
Setting a write key is required for publishing events. Setting a read key is required for
3131
running queries. The recommended way to set this configuration information is via the environment.
3232
The keys you can set are `KEEN_PROJECT_ID`, `KEEN_WRITE_KEY`, `KEEN_READ_KEY`, and `KEEN_MASTER_KEY`.
33+
As per the `Principle of Least Privilege <https://en.wikipedia.org/wiki/Principle_of_least_privilege>`_, it's recommended that you not use the master_key if not
34+
necessary. This SDK will expect and use the precise key for a given operation, and throw an
35+
exception in cases of misuse.
3336

3437
If you don't want to use environment variables for some reason, you can directly set values as follows:
3538

@@ -38,7 +41,7 @@ If you don't want to use environment variables for some reason, you can directly
3841
keen.project_id = "xxxx"
3942
keen.write_key = "yyyy"
4043
keen.read_key = "zzzz"
41-
keen.master_key = "abcd"
44+
keen.master_key = "abcd" # not required for typical usage
4245
4346
4447
For information on how to configure unique client instances, take a look at the
@@ -100,33 +103,35 @@ For more code samples, take a look at Keen's `docs <https://keen.io/docs/api/?py
100103
101104
keen.extraction("purchases", timeframe="today") # => [{ "price" => 20, ... }, { ... }]
102105
103-
keen.multi_analysis("purchases", analyses={
104-
"total":{
105-
"analysis_type": "sum",
106-
"target_property":"price",
107-
"timeframe": "this_14_days"
106+
keen.multi_analysis(
107+
"purchases",
108+
analyses={
109+
"total":{
110+
"analysis_type": "sum",
111+
"target_property": "price"
112+
},
113+
"average":{
114+
"analysis_type": "average",
115+
"target_property": "price"
116+
}
108117
},
109-
"average":{
110-
"analysis_type": "average",
111-
"target_property":"price",
112-
"timeframe": "this_14_days"
113-
}
118+
timeframe='this_14_days'
114119
) # => {"total":10329.03, "average":933.93}
115120
116121
step1 = {
117-
"event_collection": "signup",
122+
"event_collection": "sign_ups",
118123
"actor_property": "user.email"
119124
}
120125
step2 = {
121-
"event_collection": "purchase",
126+
"event_collection": "purchases",
122127
"actor_property": "user.email"
123128
}
124129
keen.funnel([step1, step2], timeframe="today") # => [2039, 201]
125130
126131
127132
To return the full API response from a funnel analysis (as opposed to the singular "result" key), set `all_keys=True`.
128133

129-
For example, `keen.funnel([step1, step2], all_keys=True)` would return "result", "actors" and "steps" keys.
134+
For example, `keen.funnel([step1, step2], timeframe="today", all_keys=True)` would return "result", "actors" and "steps" keys.
130135

131136
Delete Events
132137
`````````````
@@ -217,14 +222,14 @@ unique client instances (one per project). You can do this by assigning an insta
217222
project_id="xxxx", # your project ID for collecting cycling data
218223
write_key="yyyy",
219224
read_key="zzzz",
220-
master_key="abcd"
225+
master_key="abcd" # not required for typical usage
221226
)
222227
223228
client_hike = KeenClient(
224229
project_id="xxxx", # your project ID for collecting hiking data (different from the one above)
225230
write_key="yyyy",
226231
read_key="zzzz",
227-
master_key="abcd"
232+
master_key="abcd" # not required for typical usage
228233
)
229234
230235
@@ -249,28 +254,56 @@ Similarly, you can query events like this:
249254
Saved Queries
250255
'''''''''''''
251256

252-
You can manage your saved queries from the Keen python client.
257+
You can manage your `saved queries <https://keen.io/docs/api/?shell#saved-queries>`_ from the Keen python client.
253258

254259
.. code-block:: python
255260
261+
# Create your KeenClient
262+
from keen.client import KeenClient
263+
264+
client = KeenClient(
265+
project_id="xxxx", # your project ID
266+
read_key="zzzz",
267+
master_key="abcd" # Most Saved Query functionality requires master_key
268+
)
269+
256270
# Create a saved query
257-
keen.saved_queries.create("name", saved_query_attributes)
271+
saved_query_attributes = {
272+
# NOTE : For now, refresh_rate must explicitly be set to 0 unless you
273+
# intend to create a Cached Query.
274+
"refresh_rate": 0,
275+
"query": {
276+
"analysis_type": "count",
277+
"event_collection": "purchases",
278+
"timeframe": "this_2_weeks",
279+
"filters": [{
280+
"property_name": "price",
281+
"operator": "gte",
282+
"property_value": 1.00
283+
}]
284+
}
285+
}
286+
client.saved_queries.create("name", saved_query_attributes)
258287
259288
# Get all saved queries
260-
keen.saved_queries.all()
289+
client.saved_queries.all()
261290
262291
# Get one saved query
263-
keen.saved_queries.get("saved-query-slug")
292+
client.saved_queries.get("saved-query-name")
264293
265294
# Get saved query with results
266-
keen.saved_queries.results("saved-query-slug")
295+
client.saved_queries.results("saved-query-name")
296+
297+
# Update a saved query to now be a cached query with the minimum refresh rate of 4 hrs
298+
saved_query_attributes = { "refresh_rate": 14400 }
299+
client.saved_queries.update("saved-query-name", saved_query_attributes)
267300
268-
# Update a saved query
269-
saved_query_attributes = { refresh_rate: 14400 }
270-
keen.saved_queries.update("saved-query-slug", saved_query_attributes)
301+
# Update a saved query to a new resource name
302+
saved_query_attributes = { "query_name": "cached-query-name" }
303+
client.saved_queries.update("saved-query-name", saved_query_attributes)
271304
272-
# Delete a saved query
273-
keen.saved_queries.delete("saved-query-slug")
305+
# Delete a saved query (use the new resource name since we just changed it)
306+
client.saved_queries.delete("cached-query-name")
274307
275308
276309
Overwriting event timestamps
@@ -310,7 +343,6 @@ returned by the server in the specified time. For example:
310343
write_key="yyyy",
311344
read_key="zzzz",
312345
get_timeout=100
313-
314346
)
315347
316348
@@ -332,10 +364,7 @@ returned by the server in the specified time. For example:
332364
client = KeenClient(
333365
project_id="xxxx",
334366
write_key="yyyy",
335-
read_key="zzzz",
336-
master_key="abcd",
337367
post_timeout=100
338-
339368
)
340369
341370
@@ -366,7 +395,7 @@ To run tests:
366395

367396
::
368397

369-
python setup.py tests
398+
python setup.py test
370399

371400

372401
Changelog

keen/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
base_url = None
1313

1414
def _initialize_client_from_environment():
15-
''' Initialize a KeenCLient instance using environment variables. '''
15+
''' Initialize a KeenClient instance using environment variables. '''
1616
global _client, project_id, write_key, read_key, master_key, base_url
1717

1818
if _client is None:

keen/client.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def count(self, event_collection, timeframe=None, timezone=None, interval=None,
228228
:param filters: array of dict, contains the filters you'd like to apply to the data
229229
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
230230
:param group_by: string or array of strings, the name(s) of the properties you would
231-
like to group you results by. example: "customer.id" or ["browser","operating_system"]
231+
like to group your results by. example: "customer.id" or ["browser","operating_system"]
232232
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
233233
willing to trade for increased query performance, in seconds
234234
@@ -254,7 +254,7 @@ def sum(self, event_collection, target_property, timeframe=None, timezone=None,
254254
:param filters: array of dict, contains the filters you'd like to apply to the data
255255
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
256256
:param group_by: string or array of strings, the name(s) of the properties you would
257-
like to group you results by. example: "customer.id" or ["browser","operating_system"]
257+
like to group your results by. example: "customer.id" or ["browser","operating_system"]
258258
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
259259
willing to trade for increased query performance, in seconds
260260
@@ -281,7 +281,7 @@ def minimum(self, event_collection, target_property, timeframe=None, timezone=No
281281
:param filters: array of dict, contains the filters you'd like to apply to the data
282282
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
283283
:param group_by: string or array of strings, the name(s) of the properties you would
284-
like to group you results by. example: "customer.id" or ["browser","operating_system"]
284+
like to group your results by. example: "customer.id" or ["browser","operating_system"]
285285
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
286286
willing to trade for increased query performance, in seconds
287287
@@ -308,7 +308,7 @@ def maximum(self, event_collection, target_property, timeframe=None, timezone=No
308308
:param filters: array of dict, contains the filters you'd like to apply to the data
309309
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
310310
:param group_by: string or array of strings, the name(s) of the properties you would
311-
like to group you results by. example: "customer.id" or ["browser","operating_system"]
311+
like to group your results by. example: "customer.id" or ["browser","operating_system"]
312312
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
313313
willing to trade for increased query performance, in seconds
314314
@@ -335,7 +335,7 @@ def average(self, event_collection, target_property, timeframe=None, timezone=No
335335
:param filters: array of dict, contains the filters you'd like to apply to the data
336336
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
337337
:param group_by: string or array of strings, the name(s) of the properties you would
338-
like to group you results by. example: "customer.id" or ["browser","operating_system"]
338+
like to group your results by. example: "customer.id" or ["browser","operating_system"]
339339
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
340340
willing to trade for increased query performance, in seconds
341341
@@ -362,7 +362,7 @@ def median(self, event_collection, target_property, timeframe=None, timezone=Non
362362
:param filters: array of dict, contains the filters you'd like to apply to the data
363363
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
364364
:param group_by: string or array of strings, the name(s) of the properties you would
365-
like to group you results by. example: "customer.id" or ["browser","operating_system"]
365+
like to group your results by. example: "customer.id" or ["browser","operating_system"]
366366
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
367367
willing to trade for increased query performance, in seconds
368368
@@ -391,7 +391,7 @@ def percentile(self, event_collection, target_property, percentile, timeframe=No
391391
:param filters: array of dict, contains the filters you'd like to apply to the data
392392
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
393393
:param group_by: string or array of strings, the name(s) of the properties you would
394-
like to group you results by. example: "customer.id" or ["browser","operating_system"]
394+
like to group your results by. example: "customer.id" or ["browser","operating_system"]
395395
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
396396
willing to trade for increased query performance, in seconds
397397
@@ -426,7 +426,7 @@ def count_unique(self, event_collection, target_property, timeframe=None, timezo
426426
:param filters: array of dict, contains the filters you'd like to apply to the data
427427
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
428428
:param group_by: string or array of strings, the name(s) of the properties you would
429-
like to group you results by. example: "customer.id" or ["browser","operating_system"]
429+
like to group your results by. example: "customer.id" or ["browser","operating_system"]
430430
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
431431
willing to trade for increased query performance, in seconds
432432
@@ -453,7 +453,7 @@ def select_unique(self, event_collection, target_property, timeframe=None, timez
453453
:param filters: array of dict, contains the filters you'd like to apply to the data
454454
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
455455
:param group_by: string or array of strings, the name(s) of the properties you would
456-
like to group you results by. example: "customer.id" or ["browser","operating_system"]
456+
like to group your results by. example: "customer.id" or ["browser","operating_system"]
457457
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
458458
willing to trade for increased query performance, in seconds
459459
@@ -531,7 +531,7 @@ def multi_analysis(self, event_collection, analyses, timeframe=None, interval=No
531531
:param filters: array of dict, contains the filters you'd like to apply to the data
532532
example: [{"property_name":"device", "operator":"eq", "property_value":"iPhone"}]
533533
:param group_by: string or array of strings, the name(s) of the properties you would
534-
like to group you results by. example: "customer.id" or ["browser","operating_system"]
534+
like to group your results by. example: "customer.id" or ["browser","operating_system"]
535535
:param max_age: an integer, greater than 30 seconds, the maximum 'staleness' you're
536536
willing to trade for increased query performance, in seconds
537537

0 commit comments

Comments
 (0)