trodo-python 1.0.0__tar.gz → 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. {trodo_python-1.0.0 → trodo_python-1.0.1}/PKG-INFO +227 -227
  2. {trodo_python-1.0.0 → trodo_python-1.0.1}/README.md +200 -200
  3. {trodo_python-1.0.0 → trodo_python-1.0.1}/pyproject.toml +43 -43
  4. {trodo_python-1.0.0 → trodo_python-1.0.1}/setup.cfg +4 -4
  5. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/__init__.py +134 -134
  6. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/api/async_client.py +96 -96
  7. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/api/endpoints.py +20 -20
  8. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/api/http_client.py +87 -87
  9. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/auto/auto_event_manager.py +134 -134
  10. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/client.py +195 -195
  11. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/managers/group_manager.py +106 -106
  12. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/managers/people_manager.py +77 -77
  13. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/queue/batch_flusher.py +52 -52
  14. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/queue/event_queue.py +32 -32
  15. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/session/server_session.py +74 -74
  16. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/session/session_manager.py +74 -74
  17. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/types.py +79 -79
  18. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/user_context.py +224 -224
  19. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo_python.egg-info/PKG-INFO +227 -227
  20. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/api/__init__.py +0 -0
  21. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/auto/__init__.py +0 -0
  22. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/managers/__init__.py +0 -0
  23. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/queue/__init__.py +0 -0
  24. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo/session/__init__.py +0 -0
  25. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo_python.egg-info/SOURCES.txt +0 -0
  26. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo_python.egg-info/dependency_links.txt +0 -0
  27. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo_python.egg-info/requires.txt +0 -0
  28. {trodo_python-1.0.0 → trodo_python-1.0.1}/trodo_python.egg-info/top_level.txt +0 -0
