Skip to content

Commit ee03059

Browse files
authored
feat: add super properties (#138)
1 parent 28c4802 commit ee03059

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

CHANGELOG.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.7.0 - 2024-10-03
2+
3+
1. Adds a new `super_properties` parameter on the client that are appended to every /capture call.
4+
15
## 3.6.7 - 2024-09-24
26

37
1. Remove deprecated datetime.utcnow() in favour of datetime.now(tz=tzutc())
@@ -66,7 +70,6 @@
6670

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

69-
7073
## 3.3.1 - 2024-01-10
7174

7275
1. Make sure we don't override any existing feature flag properties when adding locally evaluated feature flag properties.
@@ -92,6 +95,7 @@
9295

9396
1. Restore how feature flags work when the client library is disabled: All requests return `None` and no events are sent when the client is disabled.
9497
2. Add a `feature_flag_definitions()` debug option, which returns currently loaded feature flag definitions. You can use this to more cleverly decide when to request local evaluation of feature flags.
98+
9599
## 3.0.0 - 2023-04-14
96100

97101
Breaking change:
@@ -132,7 +136,6 @@ posthog = Posthog('api_key', disable_geoip=False)
132136
1. Log instead of raise error on posthog personal api key errors
133137
2. Remove upper bound on backoff dependency
134138

135-
136139
## 2.3.0 - 2023-01-31
137140

138141
1. Add support for returning payloads of matched feature flags
@@ -148,6 +151,7 @@ Changes:
148151
Changes:
149152

150153
1. Fixes issues with date comparison.
154+
151155
## 2.1.1 - 2022-09-14
152156

153157
Changes:
@@ -160,6 +164,7 @@ Changes:
160164

161165
1. Feature flag defaults have been removed
162166
2. Setup logging only when debug mode is enabled.
167+
163168
## 2.0.1 - 2022-08-04
164169

165170
- Make poll_interval configurable
@@ -172,26 +177,28 @@ Breaking changes:
172177

173178
1. The minimum version requirement for PostHog servers is now 1.38. If you're using PostHog Cloud, you satisfy this requirement automatically.
174179
2. Feature flag defaults apply only when there's an error fetching feature flag results. Earlier, if the default was set to `True`, even if a flag resolved to `False`, the default would override this.
175-
**Note: These are removed in 2.0.2**
180+
**Note: These are removed in 2.0.2**
176181
3. Feature flag remote evaluation doesn't require a personal API key.
177182

178183
New Changes:
179184

180185
1. You can now evaluate feature flags locally (i.e. without sending a request to your PostHog servers) by setting a personal API key, and passing in groups and person properties to `is_feature_enabled` and `get_feature_flag` calls.
181186
2. Introduces a `get_all_flags` method that returns all feature flags. This is useful for when you want to seed your frontend with some initial flags, given a user ID.
182187

183-
184-
185188
## 1.4.9 - 2022-06-13
189+
186190
- Support for sending feature flags with capture calls
187191

188192
## 1.4.8 - 2022-05-12
193+
189194
- Support multi variate feature flags
190195

191196
## 1.4.7 - 2022-04-25
197+
192198
- Allow feature flags usage without project_api_key
193199

194200
## 1.4.1 - 2021-05-28
201+
195202
- Fix packaging issues with Sentry integrations
196203

197204
## 1.4.0 - 2021-05-18

posthog/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
poll_interval = 30 # type: int
2121
disable_geoip = True # type: bool
2222
feature_flags_request_timeout_seconds = 3 # type: int
23+
super_properties = None # type: Optional[Dict]
2324
# Currently alpha, use at your own risk
2425
enable_exception_autocapture = False # type: bool
2526
exception_autocapture_integrations = [] # type: List[Integrations]
@@ -504,6 +505,7 @@ def _proxy(method, *args, **kwargs):
504505
disabled=disabled,
505506
disable_geoip=disable_geoip,
506507
feature_flags_request_timeout_seconds=feature_flags_request_timeout_seconds,
508+
super_properties=super_properties,
507509
# TODO: Currently this monitoring begins only when the Client is initialised (which happens when you do something with the SDK)
508510
# This kind of initialisation is very annoying for exception capture. We need to figure out a way around this,
509511
# or deprecate this proxy option fully (it's already in the process of deprecation, no new clients should be using this method since like 5-6 months)

posthog/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def __init__(
5555
disable_geoip=True,
5656
historical_migration=False,
5757
feature_flags_request_timeout_seconds=3,
58+
super_properties=None,
5859
enable_exception_autocapture=False,
5960
exception_autocapture_integrations=None,
6061
project_root=None,
@@ -86,6 +87,7 @@ def __init__(
8687
self.disabled = disabled
8788
self.disable_geoip = disable_geoip
8889
self.historical_migration = historical_migration
90+
self.super_properties = super_properties
8991
self.enable_exception_autocapture = enable_exception_autocapture
9092
self.exception_autocapture_integrations = exception_autocapture_integrations
9193
self.exception_capture = None
@@ -443,6 +445,9 @@ def _enqueue(self, msg, disable_geoip):
443445
if disable_geoip:
444446
msg["properties"]["$geoip_disable"] = True
445447

448+
if self.super_properties:
449+
msg["properties"] = {**msg["properties"], **self.super_properties}
450+
446451
msg["distinct_id"] = stringify_id(msg.get("distinct_id", None))
447452

448453
msg = clean(msg)

posthog/test/test_client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,21 @@ def test_basic_capture_with_project_api_key(self):
8484
self.assertEqual(msg["properties"]["$lib"], "posthog-python")
8585
self.assertEqual(msg["properties"]["$lib_version"], VERSION)
8686

87+
def test_basic_super_properties(self):
88+
client = Client(FAKE_TEST_API_KEY, super_properties={"source": "repo-name"})
89+
90+
_, msg = client.capture("distinct_id", "python test event")
91+
client.flush()
92+
93+
self.assertEqual(msg["event"], "python test event")
94+
self.assertEqual(msg["properties"]["source"], "repo-name")
95+
96+
_, msg = client.identify("distinct_id", {"trait": "value"})
97+
client.flush()
98+
99+
self.assertEqual(msg["$set"]["trait"], "value")
100+
self.assertEqual(msg["properties"]["source"], "repo-name")
101+
87102
def test_basic_capture_exception(self):
88103

89104
with mock.patch.object(Client, "capture", return_value=None) as patch_capture:

posthog/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION = "3.6.7"
1+
VERSION = "3.7.0"
22

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

0 commit comments

Comments
 (0)