
    gB                        d dl Z d dlmZmZmZmZmZ d dlmZ d dl	m
Z
 d dlmZ eZ	 dZdZdZdZdZdZdZdZdZdZdZd	ZdZdZg ZdZdZda	 	 	 	 	 	 	 d d
Z 	 	 	 	 	 d!dZ!	 	 	 	 	 d!dZ"	 	 	 	 	 d!dZ#	 	 	 	 	 d!dZ$	 	 	 	 d"dZ%	 	 	 	 	 	 	 d#dZ&i i i dddfdZ'i i i dddfdZ(i i i ddfdZ)di i i dddfdZ*i i i ddfdZ+d Z,d Z-d Z.d Z/d Z0d Z1d Z2d Z3 G d de      Z4y)$    N)CallableDictListOptionalTuple)Client)Integrations)VERSIONFT      c	                 ,    t        d| ||||||||
      S )a  
    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.

    A `capture` call requires
    - `distinct id` which uniquely identifies your user
    - `event name` to specify the event
    - We recommend using [verb] [noun], like `movie played` or `movie updated` to easily identify what your events mean later on.

    Optionally you can submit
    - `properties`, which can be a dict with any information you'd like to add
    - `groups`, which is a dict of group type -> group key mappings

    For example:
    ```python
    posthog.capture('distinct id', 'opened app')
    posthog.capture('distinct id', 'movie played', {'movie_id': '123', 'category': 'romcom'})

    posthog.capture('distinct id', 'purchase', groups={'company': 'id:5'})
    ```
    capture	distinct_idevent
propertiescontext	timestampuuidgroupssend_feature_flagsdisable_geoip_proxyr   s	            E/var/www/openai/venv/lib/python3.12/site-packages/posthog/__init__.pyr   r   #   s0    @ -#     c           	      &    t        d| |||||      S )a  
    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.

    An `identify` call requires
    - `distinct id` which uniquely identifies your user
    - `properties` with a dict with any key: value pairs

    For example:
    ```python
    posthog.identify('distinct id', {
        'email': 'dwayne@gmail.com',
        'name': 'Dwayne Johnson'
    })
    ```
    identifyr   r   r   r   r   r   r   r   s         r   r   r   Q   &    0 # r   c           	      &    t        d| |||||      S )a  
    Set properties on a user record.
    This will overwrite previous people property values, just like `identify`.

     A `set` call requires
     - `distinct id` which uniquely identifies your user
     - `properties` with a dict with any key: value pairs

     For example:
     ```python
     posthog.set('distinct id', {
         'current_browser': 'Chrome',
     })
     ```
    setr   r   r   s         r   r"   r"   t   s&    0 # r   c           	      &    t        d| |||||      S )a  
    Set properties on a user record, only if they do not yet exist.
    This will not overwrite previous people property values, unlike `identify`.

     A `set_once` call requires
     - `distinct id` which uniquely identifies your user
     - `properties` with a dict with any key: value pairs

     For example:
     ```python
     posthog.set_once('distinct id', {
         'referred_by': 'friend',
     })
     ```
    set_oncer   r   r   s         r   r$   r$      r    r   c           
      (    t        d| ||||||      S )aV  
    Set properties on a group

     A `group_identify` call requires
     - `group_type` type of your group
     - `group_key` unique identifier of the group
     - `properties` with a dict with any key: value pairs

     For example:
     ```python
     posthog.group_identify('company', 5, {
         'employees': 11,
     })
     ```
    group_identify
group_type	group_keyr   r   r   r   r   r   r'   s          r   r&   r&      s)    2 #	 	r   c           	      &    t        d| |||||      S )a-  
    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?"

    In a purely back-end implementation, this means whenever an anonymous user does something, you'll want to send a session ID ([Django](https://stackoverflow.com/questions/526179/in-django-how-can-i-find-out-the-request-session-sessionid-and-use-it-as-a-vari), [Flask](https://stackoverflow.com/questions/15156132/flask-login-how-to-get-session-id)) with the capture call. Then, when that users signs up, you want to do an alias call with the session ID and the newly created user ID.

    The same concept applies for when a user logs in.

    An `alias` call requires
    - `previous distinct id` the unique ID of the user before
    - `distinct id` the current unique id

    For example:
    ```python
    posthog.alias('anonymous session id', 'distinct id')
    ```
    aliasprevious_idr   r   r   r   r   r   r,   s         r   r+   r+      s&    2 # r   c           
      (    t        d| ||||||      S )a  
    capture_exception allows you to capture exceptions that happen in your code. This is useful for debugging and understanding what errors your users are encountering.
    This function never raises an exception, even if it fails to send the event.

    A `capture_exception` call does not require any fields, but we recommend sending:
    - `distinct id` which uniquely identifies your user for which this exception happens
    - `exception` to specify the exception to capture. If not provided, the current exception is captured via `sys.exc_info()`

    Optionally you can submit
    - `properties`, which can be a dict with any information you'd like to add
    - `groups`, which is a dict of group type -> group key mappings

    For example:
    ```python
    try:
        1 / 0
    except Exception as e:
        posthog.capture_exception(e, 'my specific distinct id')
        posthog.capture_exception(distinct_id='my specific distinct id')

    ```
    capture_exception	exceptionr   r   r   r   r   r   r   r0   s          r   r/   r/     s*    @ 	 	r   c                 *    t        d| |||||||	      S )a  
    Use feature flags to enable or disable features for users.

    For example:
    ```python
    if posthog.feature_enabled('beta feature', 'distinct id'):
        # do something
    if posthog.feature_enabled('groups feature', 'distinct id', groups={"organization": "5"}):
        # do something
    ```

    You can call `posthog.load_feature_flags()` before to make sure you're not doing unexpected requests.
    feature_enabledkeyr   r   person_propertiesgroup_propertiesonly_evaluate_locallysend_feature_flag_eventsr   r   r4   s           r   r3   r3   /  s,    0 +)3!9#
 