@@ -1,227 +1,227 @@
1
- Metadata-Version: 2.4
2
- Name: trodo-python
3
- Version: 1.0.0
4
- Summary: Trodo Analytics SDK for Python — server-side event tracking
5
- License: ISC
6
- Keywords: analytics,tracking,trodo,server-side
7
- Classifier: Programming Language :: Python :: 3
8
- Classifier: Programming Language :: Python :: 3.8
9
- Classifier: Programming Language :: Python :: 3.9
10
- Classifier: Programming Language :: Python :: 3.10
11
- Classifier: Programming Language :: Python :: 3.11
12
- Classifier: Programming Language :: Python :: 3.12
13
- Classifier: License :: OSI Approved :: ISC License (ISCL)
14
- Classifier: Operating System :: OS Independent
15
- Classifier: Intended Audience :: Developers
16
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
- Requires-Python: >=3.8
18
- Description-Content-Type: text/markdown
19
- Requires-Dist: requests>=2.28.0
20
- Provides-Extra: async
21
- Requires-Dist: httpx>=0.27.0; extra == "async"
22
- Provides-Extra: dev
23
- Requires-Dist: pytest>=7.0; extra == "dev"
24
- Requires-Dist: pytest-cov; extra == "dev"
25
- Requires-Dist: responses>=0.25.0; extra == "dev"
26
- Requires-Dist: httpx>=0.27.0; extra == "dev"
27
-
28
- # trodo-python
29
-
30
- Server-side Python SDK for [Trodo Analytics](https://trodo.ai). Track backend events, identify users, and manage people/groups — all merging seamlessly with your frontend Trodo data under the same `site_id`.
31
-
32
- ## Installation
33
-
34
- ```bash
35
- pip install trodo-python
36
- ```
37
-
38
- For async support (optional):
39
-
40
- ```bash
41
- pip install trodo-python[async]
42
- ```
43
-
44
- Requires Python 3.8+.
45
-
46
- ## Quick Start
47
-
48
- ```python
49
- import trodo
50
-
51
- # Initialize once at app startup
52
- trodo.init(
53
- site_id='your-site-id',
54
- debug=False, # optional: log API calls
55
- auto_events=True, # optional: hook sys.excepthook
56
- )
57
-
58
- # Get a user context
59
- user = trodo.for_user('user-123')
60
-
61
- # Track a custom event
62
- user.track('purchase_completed', {'amount': 99.99, 'plan': 'pro'})
63
-
64
- # Identify the user (merges with frontend events under the same identity)
65
- user.identify('user@example.com') # distinct_id becomes id_user@example.com
66
-
67
- # Update people profile
68
- user.people.set({'plan': 'pro', 'company': 'Acme'})
69
-
70
- # Track a server-side error
71
- user.capture_error(Exception('payment failed'))
72
-
73
- # Flush queued events before process exit
74
- trodo.shutdown()
75
- ```
76
-
77
- ## Flask / FastAPI Example
78
-
79
- ```python
80
- # Flask
81
- from flask import Flask, request
82
- import trodo
83
-
84
- app = Flask(__name__)
85
- trodo.init(site_id='your-site-id')
86
-
87
- @app.route('/purchase', methods=['POST'])
88
- def purchase():
89
- user_id = request.json['user_id']
90
- user = trodo.for_user(user_id)
91
- user.track('purchase_completed', {'amount': request.json['amount']})
92
- return {'ok': True}
93
- ```
94
-
95
- ## Cross-SDK Identity Merging
96
-
97
- Frontend and backend events merge when both sides call `identify()` with the same value:
98
-
99
- ```python
100
- # Python SDK
101
- user.identify('user@example.com') # → id_user@example.com
102
-
103
- # Browser SDK (same value)
104
- # Trodo.identify('user@example.com') → id_user@example.com
105
-
106
- # Both event streams now appear together in the Trodo dashboard
107
- ```
108
-
109
- ## API Reference
110
-
111
- ### `trodo.init(config)`
112
-
113
- | Parameter | Type | Default | Description |
114
- |-----------|------|---------|-------------|
115
- | `site_id` | `str` | required | Your Trodo site ID |
116
- | `api_base` | `str` | `https://sdkapi.trodo.ai` | API base URL |
117
- | `debug` | `bool` | `False` | Log API requests/responses |
118
- | `auto_events` | `bool` | `False` | Hook `sys.excepthook` + `threading.excepthook` |
119
- | `retries` | `int` | `3` | HTTP retry attempts on 5xx errors |
120
- | `timeout` | `int` | `10` | HTTP timeout in seconds |
121
- | `batch_enabled` | `bool` | `False` | Queue events and flush in bulk |
122
- | `batch_size` | `int` | `50` | Max events per batch flush |
123
- | `batch_flush_interval` | `float` | `5.0` | Flush interval in seconds |
124
- | `on_error` | `callable` | `None` | Callback for SDK errors |
125
-
126
- ### `trodo.for_user(distinct_id, session_id=None)`
127
-
128
- Returns a user-bound context. All subsequent calls use this user's session.
129
-
130
- ```python
131
- user = trodo.for_user(
132
- 'user-123',
133
- session_id=request.cookies.get('trodo_session'), # optional: correlate with browser session
134
- )
135
- ```
136
-
137
- ### User Context Methods
138
-
139
- ```python
140
- user.track(event_name, properties=None) # Track custom event
141
- user.track_event(event_name, properties=None) # Alias for track()
142
- user.identify(identify_id) # Merge identity
143
- user.wallet_address(address) # Set crypto wallet address
144
- user.reset() # Clear session context
145
- user.capture_error(exception) # Track server_error event
146
-
147
- # People profile
148
- user.people.set(properties)
149
- user.people.set_once(properties)
150
- user.people.unset(keys)
151
- user.people.increment(properties)
152
- user.people.append(properties)
153
- user.people.union(properties)
154
- user.people.remove(properties)
155
- user.people.track_charge(amount, properties=None)
156
- user.people.clear_charges()
157
- user.people.delete_user()
158
-
159
- # Groups
160
- user.set_group(group_key, group_id)
161
- user.add_group(group_key, group_id)
162
- user.remove_group(group_key, group_id)
163
- group = user.get_group(group_key, group_id)
164
- group.set(properties)
165
- group.set_once(properties)
166
- group.union(properties)
167
- group.remove(properties)
168
- group.unset(keys)
169
- group.increment(properties)
170
- group.append(properties)
171
- group.delete()
172
- ```
173
-
174
- ### Direct Call Pattern (for pipelines/scripts)
175
-
176
- ```python
177
- trodo.track('user-123', 'event_name', {'key': 'value'})
178
- trodo.identify('user-123', 'identify_id')
179
- trodo.people_set('user-123', {'plan': 'pro'})
180
- trodo.set_group('user-123', 'company', 'acme')
181
- ```
182
-
183
- ### Global Methods
184
-
185
- ```python
186
- trodo.enable_auto_events() # Enable sys.excepthook hooks
187
- trodo.disable_auto_events() # Disable hooks
188
- trodo.flush() # Flush pending batch queue
189
- trodo.shutdown() # Flush + stop background timers
190
- ```
191
-
192
- ## Auto Events
193
-
194
- When `auto_events=True`, the SDK wraps Python's exception hooks and sends `server_error` events to Trodo:
195
-
196
- - `sys.excepthook` — unhandled exceptions in the main thread
197
- - `threading.excepthook` — unhandled exceptions in threads
198
-
199
- These events use `distinct_id: 'server_global'` in the dashboard.
200
-
201
- Per-user error capture: `user.capture_error(e)` uses the user's own `distinct_id`.
202
-
203
- ## Batching
204
-
205
- ```python
206
- trodo.init(
207
- site_id='your-site-id',
208
- batch_enabled=True,
209
- batch_size=100,
210
- batch_flush_interval=3.0,
211
- )
212
-
213
- # Events are queued and flushed every 3s or when 100 events accumulate
214
- user.track('page_view')
215
-
216
- # Always flush before process exit
217
- import atexit
218
- atexit.register(trodo.shutdown)
219
- ```
220
-
221
- ## Thread Safety
222
-
223
- The SDK is thread-safe. `SessionManager`, `EventQueue`, and `BatchFlusher` all use `threading.Lock` internally. Safe to use in multi-threaded Flask/Django/FastAPI applications.
224
-
225
- ## License
226
-
227
- ISC
1
+ Metadata-Version: 2.4
2
+ Name: trodo-python
3
+ Version: 1.0.1
4
+ Summary: Trodo Analytics SDK for Python — server-side event tracking
5
+ License: ISC
6
+ Keywords: analytics,tracking,trodo,server-side
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.8
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: License :: OSI Approved :: ISC License (ISCL)
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ Requires-Dist: requests>=2.28.0
20
+ Provides-Extra: async
21
+ Requires-Dist: httpx>=0.27.0; extra == "async"
22
+ Provides-Extra: dev
23
+ Requires-Dist: pytest>=7.0; extra == "dev"
24
+ Requires-Dist: pytest-cov; extra == "dev"
25
+ Requires-Dist: responses>=0.25.0; extra == "dev"
26
+ Requires-Dist: httpx>=0.27.0; extra == "dev"
27
+
28
+ # trodo-python
29
+
30
+ Server-side Python SDK for [Trodo Analytics](https://trodo.ai). Track backend events, identify users, and manage people/groups — all merging seamlessly with your frontend Trodo data under the same `site_id`.
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install trodo-python
36
+ ```
37
+
38
+ For async support (optional):
39
+
40
+ ```bash
41
+ pip install trodo-python[async]
42
+ ```
43
+
44
+ Requires Python 3.8+.
45
+
46
+ ## Quick Start
47
+
48
+ ```python
49
+ import trodo
50
+
51
+ # Initialize once at app startup
52
+ trodo.init(
53
+ site_id='your-site-id',
54
+ debug=False, # optional: log API calls
55
+ auto_events=True, # optional: hook sys.excepthook
56
+ )
57
+
58
+ # Get a user context
59
+ user = trodo.for_user('user-123')
60
+
61
+ # Track a custom event
62
+ user.track('purchase_completed', {'amount': 99.99, 'plan': 'pro'})
63
+
64
+ # Identify the user (merges with frontend events under the same identity)
65
+ user.identify('user@example.com') # distinct_id becomes id_user@example.com
66
+
67
+ # Update people profile
68
+ user.people.set({'plan': 'pro', 'company': 'Acme'})
69
+
70
+ # Track a server-side error
71
+ user.capture_error(Exception('payment failed'))
72
+
73
+ # Flush queued events before process exit
74
+ trodo.shutdown()
75
+ ```
76
+
77
+ ## Flask / FastAPI Example
78
+
79
+ ```python
80
+ # Flask
81
+ from flask import Flask, request
82
+ import trodo
83
+
84
+ app = Flask(__name__)
85
+ trodo.init(site_id='your-site-id')
86
+
87
+ @app.route('/purchase', methods=['POST'])
88
+ def purchase():
89
+ user_id = request.json['user_id']
90
+ user = trodo.for_user(user_id)
91
+ user.track('purchase_completed', {'amount': request.json['amount']})
92
+ return {'ok': True}
93
+ ```
94
+
95
+ ## Cross-SDK Identity Merging
96
+
97
+ Frontend and backend events merge when both sides call `identify()` with the same value:
98
+
99
+ ```python
100
+ # Python SDK
101
+ user.identify('user@example.com') # → id_user@example.com
102
+
103
+ # Browser SDK (same value)
104
+ # Trodo.identify('user@example.com') → id_user@example.com
105
+
106
+ # Both event streams now appear together in the Trodo dashboard
107
+ ```
108
+
109
+ ## API Reference
110
+
111
+ ### `trodo.init(config)`
112
+
113
+ | Parameter | Type | Default | Description |
114
+ |-----------|------|---------|-------------|
115
+ | `site_id` | `str` | required | Your Trodo site ID |
116
+ | `api_base` | `str` | `https://sdkapi.trodo.ai` | API base URL |
117
+ | `debug` | `bool` | `False` | Log API requests/responses |
118
+ | `auto_events` | `bool` | `False` | Hook `sys.excepthook` + `threading.excepthook` |
119
+ | `retries` | `int` | `3` | HTTP retry attempts on 5xx errors |
120
+ | `timeout` | `int` | `10` | HTTP timeout in seconds |
121
+ | `batch_enabled` | `bool` | `False` | Queue events and flush in bulk |
122
+ | `batch_size` | `int` | `50` | Max events per batch flush |
123
+ | `batch_flush_interval` | `float` | `5.0` | Flush interval in seconds |
124
+ | `on_error` | `callable` | `None` | Callback for SDK errors |
125
+
126
+ ### `trodo.for_user(distinct_id, session_id=None)`
127
+
128
+ Returns a user-bound context. All subsequent calls use this user's session.
129
+
130
+ ```python
131
+ user = trodo.for_user(
132
+ 'user-123',
133
+ session_id=request.cookies.get('trodo_session'), # optional: correlate with browser session
134
+ )
135
+ ```
136
+
137
+ ### User Context Methods
138
+
139
+ ```python
140
+ user.track(event_name, properties=None) # Track custom event
141
+ user.track_event(event_name, properties=None) # Alias for track()
142
+ user.identify(identify_id) # Merge identity
143
+ user.wallet_address(address) # Set crypto wallet address
144
+ user.reset() # Clear session context
145
+ user.capture_error(exception) # Track server_error event
146
+
147
+ # People profile
148
+ user.people.set(properties)
149
+ user.people.set_once(properties)
150
+ user.people.unset(keys)
151
+ user.people.increment(properties)
152
+ user.people.append(properties)
153
+ user.people.union(properties)
154
+ user.people.remove(properties)
155
+ user.people.track_charge(amount, properties=None)
156
+ user.people.clear_charges()
157
+ user.people.delete_user()
158
+
159
+ # Groups
160
+ user.set_group(group_key, group_id)
161
+ user.add_group(group_key, group_id)
162
+ user.remove_group(group_key, group_id)
163
+ group = user.get_group(group_key, group_id)
164
+ group.set(properties)
165
+ group.set_once(properties)
166
+ group.union(properties)
167
+ group.remove(properties)
168
+ group.unset(keys)
169
+ group.increment(properties)
170
+ group.append(properties)
171
+ group.delete()
172
+ ```
173
+
174
+ ### Direct Call Pattern (for pipelines/scripts)
175
+
176
+ ```python
177
+ trodo.track('user-123', 'event_name', {'key': 'value'})
178
+ trodo.identify('user-123', 'identify_id')
179
+ trodo.people_set('user-123', {'plan': 'pro'})
180
+ trodo.set_group('user-123', 'company', 'acme')
181
+ ```
182
+
183
+ ### Global Methods
184
+
185
+ ```python
186
+ trodo.enable_auto_events() # Enable sys.excepthook hooks
187
+ trodo.disable_auto_events() # Disable hooks
188
+ trodo.flush() # Flush pending batch queue
189
+ trodo.shutdown() # Flush + stop background timers
190
+ ```
191
+
192
+ ## Auto Events
193
+
194
+ When `auto_events=True`, the SDK wraps Python's exception hooks and sends `server_error` events to Trodo:
195
+
196
+ - `sys.excepthook` — unhandled exceptions in the main thread
197
+ - `threading.excepthook` — unhandled exceptions in threads
198
+
199
+ These events use `distinct_id: 'server_global'` in the dashboard.
200
+
201
+ Per-user error capture: `user.capture_error(e)` uses the user's own `distinct_id`.
202
+
203
+ ## Batching
204
+
205
+ ```python
206
+ trodo.init(
207
+ site_id='your-site-id',
208
+ batch_enabled=True,
209
+ batch_size=100,
210
+ batch_flush_interval=3.0,
211
+ )
212
+
213
+ # Events are queued and flushed every 3s or when 100 events accumulate
214
+ user.track('page_view')
215
+
216
+ # Always flush before process exit
217
+ import atexit
218
+ atexit.register(trodo.shutdown)
219
+ ```
220
+
221
+ ## Thread Safety
222
+
223
+ The SDK is thread-safe. `SessionManager`, `EventQueue`, and `BatchFlusher` all use `threading.Lock` internally. Safe to use in multi-threaded Flask/Django/FastAPI applications.
224
+
225
+ ## License
226
+
227
+ ISC