Skip to content

Commit 37bd301

Browse files
oliverb123greptile-apps[bot]daibhin
authored
feat: prep for 6.0.0, bunch of breaking changes (#273)
* alright * fix exports * Update posthog/test/test_before_send.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update posthog/__init__.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * Update posthog/__init__.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> * fix tests after rebase * update examples * update mypy baseline * Revert "update mypy baseline" This reverts commit da395dd. * try again * whatever * request user * fix middleware * getattr is_authenticated * allow using custom client for exception capture * update comments * fix circular import * type arguments, use TypedDict * fix setup * mypy * whoops * ok * further mypy * mypy sync * docs and fixes --------- Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: David Newell <david@posthog.com>
1 parent b41dc85 commit 37bd301

28 files changed

+3771
-4227
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
# 6.0.0
2+
3+
This release contains a number of major breaking changes:
4+
- feat: make distinct_id an optional parameter in posthog.capture and related functions
5+
- feat: make capture and related functions return `Optional[str]`, which is the UUID of the sent event, if it was sent
6+
- fix: remove `identify` (prefer `posthog.set()`), and `page` and `screen` (prefer `posthog.capture()`)
7+
- fix: delete exception-capture specific integrations module. Prefer the general-purpose django middleware as a replacement for the django `Integration`.
8+
9+
To migrate to this version, you'll mostly just need to switch to using named keyword arguments, rather than positional ones. For example:
10+
```python
11+
# Old calling convention
12+
posthog.capture("user123", "button_clicked", {"button_id": "123"})
13+
# New calling convention
14+
posthog.capture(distinct_id="user123", event="button_clicked", properties={"button_id": "123"})
15+
16+
# Better pattern
17+
with posthog.new_context():
18+
posthog.identify_context("user123")
19+
20+
# The event name is the first argument, and can be passed positionally, or as a keyword argument in a later position
21+
posthog.capture("button_pressed")
22+
```
23+
24+
Generally, arguments are now appropriately typed, and docstrings have been updated. If something is unclear, please open an issue, or submit a PR!
25+
126
# 5.4.0 - 2025-06-20
227

328
- feat: add support to session_id context on page method

example.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141

4242
# Capture an event
4343
posthog.capture(
44-
"distinct_id",
4544
"event",
46-
{"property1": "value", "property2": "value"},
45+
distinct_id="distinct_id",
46+
properties={"property1": "value", "property2": "value"},
4747
send_feature_flags=True,
4848
)
4949

@@ -65,31 +65,35 @@
6565
posthog.alias("distinct_id", "new_distinct_id")
6666

6767
posthog.capture(
68-
"new_distinct_id", "event2", {"property1": "value", "property2": "value"}
68+
"event2",
69+
distinct_id="new_distinct_id",
70+
properties={"property1": "value", "property2": "value"},
6971
)
7072
posthog.capture(
71-
"new_distinct_id",
7273
"event-with-groups",
73-
{"property1": "value", "property2": "value"},
74+
distinct_id="new_distinct_id",
75+
properties={"property1": "value", "property2": "value"},
7476
groups={"company": "id:5"},
7577
)
7678

7779
# # Add properties to the person
78-
posthog.identify("new_distinct_id", {"email": "something@something.com"})
80+
posthog.set(
81+
distinct_id="new_distinct_id", properties={"email": "something@something.com"}
82+
)
7983

8084
# Add properties to a group
8185
posthog.group_identify("company", "id:5", {"employees": 11})
8286

8387
# properties set only once to the person
84-
posthog.set_once("new_distinct_id", {"self_serve_signup": True})
88+
posthog.set_once(distinct_id="new_distinct_id", properties={"self_serve_signup": True})
8589

8690

8791
posthog.set_once(
88-
"new_distinct_id", {"self_serve_signup": False}
92+
distinct_id="new_distinct_id", properties={"self_serve_signup": False}
8993
) # this will not change the property (because it was already set)
9094

91-
posthog.set("new_distinct_id", {"current_browser": "Chrome"})
92-
posthog.set("new_distinct_id", {"current_browser": "Firefox"})
95+
posthog.set(distinct_id="new_distinct_id", properties={"current_browser": "Chrome"})
96+
posthog.set(distinct_id="new_distinct_id", properties={"current_browser": "Firefox"})
9397

9498

9599
# #############################################################################

mypy-baseline.txt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@ posthog/client.py:0: error: Library stubs not installed for "six" [import-untyp
2222
posthog/client.py:0: note: Hint: "python3 -m pip install types-six"
2323
posthog/client.py:0: error: Name "queue" already defined (by an import) [no-redef]
2424
posthog/client.py:0: error: Need type annotation for "queue" [var-annotated]
25-
posthog/client.py:0: error: Item "None" of "Any | None" has no attribute "get" [union-attr]
26-
simulator.py:0: error: Unexpected keyword argument "anonymous_id" for "capture" [call-arg]
27-
posthog/__init__.py:0: note: "capture" defined here
28-
simulator.py:0: error: Unexpected keyword argument "anonymous_id" for "identify" [call-arg]
29-
posthog/__init__.py:0: note: "identify" defined here
30-
simulator.py:0: error: Unexpected keyword argument "traits" for "identify" [call-arg]
31-
posthog/__init__.py:0: note: "identify" defined here
25+
posthog/client.py:0: error: Incompatible types in assignment (expression has type "Any | list[Any]", variable has type "None") [assignment]
26+
posthog/client.py:0: error: Incompatible types in assignment (expression has type "dict[Any, Any]", variable has type "None") [assignment]
27+
posthog/client.py:0: error: "None" has no attribute "__iter__" (not iterable) [attr-defined]
28+
posthog/client.py:0: error: Statement is unreachable [unreachable]
29+
posthog/client.py:0: error: Incompatible types in assignment (expression has type "Any | dict[Any, Any]", variable has type "None") [assignment]
30+
posthog/client.py:0: error: Incompatible types in assignment (expression has type "Any | dict[Any, Any]", variable has type "None") [assignment]
31+
posthog/client.py:0: error: Incompatible types in assignment (expression has type "dict[Never, Never]", variable has type "None") [assignment]
32+
posthog/client.py:0: error: Incompatible types in assignment (expression has type "dict[Never, Never]", variable has type "None") [assignment]
33+
posthog/client.py:0: error: Right operand of "and" is never evaluated [unreachable]
34+
posthog/client.py:0: error: Incompatible types in assignment (expression has type "Poller", variable has type "None") [assignment]
35+
posthog/client.py:0: error: "None" has no attribute "start" [attr-defined]
36+
posthog/client.py:0: error: "None" has no attribute "get" [attr-defined]
37+
posthog/client.py:0: error: Statement is unreachable [unreachable]
38+
posthog/client.py:0: error: Statement is unreachable [unreachable]
3239
example.py:0: error: Statement is unreachable [unreachable]
3340
posthog/ai/utils.py:0: error: Need type annotation for "output" (hint: "output: list[<type>] = ...") [var-annotated]
3441
posthog/ai/utils.py:0: error: Function "builtins.any" is not valid as a type [valid-type]

0 commit comments

Comments
 (0)