kwslib 0.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.
kwslib-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,342 @@
1
+ Metadata-Version: 2.4
2
+ Name: kwslib
3
+ Version: 0.0.1
4
+ Summary: Python client library for KWS Platform API
5
+ Home-page: https://github.com/your-org/kwslib
6
+ Author: Ngoc An Lam
7
+ Author-email:
8
+ License: MIT
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Requires-Python: >=3.8
18
+ Description-Content-Type: text/markdown
19
+ Requires-Dist: requests>=2.28.0
20
+ Requires-Dist: minio>=7.1.0
21
+ Requires-Dist: numpy>=1.21.0
22
+ Requires-Dist: tensorflow>=2.10.0
23
+ Requires-Dist: scikit-learn>=1.0.0
24
+ Requires-Dist: matplotlib>=3.5.0
25
+ Requires-Dist: seaborn>=0.12.0
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
28
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
29
+ Requires-Dist: black>=22.0.0; extra == "dev"
30
+ Requires-Dist: flake8>=5.0.0; extra == "dev"
31
+ Dynamic: home-page
32
+ Dynamic: requires-python
33
+
34
+ # KWS Library (kwslib)
35
+
36
+ Python client library for interacting with the KWS Platform backend API.
37
+
38
+ ## Features
39
+
40
+ - **Complete API Coverage**: Wraps all backend API endpoints
41
+ - **MinIO Integration**: Download .wav and .npz files for training
42
+ - **Telegram Notifications**: Optional notifications for training jobs
43
+ - **Easy to Use**: Simple, intuitive API design
44
+ - **Type Hints**: Full type annotations for better IDE support
45
+
46
+ ## Installation
47
+
48
+ ```bash
49
+ pip install kwslib
50
+ ```
51
+
52
+ Or from source:
53
+
54
+ ```bash
55
+ git clone <repository>
56
+ cd KWS_Lib
57
+ pip install -e .
58
+ ```
59
+
60
+ ## Quick Start
61
+
62
+ ### Basic Usage
63
+
64
+ ```python
65
+ from kwslib import KWSClient
66
+
67
+ # Initialize client
68
+ client = KWSClient(base_url="http://localhost:8000")
69
+
70
+ # Login
71
+ client.login(username="admin", password="password")
72
+
73
+ # List datasets
74
+ datasets = client.datasets.list()
75
+ print(f"Found {datasets['total']} datasets")
76
+
77
+ # Get dataset details
78
+ dataset = client.datasets.get(dataset_id=1)
79
+ print(f"Dataset: {dataset['name']}")
80
+ ```
81
+
82
+ ### Download Dataset Split Files for Training
83
+
84
+ ```python
85
+ from kwslib import KWSClient, DatasetSplitFilesClient
86
+
87
+ # Initialize API client
88
+ api = KWSClient(base_url="http://localhost:8000")
89
+ api.login(username="admin", password="password")
90
+
91
+ # Initialize files client (uses API, no direct MinIO connection)
92
+ files_client = DatasetSplitFilesClient(api)
93
+
94
+ # List all files in split
95
+ files_info = files_client.list_files(split_id=1, file_type="npz")
96
+ print(f"Found {files_info['total_files']} files")
97
+
98
+ # Download all .npz files
99
+ files_client.download_all_npz(
100
+ split_id=1,
101
+ output_dir="features"
102
+ )
103
+
104
+ # Download all .wav files
105
+ files_client.download_all_wav(
106
+ split_id=1,
107
+ output_dir="audio"
108
+ )
109
+
110
+ # Or download as ZIP
111
+ files_client.download_all_files_zip(
112
+ split_id=1,
113
+ file_type="npz",
114
+ output_path="features.zip"
115
+ )
116
+
117
+ # Get presigned URLs (for Google Colab)
118
+ urls = files_client.get_file_urls(split_id=1, file_type="npz")
119
+ for file_info in urls["files"]:
120
+ print(f"{file_info['file_name']}: {file_info['url']}")
121
+ ```
122
+
123
+ ### With Telegram Notifications
124
+
125
+ ```python
126
+ from kwslib import KWSClient, TelegramNotifier
127
+
128
+ # Initialize
129
+ client = KWSClient(base_url="http://localhost:8000")
130
+ client.login(username="admin", password="password")
131
+
132
+ notifier = TelegramNotifier(
133
+ bot_token="YOUR_BOT_TOKEN",
134
+ chat_id="YOUR_CHAT_ID"
135
+ )
136
+
137
+ # Create experiment run
138
+ run = client.experiments.create_run(
139
+ experiment_id=1,
140
+ name="Training Run 1",
141
+ model_id=1,
142
+ dataset_split_id=1
143
+ )
144
+
145
+ # Wait for completion
146
+ job_id = run.get("job_id")
147
+ status = client.jobs.wait_for_completion(job_id)
148
+
149
+ # Send notification
150
+ if status["status"] == "completed":
151
+ notifier.send(f"Training completed! Results: {status['result']}")
152
+ else:
153
+ notifier.send(f"Training failed: {status.get('error')}")
154
+ ```
155
+
156
+ ## API Modules
157
+
158
+ ### Authentication
159
+ - `client.auth.login()` - Login
160
+ - `client.auth.logout()` - Logout
161
+ - `client.auth.get_me()` - Get current user info
162
+
163
+ ### Datasets
164
+ - `client.datasets.list()` - List datasets
165
+ - `client.datasets.get()` - Get dataset
166
+ - `client.datasets.create()` - Create dataset
167
+ - `client.datasets.update()` - Update dataset
168
+ - `client.datasets.delete()` - Delete dataset
169
+ - `client.datasets.list_versions()` - List versions
170
+ - `client.datasets.create_version()` - Create version
171
+
172
+ ### Models
173
+ - `client.models.list()` - List models
174
+ - `client.models.get()` - Get model
175
+ - `client.models.create()` - Create model
176
+ - `client.models.list_model_inits()` - List model architectures
177
+
178
+ ### Experiments
179
+ - `client.experiments.list()` - List experiments
180
+ - `client.experiments.create()` - Create experiment
181
+ - `client.experiments.create_run()` - Create experiment run
182
+ - `client.experiments.list_runs()` - List experiment runs
183
+
184
+ ### Dataset Splits
185
+ - `client.dataset_splits.list()` - List splits
186
+ - `client.dataset_splits.create()` - Create split
187
+ - `client.dataset_splits.download()` - Download split as ZIP
188
+ - `client.dataset_splits.generate()` - Generate split
189
+
190
+ ### Audio
191
+ - `client.audio.list_keyword_samples()` - List keyword audio
192
+ - `client.audio.upload_keyword_sample()` - Upload audio
193
+ - `client.audio.get_keyword_sample_url()` - Get presigned URL
194
+
195
+ ### Features
196
+ - `client.features.get_keyword_features()` - Get features
197
+ - `client.features.extract_keyword_features()` - Extract features
198
+
199
+ ### Jobs
200
+ - `client.jobs.get()` - Get job status
201
+ - `client.jobs.list()` - List jobs
202
+ - `client.jobs.wait_for_completion()` - Wait for job completion
203
+
204
+ ### Dataset Split Files Client
205
+ - `files_client.list_files()` - List all files in split
206
+ - `files_client.download_wav()` - Download a .wav file
207
+ - `files_client.download_npz()` - Download and load a .npz file
208
+ - `files_client.download_all_wav()` - Download all .wav files
209
+ - `files_client.download_all_npz()` - Download all .npz files
210
+ - `files_client.download_all_files_zip()` - Download all files as ZIP
211
+ - `files_client.get_file_urls()` - Get presigned URLs for all files
212
+
213
+ ### Telegram Notifier
214
+ - `notifier.send()` - Send message
215
+ - `notifier.send_file()` - Send file
216
+ - `notifier.send_photo()` - Send photo
217
+
218
+ ## Examples
219
+
220
+ ### Complete Training Workflow
221
+
222
+ ```python
223
+ from kwslib import KWSClient, DatasetSplitFilesClient, TelegramNotifier
224
+
225
+ # Setup
226
+ api = KWSClient(base_url="http://localhost:8000")
227
+ api.login(username="admin", password="password")
228
+
229
+ files_client = DatasetSplitFilesClient(api)
230
+
231
+ notifier = TelegramNotifier(
232
+ bot_token="YOUR_TOKEN",
233
+ chat_id="YOUR_CHAT_ID"
234
+ )
235
+
236
+ # 1. Create dataset split
237
+ split = api.dataset_splits.create(
238
+ dataset_version_id=1,
239
+ name="train_split",
240
+ config_name="train",
241
+ seed=42,
242
+ split_option="fixed",
243
+ fixed_count=1000,
244
+ keyword_ids=[1, 2, 3]
245
+ )
246
+
247
+ split_id = split["dataset_splits_id"]
248
+
249
+ # 2. Generate split
250
+ job = api.dataset_splits.generate(split_id)
251
+ job_id = job["job_id"]
252
+
253
+ # 3. Wait for completion
254
+ status = api.jobs.wait_for_completion(job_id)
255
+ notifier.send(f"Split generation: {status['status']}")
256
+
257
+ # 4. Download features (via API, no direct MinIO access)
258
+ features_dir = f"features/split_{split_id}"
259
+ files_client.download_all_npz(
260
+ split_id=split_id,
261
+ output_dir=features_dir
262
+ )
263
+
264
+ # 5. Create experiment run
265
+ run = api.experiments.create_run(
266
+ experiment_id=1,
267
+ name="Training Run",
268
+ model_id=1,
269
+ dataset_split_id=split_id
270
+ )
271
+
272
+ notifier.send(f"Training started: {run['name']}")
273
+ ```
274
+
275
+ ### Google Colab Usage
276
+
277
+ ```python
278
+ # In Google Colab, use presigned URLs for direct download
279
+ from kwslib import KWSClient, DatasetSplitFilesClient
280
+
281
+ api = KWSClient(base_url="https://your-api.com")
282
+ api.login(username="admin", password="password")
283
+
284
+ files_client = DatasetSplitFilesClient(api)
285
+
286
+ # Get presigned URLs
287
+ urls = files_client.get_file_urls(split_id=1, file_type="npz")
288
+
289
+ # Download in Colab
290
+ import urllib.request
291
+ for file_info in urls["files"]:
292
+ urllib.request.urlretrieve(
293
+ file_info["url"],
294
+ f"/content/{file_info['file_name']}"
295
+ )
296
+ ```
297
+
298
+ ### Google Colab Usage
299
+
300
+ ```python
301
+ # In Google Colab, use presigned URLs for direct download
302
+ from kwslib import KWSClient, DatasetSplitFilesClient
303
+
304
+ api = KWSClient(base_url="https://your-api.com")
305
+ api.login(username="admin", password="password")
306
+
307
+ files_client = DatasetSplitFilesClient(api)
308
+
309
+ # Get presigned URLs
310
+ urls = files_client.get_file_urls(split_id=1, file_type="npz")
311
+
312
+ # Download in Colab
313
+ import urllib.request
314
+ for file_info in urls["files"]:
315
+ urllib.request.urlretrieve(
316
+ file_info["url"],
317
+ f"/content/{file_info['file_name']}"
318
+ )
319
+ ```
320
+
321
+ ## Configuration
322
+
323
+ ### Environment Variables
324
+
325
+ You can set default values using environment variables:
326
+
327
+ ```bash
328
+ export KWS_BASE_URL="http://localhost:8000"
329
+ export KWS_USERNAME="admin"
330
+ export KWS_PASSWORD="password"
331
+ export MINIO_ENDPOINT="localhost:9000"
332
+ export MINIO_ACCESS_KEY="minioadmin"
333
+ export MINIO_SECRET_KEY="minioadmin"
334
+ ```
335
+
336
+ ## License
337
+
338
+ MIT License
339
+
340
+ ## Contributing
341
+
342
+ Contributions are welcome! Please open an issue or submit a pull request.
kwslib-0.0.1/README.md ADDED
@@ -0,0 +1,309 @@
1
+ # KWS Library (kwslib)
2
+
3
+ Python client library for interacting with the KWS Platform backend API.
4
+
5
+ ## Features
6
+
7
+ - **Complete API Coverage**: Wraps all backend API endpoints
8
+ - **MinIO Integration**: Download .wav and .npz files for training
9
+ - **Telegram Notifications**: Optional notifications for training jobs
10
+ - **Easy to Use**: Simple, intuitive API design
11
+ - **Type Hints**: Full type annotations for better IDE support
12
+
13
+ ## Installation
14
+
15
+ ```bash
16
+ pip install kwslib
17
+ ```
18
+
19
+ Or from source:
20
+
21
+ ```bash
22
+ git clone <repository>
23
+ cd KWS_Lib
24
+ pip install -e .
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ### Basic Usage
30
+
31
+ ```python
32
+ from kwslib import KWSClient
33
+
34
+ # Initialize client
35
+ client = KWSClient(base_url="http://localhost:8000")
36
+
37
+ # Login
38
+ client.login(username="admin", password="password")
39
+
40
+ # List datasets
41
+ datasets = client.datasets.list()
42
+ print(f"Found {datasets['total']} datasets")
43
+
44
+ # Get dataset details
45
+ dataset = client.datasets.get(dataset_id=1)
46
+ print(f"Dataset: {dataset['name']}")
47
+ ```
48
+
49
+ ### Download Dataset Split Files for Training
50
+
51
+ ```python
52
+ from kwslib import KWSClient, DatasetSplitFilesClient
53
+
54
+ # Initialize API client
55
+ api = KWSClient(base_url="http://localhost:8000")
56
+ api.login(username="admin", password="password")
57
+
58
+ # Initialize files client (uses API, no direct MinIO connection)
59
+ files_client = DatasetSplitFilesClient(api)
60
+
61
+ # List all files in split
62
+ files_info = files_client.list_files(split_id=1, file_type="npz")
63
+ print(f"Found {files_info['total_files']} files")
64
+
65
+ # Download all .npz files
66
+ files_client.download_all_npz(
67
+ split_id=1,
68
+ output_dir="features"
69
+ )
70
+
71
+ # Download all .wav files
72
+ files_client.download_all_wav(
73
+ split_id=1,
74
+ output_dir="audio"
75
+ )
76
+
77
+ # Or download as ZIP
78
+ files_client.download_all_files_zip(
79
+ split_id=1,
80
+ file_type="npz",
81
+ output_path="features.zip"
82
+ )
83
+
84
+ # Get presigned URLs (for Google Colab)
85
+ urls = files_client.get_file_urls(split_id=1, file_type="npz")
86
+ for file_info in urls["files"]:
87
+ print(f"{file_info['file_name']}: {file_info['url']}")
88
+ ```
89
+
90
+ ### With Telegram Notifications
91
+
92
+ ```python
93
+ from kwslib import KWSClient, TelegramNotifier
94
+
95
+ # Initialize
96
+ client = KWSClient(base_url="http://localhost:8000")
97
+ client.login(username="admin", password="password")
98
+
99
+ notifier = TelegramNotifier(
100
+ bot_token="YOUR_BOT_TOKEN",
101
+ chat_id="YOUR_CHAT_ID"
102
+ )
103
+
104
+ # Create experiment run
105
+ run = client.experiments.create_run(
106
+ experiment_id=1,
107
+ name="Training Run 1",
108
+ model_id=1,
109
+ dataset_split_id=1
110
+ )
111
+
112
+ # Wait for completion
113
+ job_id = run.get("job_id")
114
+ status = client.jobs.wait_for_completion(job_id)
115
+
116
+ # Send notification
117
+ if status["status"] == "completed":
118
+ notifier.send(f"Training completed! Results: {status['result']}")
119
+ else:
120
+ notifier.send(f"Training failed: {status.get('error')}")
121
+ ```
122
+
123
+ ## API Modules
124
+
125
+ ### Authentication
126
+ - `client.auth.login()` - Login
127
+ - `client.auth.logout()` - Logout
128
+ - `client.auth.get_me()` - Get current user info
129
+
130
+ ### Datasets
131
+ - `client.datasets.list()` - List datasets
132
+ - `client.datasets.get()` - Get dataset
133
+ - `client.datasets.create()` - Create dataset
134
+ - `client.datasets.update()` - Update dataset
135
+ - `client.datasets.delete()` - Delete dataset
136
+ - `client.datasets.list_versions()` - List versions
137
+ - `client.datasets.create_version()` - Create version
138
+
139
+ ### Models
140
+ - `client.models.list()` - List models
141
+ - `client.models.get()` - Get model
142
+ - `client.models.create()` - Create model
143
+ - `client.models.list_model_inits()` - List model architectures
144
+
145
+ ### Experiments
146
+ - `client.experiments.list()` - List experiments
147
+ - `client.experiments.create()` - Create experiment
148
+ - `client.experiments.create_run()` - Create experiment run
149
+ - `client.experiments.list_runs()` - List experiment runs
150
+
151
+ ### Dataset Splits
152
+ - `client.dataset_splits.list()` - List splits
153
+ - `client.dataset_splits.create()` - Create split
154
+ - `client.dataset_splits.download()` - Download split as ZIP
155
+ - `client.dataset_splits.generate()` - Generate split
156
+
157
+ ### Audio
158
+ - `client.audio.list_keyword_samples()` - List keyword audio
159
+ - `client.audio.upload_keyword_sample()` - Upload audio
160
+ - `client.audio.get_keyword_sample_url()` - Get presigned URL
161
+
162
+ ### Features
163
+ - `client.features.get_keyword_features()` - Get features
164
+ - `client.features.extract_keyword_features()` - Extract features
165
+
166
+ ### Jobs
167
+ - `client.jobs.get()` - Get job status
168
+ - `client.jobs.list()` - List jobs
169
+ - `client.jobs.wait_for_completion()` - Wait for job completion
170
+
171
+ ### Dataset Split Files Client
172
+ - `files_client.list_files()` - List all files in split
173
+ - `files_client.download_wav()` - Download a .wav file
174
+ - `files_client.download_npz()` - Download and load a .npz file
175
+ - `files_client.download_all_wav()` - Download all .wav files
176
+ - `files_client.download_all_npz()` - Download all .npz files
177
+ - `files_client.download_all_files_zip()` - Download all files as ZIP
178
+ - `files_client.get_file_urls()` - Get presigned URLs for all files
179
+
180
+ ### Telegram Notifier
181
+ - `notifier.send()` - Send message
182
+ - `notifier.send_file()` - Send file
183
+ - `notifier.send_photo()` - Send photo
184
+
185
+ ## Examples
186
+
187
+ ### Complete Training Workflow
188
+
189
+ ```python
190
+ from kwslib import KWSClient, DatasetSplitFilesClient, TelegramNotifier
191
+
192
+ # Setup
193
+ api = KWSClient(base_url="http://localhost:8000")
194
+ api.login(username="admin", password="password")
195
+
196
+ files_client = DatasetSplitFilesClient(api)
197
+
198
+ notifier = TelegramNotifier(
199
+ bot_token="YOUR_TOKEN",
200
+ chat_id="YOUR_CHAT_ID"
201
+ )
202
+
203
+ # 1. Create dataset split
204
+ split = api.dataset_splits.create(
205
+ dataset_version_id=1,
206
+ name="train_split",
207
+ config_name="train",
208
+ seed=42,
209
+ split_option="fixed",
210
+ fixed_count=1000,
211
+ keyword_ids=[1, 2, 3]
212
+ )
213
+
214
+ split_id = split["dataset_splits_id"]
215
+
216
+ # 2. Generate split
217
+ job = api.dataset_splits.generate(split_id)
218
+ job_id = job["job_id"]
219
+
220
+ # 3. Wait for completion
221
+ status = api.jobs.wait_for_completion(job_id)
222
+ notifier.send(f"Split generation: {status['status']}")
223
+
224
+ # 4. Download features (via API, no direct MinIO access)
225
+ features_dir = f"features/split_{split_id}"
226
+ files_client.download_all_npz(
227
+ split_id=split_id,
228
+ output_dir=features_dir
229
+ )
230
+
231
+ # 5. Create experiment run
232
+ run = api.experiments.create_run(
233
+ experiment_id=1,
234
+ name="Training Run",
235
+ model_id=1,
236
+ dataset_split_id=split_id
237
+ )
238
+
239
+ notifier.send(f"Training started: {run['name']}")
240
+ ```
241
+
242
+ ### Google Colab Usage
243
+
244
+ ```python
245
+ # In Google Colab, use presigned URLs for direct download
246
+ from kwslib import KWSClient, DatasetSplitFilesClient
247
+
248
+ api = KWSClient(base_url="https://your-api.com")
249
+ api.login(username="admin", password="password")
250
+
251
+ files_client = DatasetSplitFilesClient(api)
252
+
253
+ # Get presigned URLs
254
+ urls = files_client.get_file_urls(split_id=1, file_type="npz")
255
+
256
+ # Download in Colab
257
+ import urllib.request
258
+ for file_info in urls["files"]:
259
+ urllib.request.urlretrieve(
260
+ file_info["url"],
261
+ f"/content/{file_info['file_name']}"
262
+ )
263
+ ```
264
+
265
+ ### Google Colab Usage
266
+
267
+ ```python
268
+ # In Google Colab, use presigned URLs for direct download
269
+ from kwslib import KWSClient, DatasetSplitFilesClient
270
+
271
+ api = KWSClient(base_url="https://your-api.com")
272
+ api.login(username="admin", password="password")
273
+
274
+ files_client = DatasetSplitFilesClient(api)
275
+
276
+ # Get presigned URLs
277
+ urls = files_client.get_file_urls(split_id=1, file_type="npz")
278
+
279
+ # Download in Colab
280
+ import urllib.request
281
+ for file_info in urls["files"]:
282
+ urllib.request.urlretrieve(
283
+ file_info["url"],
284
+ f"/content/{file_info['file_name']}"
285
+ )
286
+ ```
287
+
288
+ ## Configuration
289
+
290
+ ### Environment Variables
291
+
292
+ You can set default values using environment variables:
293
+
294
+ ```bash
295
+ export KWS_BASE_URL="http://localhost:8000"
296
+ export KWS_USERNAME="admin"
297
+ export KWS_PASSWORD="password"
298
+ export MINIO_ENDPOINT="localhost:9000"
299
+ export MINIO_ACCESS_KEY="minioadmin"
300
+ export MINIO_SECRET_KEY="minioadmin"
301
+ ```
302
+
303
+ ## License
304
+
305
+ MIT License
306
+
307
+ ## Contributing
308
+
309
+ Contributions are welcome! Please open an issue or submit a pull request.
@@ -0,0 +1,13 @@
1
+ """
2
+ KWS Library - Python client for KWS Platform API
3
+
4
+ A comprehensive Python library for interacting with the KWS Platform backend API,
5
+ including dataset management, model training, experiments, and dataset split file access.
6
+ """
7
+
8
+ from .client import KWSClient
9
+ from .minio_client import DatasetSplitFilesClient
10
+ from .telegram_notifier import TelegramNotifier
11
+
12
+ __version__ = "0.0.1"
13
+ __all__ = ["KWSClient", "DatasetSplitFilesClient", "TelegramNotifier"]