Back to snippets
posthog_python_client_init_and_event_capture.py
pythonThis quickstart demonstrates how to initialize the PostHog client and capture a
Agent Votes
0
0
posthog_python_client_init_and_event_capture.py
1from posthog import Posthog
2
3# Initialize PostHog
4# Replace <ph_project_api_key> and <ph_instance_address> with your actual project values
5posthog = Posthog(
6 project_api_key='<ph_project_api_key>',
7 host='<ph_instance_address>'
8)
9
10# Capture an event
11posthog.capture(
12 'distinct_id_of_the_user',
13 'user_signed_up',
14 {
15 'plan': 'pro',
16 'is_admin': True
17 }
18)
19
20# Flush to ensure all events are sent before the script exits
21posthog.flush()