r   c                 *    t        d| |||||||	      S )aJ  
    Get feature flag variant for users. Used with experiments.
    Example:
    ```python
    if posthog.get_feature_flag('beta-feature', 'distinct_id') == 'test-variant':
        # do test variant code
    if posthog.get_feature_flag('beta-feature', 'distinct_id') == 'control':
        # do control code
    ```

    `groups` are a mapping from group type to group key. So, if you have a group type of "organization" and a group key of "5",
    you would pass groups={"organization": "5"}.

    `group_properties` take the format: { group_type_name: { group_properties } }

    So, for example, if you have the group type "organization" and the group key "5", with the properties name, and employee count,
    you'll send these as:

    ```python
        group_properties={"organization": {"name": "PostHog", "employees": 11}}
    ```
    get_feature_flagr4   r   r4   s           r   r;   r;   T  s-    @ +)3!9#
 
r   c           	      &    t        d| |||||      S )z
    Get all flags for a given user.
    Example:
    ```python
    flags = posthog.get_all_flags('distinct_id')
    ```

    flags are key-value pairs where the key is the flag key and the value is the flag variant, or True, or False.
    get_all_flagsr   r   r6   r7   r8   r   r   r>   s         r   r=   r=     s&    " +)3# r   c	                 ,    t        d| ||||||||
      S )Nget_feature_flag_payload	r5   r   match_valuer   r6   r7   r8   r9   r   r   rA   s	            r   r@   r@     s/     "+)3!9# r   c           	      &    t        d| |||||      S )Nget_all_flags_and_payloadsr>   r   r>   s         r   rD   rD     s&     $+)3# r   c                      t        d      S )zbReturns loaded feature flags, if any. Helpful for debugging what flag information you have loaded.feature_flag_definitionsr    r   r   rF   rF     s    ,--r   c                      t        d      S )z+Load feature flag definitions from PostHog.load_feature_flagsr   rG   r   r   rI   rI     s    &''r   c                  "    t        dg| i | y)zSend a page call.pageNr   argskwargss     r   rK   rK     s    
6#D#F#r   c                  "    t        dg| i | y)zSend a screen call.screenNr   rL   s     r   rP   rP     s    
8%d%f%r   c                      t        d       y)zTell the client to flush.flushNr   rG   r   r   rR   rR     s	    
7Or   c                      t        d       y)z/Block program until the client clears the queuejoinNr   rG   r   r   rT   rT     s	    
6Nr   c                  0    t        d       t        d       y)z2Flush all messages and cleanly shutdown the clientrR   rT   Nr   rG   r   r   shutdownrV     s    
7O
6Nr   c                 &   t         sVt        t        t        t        t
        t        t        t        t        t        t        t        t        t        t        t               a t        t         _        t        t         _        t#        t         |       } ||i |S )z?Create an analytics client if one doesn't exist and send to it.)hostdebugon_errorsend	sync_modepersonal_api_keyproject_api_keypoll_intervaldisabledr   %feature_flags_request_timeout_secondssuper_propertiesenable_exception_autocapture"exception_autocapture_integrations)default_clientr   api_keyrX   rY   rZ   r[   r\   r]   r^   r_   r`   r   ra   rb   rc   rd   getattr)methodrM   rN   fns       r   r   r     so     -+''2W- *F/Q%
, 'N N		(Btvr   c                       e Zd Zy)PosthogN)__name__
__module____qualname__rG   r   r   rk   rk     s    r   rk   )NNNNNFN)NNNNN)NNNN)NNNNNNN)5datetimetypingr   r   r   r   r   posthog.clientr   posthog.exception_capturer	   posthog.versionr
   __version__rf   rX   rZ   rY   r[   r\   r`   r]   r^   r_   r   ra   rb   rc   rd   project_rootprivacy_modere   r   r   r"   r$   r&   r+   r/   r3   r;   r=   r@   rD   rF   rI   rK   rP   rR   rT   rV   r   rk   rG   r   r   <module>rw      s    8 8 ! 2 # 
	 () % $ %' " 	+` 	 J 	 J 	 L 	"P 	!J 	)^ !"P !*^ > !6 &.
(
$
&


B	f 	r   