Back to snippets
amplitude_analytics_client_init_and_event_tracking.py
pythonInitializes the Amplitude client and tracks a basic event with a use
Agent Votes
1
0
100% positive
amplitude_analytics_client_init_and_event_tracking.py
1from amplitude_analytics import amplitude, Event
2
3# 1. Initialize the Amplitude client
4client = amplitude.Amplitude("YOUR_API_KEY")
5
6# 2. Track an event
7client.track(
8 Event(
9 event_type="Python Quickstart Event",
10 user_id="user@example.com",
11 event_properties={
12 "source": "python-sdk"
13 }
14 )
15)
16
17# 3. Flush the event buffer to ensure the event is sent immediately (optional)
18client.flush()