1- # klime-analytics
1+ # klime
22
3- Klime Analytics SDK for Python.
3+ Klime SDK for Python.
44
55## Installation
66
77``` bash
8- pip install klime-analytics
8+ pip install klime
99```
1010
1111## Quick Start
@@ -17,24 +17,27 @@ client = KlimeClient(
1717 write_key = ' your-write-key'
1818)
1919
20- # Track an event
21- client.track(' Button Clicked' , {
22- ' button_name' : ' Sign up' ,
23- ' plan' : ' pro'
24- })
25-
2620# Identify a user
2721client.identify(' user_123' , {
28222923 ' name' : ' Stefan'
3024})
3125
32- # Group a user with an organization
26+ # Track an event
27+ client.track(' Button Clicked' , {
28+ ' button_name' : ' Sign up' ,
29+ ' plan' : ' pro'
30+ }, user_id = ' user_123' )
31+
32+ # Associate user with a group and set group traits
3333client.group(' org_456' , {
3434 ' name' : ' Acme Inc' ,
3535 ' plan' : ' enterprise'
3636}, user_id = ' user_123' )
3737
38+ # Or just link the user to a group (if traits are already set)
39+ client.group(' org_456' , user_id = ' user_123' )
40+
3841# Shutdown gracefully
3942client.shutdown()
4043```
@@ -46,7 +49,7 @@ client.shutdown()
4649``` python
4750KlimeClient(
4851 write_key: str , # Required: Your Klime write key
49- endpoint: Optional[str ] = None , # Optional: API endpoint (default: https://ingest .klime.com)
52+ endpoint: Optional[str ] = None , # Optional: API endpoint (default: https://i .klime.com)
5053 flush_interval: Optional[int ] = None , # Optional: Milliseconds between flushes (default: 2000)
5154 max_batch_size: Optional[int ] = None , # Optional: Max events per batch (default: 20, max: 100)
5255 max_queue_size: Optional[int ] = None , # Optional: Max queued events (default: 1000)
@@ -60,22 +63,23 @@ KlimeClient(
6063
6164#### ` track(event: str, properties: Optional[Dict] = None, user_id: Optional[str] = None, group_id: Optional[str] = None, ip: Optional[str] = None) -> None `
6265
63- Track a user event.
66+ Track a user event. A ` user_id ` is required for events to be useful in Klime.
6467
6568``` python
66- # Simple usage
6769client.track(' Button Clicked' , {
6870 ' button_name' : ' Sign up' ,
6971 ' plan' : ' pro'
70- })
72+ }, user_id = ' user_123 ' )
7173
72- # With user context and IP
74+ # With IP address (for geolocation)
7375client.track(' Button Clicked' , {
7476 ' button_name' : ' Sign up' ,
7577 ' plan' : ' pro'
76- }, user_id = ' user_123' , group_id = ' org_456 ' , ip = ' 192.168.1.1' )
78+ }, user_id = ' user_123' , ip = ' 192.168.1.1' )
7779```
7880
81+ > ** Advanced** : The ` group_id ` parameter is available for multi-tenant scenarios where a user belongs to multiple organizations and you need to specify which organization context the event occurred in.
82+
7983#### ` identify(user_id: str, traits: Optional[Dict] = None, ip: Optional[str] = None) -> None `
8084
8185Identify a user with traits.
@@ -89,20 +93,23 @@ client.identify('user_123', {
8993
9094#### ` group(group_id: str, traits: Optional[Dict] = None, user_id: Optional[str] = None, ip: Optional[str] = None) -> None `
9195
92- Associate a user with a group and set group traits.
96+ Associate a user with a group and/or set group traits.
9397
9498``` python
95- # Simple usage
99+ # Associate user with a group and set group traits (most common)
96100client.group(' org_456' , {
97101 ' name' : ' Acme Inc' ,
98102 ' plan' : ' enterprise'
99- })
103+ }, user_id = ' user_123' )
104+
105+ # Just link a user to a group (traits already set or not needed)
106+ client.group(' org_456' , user_id = ' user_123' )
100107
101- # With user ID and IP
108+ # Just update group traits (e.g., from a webhook or background job)
102109client.group(' org_456' , {
103- ' name ' : ' Acme Inc ' ,
104- ' plan ' : ' enterprise '
105- }, user_id = ' user_123 ' , ip = ' 192.168.1.1 ' )
110+ ' plan ' : ' enterprise ' ,
111+ ' employee_count ' : 50
112+ })
106113```
107114
108115#### ` flush() -> None `
@@ -170,7 +177,7 @@ def button_clicked():
170177 client.track(' Button Clicked' , {
171178 ' button_name' : request.json.get(' buttonName' )
172179 }, user_id = request.json.get(' userId' ), ip = request.remote_addr)
173-
180+
174181 return {' success' : True }
175182
176183# Graceful shutdown
@@ -192,16 +199,15 @@ class ButtonClickView(View):
192199 client.track(' Button Clicked' , {
193200 ' button_name' : request.POST .get(' buttonName' )
194201 }, user_id = str (request.user.id), ip = request.META .get(' REMOTE_ADDR' ))
195-
202+
196203 return JsonResponse({' success' : True })
197204```
198205
199206## Requirements
200207
201- - Python 3.7 or higher
208+ - Python 3.9 or higher
202209- No external dependencies (uses only standard library)
203210
204211## License
205212
206213MIT
207-
0 commit comments