Skip to content

Commit

Permalink
Module functions to also return the same as its Client equivalent (#111)
Browse files Browse the repository at this point in the history
Co-authored-by: Neil Kakkar <neilkakkar@gmail.com>
  • Loading branch information
hjoaquim and neilkakkar authored Jan 19, 2024
1 parent e348106 commit d0d962a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.3.2 - 2024-01-19

1. Return success/failure with all capture calls from module functions


## 3.3.1 - 2024-01-10

1. Make sure we don't override any existing feature flag properties when adding locally evaluated feature flag properties.
Expand Down
26 changes: 13 additions & 13 deletions posthog/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime # noqa: F401
from typing import Callable, Dict, Optional # noqa: F401
from typing import Callable, Dict, Optional, Tuple # noqa: F401

from posthog.client import Client
from posthog.version import VERSION
Expand Down Expand Up @@ -33,7 +33,7 @@ def capture(
send_feature_flags=False,
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> None
# type: (...) -> Tuple[bool, dict]
"""
Capture allows you to capture anything a user does within your system, which you can later use in PostHog to find patterns in usage, work out which features to improve or where people are giving up.
Expand All @@ -54,7 +54,7 @@ def capture(
posthog.capture('distinct id', 'purchase', groups={'company': 'id:5'})
```
"""
_proxy(
return _proxy(
"capture",
distinct_id=distinct_id,
event=event,
Expand All @@ -76,7 +76,7 @@ def identify(
uuid=None, # type: Optional[str]
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> None
# type: (...) -> Tuple[bool, dict]
"""
Identify lets you add metadata on your users so you can more easily identify who they are in PostHog, and even do things like segment users by these properties.
Expand All @@ -92,7 +92,7 @@ def identify(
})
```
"""
_proxy(
return _proxy(
"identify",
distinct_id=distinct_id,
properties=properties,
Expand All @@ -111,7 +111,7 @@ def set(
uuid=None, # type: Optional[str]
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> None
# type: (...) -> Tuple[bool, dict]
"""
Set properties on a user record.
This will overwrite previous people property values, just like `identify`.
Expand All @@ -127,7 +127,7 @@ def set(
})
```
"""
_proxy(
return _proxy(
"set",
distinct_id=distinct_id,
properties=properties,
Expand All @@ -146,7 +146,7 @@ def set_once(
uuid=None, # type: Optional[str]
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> None
# type: (...) -> Tuple[bool, dict]
"""
Set properties on a user record, only if they do not yet exist.
This will not overwrite previous people property values, unlike `identify`.
Expand All @@ -162,7 +162,7 @@ def set_once(
})
```
"""
_proxy(
return _proxy(
"set_once",
distinct_id=distinct_id,
properties=properties,
Expand All @@ -182,7 +182,7 @@ def group_identify(
uuid=None, # type: Optional[str]
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> None
# type: (...) -> Tuple[bool, dict]
"""
Set properties on a group
Expand All @@ -198,7 +198,7 @@ def group_identify(
})
```
"""
_proxy(
return _proxy(
"group_identify",
group_type=group_type,
group_key=group_key,
Expand All @@ -218,7 +218,7 @@ def alias(
uuid=None, # type: Optional[str]
disable_geoip=None, # type: Optional[bool]
):
# type: (...) -> None
# type: (...) -> Tuple[bool, dict]
"""
To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call. This will allow you to answer questions like "Which marketing channels leads to users churning after a month?" or "What do users do on our website before signing up?"
Expand All @@ -235,7 +235,7 @@ def alias(
posthog.alias('anonymous session id', 'distinct id')
```
"""
_proxy(
return _proxy(
"alias",
previous_id=previous_id,
distinct_id=distinct_id,
Expand Down
13 changes: 10 additions & 3 deletions posthog/test/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
class TestModule(unittest.TestCase):
posthog = None

def _assert_enqueue_result(self, result):
self.assertEqual(type(result[0]), bool)
self.assertEqual(type(result[1]), dict)

def failed(self):
self.failed = True

Expand All @@ -22,15 +26,18 @@ def test_no_host(self):
self.assertRaises(Exception, self.posthog.capture)

def test_track(self):
self.posthog.capture("distinct_id", "python module event")
res = self.posthog.capture("distinct_id", "python module event")
self._assert_enqueue_result(res)
self.posthog.flush()

def test_identify(self):
self.posthog.identify("distinct_id", {"email": "user@email.com"})
res = self.posthog.identify("distinct_id", {"email": "user@email.com"})
self._assert_enqueue_result(res)
self.posthog.flush()

def test_alias(self):
self.posthog.alias("previousId", "distinct_id")
res = self.posthog.alias("previousId", "distinct_id")
self._assert_enqueue_result(res)
self.posthog.flush()

def test_page(self):
Expand Down
2 changes: 1 addition & 1 deletion posthog/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "3.3.1"
VERSION = "3.3.2"

if __name__ == "__main__":
print(VERSION, end="") # noqa: T201

0 comments on commit d0d962a

Please sign in to comment.