1+ from typing import Callable , Dict , Optional
12
2- from posthog .version import VERSION
33from posthog .client import Client
4- from typing import Optional , Dict , Callable
4+ from posthog . version import VERSION
55
66__version__ = VERSION
77
88"""Settings."""
9- api_key = None # type: str
10- host = None # type: str
11- on_error = None # type: Callable
12- debug = False # type: bool
13- send = True # type: bool
14- sync_mode = False # type: bool
15- disabled = False # type: bool
16- personal_api_key = None # type: str
9+ api_key = None # type: str
10+ host = None # type: str
11+ on_error = None # type: Callable
12+ debug = False # type: bool
13+ send = True # type: bool
14+ sync_mode = False # type: bool
15+ disabled = False # type: bool
16+ personal_api_key = None # type: str
1717
1818default_client = None
1919
2020
2121def capture (
22- distinct_id , # type: str,
23- event , # type: str,
24- properties = None , # type: Optional[Dict]
25- context = None , # type: Optional[Dict]
26- timestamp = None , # type: Optional[datetime.datetime]
27- message_id = None , # type: Optional[str]
28- ):
22+ distinct_id , # type: str,
23+ event , # type: str,
24+ properties = None , # type: Optional[Dict]
25+ context = None , # type: Optional[Dict]
26+ timestamp = None , # type: Optional[datetime.datetime]
27+ message_id = None , # type: Optional[str]
28+ ):
2929 # type: (...) -> None
3030 """
3131 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.
3232
3333 A `capture` call requires
3434 - `distinct id` which uniquely identifies your user
35- - `event name` to make sure
35+ - `event name` to make sure
3636 - We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on.
3737
3838 Optionally you can submit
@@ -43,22 +43,31 @@ def capture(
4343 posthog.capture('distinct id', 'movie played', {'movie_id': '123', 'category': 'romcom'})
4444 ```
4545 """
46- _proxy ('capture' , distinct_id = distinct_id , event = event , properties = properties , context = context , timestamp = timestamp , message_id = message_id )
46+ _proxy (
47+ "capture" ,
48+ distinct_id = distinct_id ,
49+ event = event ,
50+ properties = properties ,
51+ context = context ,
52+ timestamp = timestamp ,
53+ message_id = message_id ,
54+ )
55+
4756
4857def identify (
49- distinct_id , # type: str,
50- properties = None , # type: Optional[Dict]
51- context = None , # type: Optional[Dict]
52- timestamp = None , # type: Optional[datetime.datetime]
53- message_id = None , # type: Optional[str]
54- ):
58+ distinct_id , # type: str,
59+ properties = None , # type: Optional[Dict]
60+ context = None , # type: Optional[Dict]
61+ timestamp = None , # type: Optional[datetime.datetime]
62+ message_id = None , # type: Optional[str]
63+ ):
5564 # type: (...) -> None
5665 """
5766 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.
5867
5968 An `identify` call requires
6069 - `distinct id` which uniquely identifies your user
61- - `properties` with a dict with any key: value pairs
70+ - `properties` with a dict with any key: value pairs
6271
6372 For example:
6473 ```python
@@ -68,20 +77,28 @@ def identify(
6877 })
6978 ```
7079 """
71- _proxy ('identify' , distinct_id = distinct_id , properties = properties , context = context , timestamp = timestamp , message_id = message_id )
80+ _proxy (
81+ "identify" ,
82+ distinct_id = distinct_id ,
83+ properties = properties ,
84+ context = context ,
85+ timestamp = timestamp ,
86+ message_id = message_id ,
87+ )
88+
7289
7390def group (* args , ** kwargs ):
7491 """Send a group call."""
75- _proxy (' group' , * args , ** kwargs )
92+ _proxy (" group" , * args , ** kwargs )
7693
7794
7895def alias (
79- previous_id , # type: str,
80- distinct_id , # type: str,
81- context = None , # type: Optional[Dict]
82- timestamp = None , # type: Optional[datetime.datetime]
83- message_id = None , # type: Optional[str]
84- ):
96+ previous_id , # type: str,
97+ distinct_id , # type: str,
98+ context = None , # type: Optional[Dict]
99+ timestamp = None , # type: Optional[datetime.datetime]
100+ message_id = None , # type: Optional[str]
101+ ):
85102 # type: (...) -> None
86103 """
87104 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?"
@@ -99,13 +116,21 @@ def alias(
99116 posthog.alias('anonymous session id', 'distinct id')
100117 ```
101118 """
102- _proxy ('alias' , previous_id = previous_id , distinct_id = distinct_id , context = context , timestamp = timestamp , message_id = message_id )
119+ _proxy (
120+ "alias" ,
121+ previous_id = previous_id ,
122+ distinct_id = distinct_id ,
123+ context = context ,
124+ timestamp = timestamp ,
125+ message_id = message_id ,
126+ )
127+
103128
104129def feature_enabled (
105- key , # type: str,
106- distinct_id , # type: str,
107- default = False , # type: bool
108- ):
130+ key , # type: str,
131+ distinct_id , # type: str,
132+ default = False , # type: bool
133+ ):
109134 # type: (...) -> bool
110135 """
111136 Use feature flags to enable or disable features for users.
@@ -118,33 +143,33 @@ def feature_enabled(
118143
119144 You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.
120145 """
121- return _proxy (' feature_enabled' , key = key , distinct_id = distinct_id , default = default )
146+ return _proxy (" feature_enabled" , key = key , distinct_id = distinct_id , default = default )
122147
123148
124149def page (* args , ** kwargs ):
125150 """Send a page call."""
126- _proxy (' page' , * args , ** kwargs )
151+ _proxy (" page" , * args , ** kwargs )
127152
128153
129154def screen (* args , ** kwargs ):
130155 """Send a screen call."""
131- _proxy (' screen' , * args , ** kwargs )
156+ _proxy (" screen" , * args , ** kwargs )
132157
133158
134159def flush ():
135160 """Tell the client to flush."""
136- _proxy (' flush' )
161+ _proxy (" flush" )
137162
138163
139164def join ():
140165 """Block program until the client clears the queue"""
141- _proxy (' join' )
166+ _proxy (" join" )
142167
143168
144169def shutdown ():
145170 """Flush all messages and cleanly shutdown the client"""
146- _proxy (' flush' )
147- _proxy (' join' )
171+ _proxy (" flush" )
172+ _proxy (" join" )
148173
149174
150175def _proxy (method , * args , ** kwargs ):
@@ -153,9 +178,15 @@ def _proxy(method, *args, **kwargs):
153178 if disabled :
154179 return None
155180 if not default_client :
156- default_client = Client (api_key , host = host , debug = debug ,
157- on_error = on_error , send = send ,
158- sync_mode = sync_mode , personal_api_key = personal_api_key )
181+ default_client = Client (
182+ api_key ,
183+ host = host ,
184+ debug = debug ,
185+ on_error = on_error ,
186+ send = send ,
187+ sync_mode = sync_mode ,
188+ personal_api_key = personal_api_key ,
189+ )
159190
160191 fn = getattr (default_client , method )
161192 return fn (* args , ** kwargs )
0 commit comments