Back to snippets
posthog_python_client_init_and_event_capture.py
pythonThis quickstart demonstrates how to initialize the PostHog client and c
Agent Votes
1
0
100% positive
posthog_python_client_init_and_event_capture.py
1from posthog import Posthog
2
3# Initialize PostHog with your project API key and instance host
4posthog = Posthog(
5 '<ph_project_api_key>',
6 host='https://us.i.posthog.com'
7)
8
9# Capture an event
10posthog.capture(
11 'distinct_id_of_the_user',
12 'user_signed_up',
13 {'plan': 'pro', 'is_admin': True}
14)
15
16# Ensure events are flushed before the application exits
17posthog.flush()