pettracer-client 0.1.0__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.
@@ -0,0 +1,5 @@
1
+ # PetTracer API Credentials
2
+ # Copy this file to .env and fill in your credentials
3
+
4
+ PETTRACER_USERNAME=your_username_here
5
+ PETTRACER_PASSWORD=your_password_here
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Richard Giles
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements-dev.txt
4
+ include .env.example
5
+ recursive-include examples *.py
6
+ recursive-include tests *.py
7
+ global-exclude __pycache__
8
+ global-exclude *.py[co]
@@ -0,0 +1,364 @@
1
+ Metadata-Version: 2.4
2
+ Name: pettracer-client
3
+ Version: 0.1.0
4
+ Summary: Python client library for the PetTracer GPS pet collar portal
5
+ Author-email: Richard Giles <git@egilius.net>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/AmbientArchitect/petTracer-API
8
+ Project-URL: Documentation, https://github.com/AmbientArchitect/petTracer-API#readme
9
+ Project-URL: Repository, https://github.com/AmbientArchitect/petTracer-API
10
+ Project-URL: Issues, https://github.com/AmbientArchitect/petTracer-API/issues
11
+ Keywords: pettracer,gps,pet,tracker,collar,api,client
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Topic :: Home Automation
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.12
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: requests>=2.31.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=7.4.0; extra == "dev"
27
+ Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # PetTracer API Client
31
+
32
+ [![PyPI version](https://badge.fury.io/py/pettracer-client.svg)](https://badge.fury.io/py/pettracer-client)
33
+ [![Python](https://img.shields.io/pypi/pyversions/pettracer-client.svg)](https://pypi.org/project/pettracer-client/)
34
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
35
+ [![Status](https://img.shields.io/pypi/status/pettracer-client.svg)](https://pypi.org/project/pettracer-client/)
36
+
37
+ Python client library for the [PetTracer](https://www.pettracer.com) GPS pet collar portal. Provides a clean, object-oriented interface for managing devices, tracking positions, and accessing user information.
38
+
39
+ **Note:** This is an unofficial API derived from the petTracer web site. Use with caution and respect for their service. You need to own a pet collar, have an account and paid subscription for this client to be useful.
40
+
41
+ ## Features
42
+
43
+ - ๐ŸŽฏ **Object-oriented design** - Clean class hierarchy for intuitive API usage
44
+ - ๐Ÿ” **Automatic authentication** - Login once, use everywhere
45
+ - ๐Ÿ“ **Position tracking** - Fetch device locations with time-range filtering
46
+ - ๐Ÿ‘ค **User management** - Access profile and subscription information
47
+ - ๐Ÿพ **Device management** - Control and monitor multiple pet collars
48
+ - ๐Ÿ“Š **Typed data models** - Full dataclass support for all responses
49
+ - โœ… **Well tested** - Comprehensive test suite included
50
+
51
+ ## Installation
52
+
53
+ Install from PyPI:
54
+
55
+ ```bash
56
+ pip install pettracer-client
57
+ ```
58
+
59
+ Or install the required dependencies for development:
60
+
61
+ ```bash
62
+ pip install requests
63
+ ```
64
+
65
+ For development:
66
+
67
+ ```bash
68
+ pip install -r requirements-dev.txt
69
+ ```
70
+
71
+ ## Quick Start
72
+
73
+ ```python
74
+ from pettracer import PetTracerClient
75
+
76
+ # Create client and authenticate
77
+ client = PetTracerClient()
78
+ client.login("your_username", "your_password")
79
+
80
+ # Access user information (cached from login)
81
+ print(f"Welcome, {client.user_name}!")
82
+ print(f"You have {client.device_count} device(s)")
83
+ print(f"Subscription expires: {client.subscription_expires}")
84
+
85
+ # Get all devices
86
+ devices = client.get_all_devices()
87
+ for device in devices:
88
+ print(f"{device.details.name}: Battery {device.bat}mV")
89
+
90
+ # Work with a specific device
91
+ pet_device = client.get_device(devices[0].id)
92
+ positions = pet_device.get_positions(
93
+ filter_time=1767152926491, # Unix timestamp in milliseconds
94
+ to_time=1767174526491
95
+ )
96
+ ```
97
+
98
+ For a complete working example, see [examples/class_based_example.py](examples/class_based_example.py).
99
+
100
+ ## Architecture
101
+
102
+ The library uses a two-tier class architecture:
103
+
104
+ ### Client Hierarchy
105
+
106
+ ```
107
+ PetTracerClient (user-level operations)
108
+ โ”œโ”€โ”€ Authentication & session management
109
+ โ”œโ”€โ”€ User profile & subscription info
110
+ โ””โ”€โ”€ Device discovery
111
+ โ””โ”€โ”€ PetTracerDevice (device-specific operations)
112
+ โ”œโ”€โ”€ Device information
113
+ โ””โ”€โ”€ Position history
114
+ ```
115
+
116
+ ### Key Classes
117
+
118
+ #### `PetTracerClient`
119
+
120
+ The main entry point for all API operations. Manages authentication and provides access to user-level functionality.
121
+
122
+ **Initialization:**
123
+ ```python
124
+ # Standard login
125
+ client = PetTracerClient()
126
+ client.login(username, password)
127
+
128
+ # Auto-login on creation
129
+ client = PetTracerClient(username, password)
130
+ ```
131
+
132
+ **Core Methods:**
133
+ - `login(username, password)` - Authenticate and store credentials
134
+ - `get_all_devices()` - Retrieve all devices owned by the user
135
+ - `get_device(device_id)` - Get a device-specific client
136
+ - `get_user_profile()` - Fetch detailed user profile (updates cached data)
137
+
138
+ **Authentication:**
139
+ - `is_authenticated` - Check if logged in
140
+ - `token` - Current bearer token
141
+ - `token_expires` - Token expiration datetime
142
+ - `session` - Requests session object
143
+
144
+ **User Information (available after login):**
145
+ - `user_id`, `user_name`, `email`
146
+ - `partner_id`, `language`
147
+ - `country`, `country_id`
148
+ - `device_count` - Number of devices
149
+
150
+ **Subscription:**
151
+ - `subscription_id` - Subscription identifier
152
+ - `subscription_expires` - Expiration date
153
+ - `subscription_info` - Full `SubscriptionInfo` object
154
+
155
+ **Raw Data:**
156
+ - `login_info` - Complete `LoginInfo` dataclass with all login response data
157
+
158
+ #### `PetTracerDevice`
159
+
160
+ Represents a single pet tracker device. Created via `client.get_device(device_id)`.
161
+
162
+ **Methods:**
163
+ - `get_info()` - Fetch current device information
164
+ - `get_positions(filter_time, to_time)` - Get position history within time range
165
+
166
+ **Properties:**
167
+ - `device_id` - The device identifier
168
+
169
+ **Time Parameters:**
170
+ Position history methods use Unix timestamps in milliseconds:
171
+ ```python
172
+ from datetime import datetime, timedelta
173
+
174
+ now = datetime.now()
175
+ yesterday = now - timedelta(days=1)
176
+
177
+ positions = device.get_positions(
178
+ filter_time=int(yesterday.timestamp() * 1000),
179
+ to_time=int(now.timestamp() * 1000)
180
+ )
181
+ ```
182
+
183
+ ## Data Models
184
+
185
+ All API responses are parsed into typed dataclasses for easy access and IDE autocomplete support.
186
+
187
+ ### Core Types
188
+
189
+ **`Device`** - Complete device information:
190
+ - `id`, `bat` (battery), `status`, `mode`
191
+ - `details` - `Details` object with name, image, birth date
192
+ - `lastPos` - `LastPos` object with most recent position
193
+ - `masterHs` - Master home station information
194
+ - `lastContact`, `homeSince` - Timestamps
195
+ - Many more fields for device state
196
+
197
+ **`LastPos`** - Position data:
198
+ - `posLat`, `posLong` - Coordinates
199
+ - `timeMeasure`, `timeDb` - Timestamps
200
+ - `sat` - Satellite count
201
+ - `rssi` - Signal strength
202
+ - `fixS`, `fixP`, `horiPrec` - GPS quality metrics
203
+ - `acc` - Accuracy
204
+ - `flags` - Status flags
205
+
206
+ **`Details`** - Device/pet details:
207
+ - `name` - Pet name
208
+ - `birth` - Birth date
209
+ - `image`, `img` - Image references
210
+ - `color` - Color code
211
+
212
+ **`UserProfile`** - User account information:
213
+ - `id`, `email`, `name`
214
+ - `street`, `street2`, `zip`, `city`
215
+ - `mobile`, `lang`, `country_id`
216
+ - Additional profile fields
217
+
218
+ **`LoginInfo`** - Complete login response data:
219
+ - User identification and account details
220
+ - Authentication tokens and expiration
221
+ - Subscription information via `abo` field
222
+ - Settings and preferences
223
+
224
+ **`SubscriptionInfo`** - Subscription details:
225
+ - `id`, `userId`, `odooId`
226
+ - `dateExpires` - Expiration date
227
+ - `paypalSubscriptionId`
228
+ - Raw subscription dict
229
+
230
+ ### Working with Data
231
+
232
+ ```python
233
+ # Device information
234
+ device = devices[0]
235
+ print(f"Pet: {device.details.name}")
236
+ print(f"Battery: {device.bat}mV")
237
+ print(f"Last seen: {device.lastContact}")
238
+
239
+ if device.lastPos:
240
+ print(f"Location: {device.lastPos.posLat}, {device.lastPos.posLong}")
241
+ print(f"Satellites: {device.lastPos.sat}")
242
+ print(f"Time: {device.lastPos.timeMeasure}")
243
+
244
+ # Position history
245
+ for pos in positions:
246
+ print(f"{pos.timeMeasure}: ({pos.posLat}, {pos.posLong})")
247
+ print(f" Accuracy: {pos.acc}m, Satellites: {pos.sat}")
248
+
249
+ # User profile
250
+ profile = client.get_user_profile()
251
+ print(f"{profile.name} - {profile.email}")
252
+ print(f"{profile.city}, {profile.zip}")
253
+ ```
254
+
255
+ ## Example Application
256
+
257
+ See [examples/class_based_example.py](examples/class_based_example.py) for a complete working example that demonstrates:
258
+
259
+ - Client initialization and login
260
+ - Accessing user information and subscription details
261
+ - Fetching and displaying all devices
262
+ - Working with device-specific clients
263
+ - Retrieving position history with time ranges
264
+ - Error handling and data validation
265
+
266
+ Run the example:
267
+ ```bash
268
+ export PETTRACER_USERNAME="your_username"
269
+ export PETTRACER_PASSWORD="your_password"
270
+ python examples/class_based_example.py
271
+ ```
272
+
273
+ ## Security
274
+
275
+ โš ๏ธ **Important:** Authentication tokens are secrets. Always:
276
+
277
+ - Store credentials in environment variables or secure vaults
278
+ - Never commit tokens or passwords to version control
279
+ - Use `.env` files (which are gitignored) for local development
280
+ - Rotate tokens regularly
281
+
282
+ The client supports token storage via environment variable:
283
+ ```python
284
+ import os
285
+ os.environ['PETTRACER_TOKEN'] = 'your_token_here'
286
+ ```
287
+
288
+ ## Testing
289
+
290
+ Run the comprehensive test suite:
291
+
292
+ ```bash
293
+ # Install test dependencies
294
+ pip install -r requirements-dev.txt
295
+
296
+ # Run all tests
297
+ pytest -v
298
+
299
+ # Run specific test file
300
+ pytest tests/test_client.py -v
301
+
302
+ # Run with coverage
303
+ pytest --cov=pettracer tests/
304
+ ```
305
+
306
+ The test suite uses `pytest` with `monkeypatch` to mock HTTP responses, ensuring tests run without actual API calls.
307
+
308
+ ## VS Code Setup
309
+
310
+ This workspace is pre-configured for VS Code development. See [VSCODE_GUIDE.md](VSCODE_GUIDE.md) for detailed instructions.
311
+
312
+ ### Quick Start in VS Code
313
+
314
+ 1. Copy `.env.example` to `.env` and add your credentials
315
+ 2. Open `examples/class_based_example.py`
316
+ 3. Press `F5` to run with debugging
317
+ 4. Choose **"Python: Run with .env"**
318
+
319
+ The workspace includes:
320
+ - Launch configurations for debugging
321
+ - Automatic PYTHONPATH setup in terminals
322
+ - pytest test discovery and debugging
323
+ - Python interpreter configuration
324
+
325
+ ## Development
326
+
327
+ ### Project Structure
328
+
329
+ ```
330
+ pettracer/
331
+ โ”œโ”€โ”€ __init__.py # Package exports
332
+ โ”œโ”€โ”€ client.py # PetTracerClient and PetTracerDevice classes
333
+ โ””โ”€โ”€ types.py # Dataclass definitions
334
+
335
+ examples/
336
+ โ””โ”€โ”€ class_based_example.py # Complete usage example
337
+
338
+ tests/
339
+ โ””โ”€โ”€ test_client.py # Test suite
340
+
341
+ .vscode/
342
+ โ”œโ”€โ”€ settings.json # VS Code configuration
343
+ โ””โ”€โ”€ launch.json # Debug configurations
344
+ ```
345
+
346
+ ### Contributing
347
+
348
+ Contributions are welcome! Please:
349
+
350
+ 1. Fork the repository
351
+ 2. Create a feature branch
352
+ 3. Add tests for new functionality
353
+ 4. Ensure all tests pass
354
+ 5. Submit a pull request
355
+
356
+ Issues and feature requests can be submitted via GitHub Issues.
357
+
358
+ ## License
359
+
360
+ See repository for license information.
361
+
362
+ ---
363
+
364
+ **Note:** This is an unofficial client library. PetTracerยฎ is a trademark of its respective owner.