sagemaker-mlp-sdk 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.
- sagemaker_mlp_sdk-0.1.0/LICENSE +21 -0
- sagemaker_mlp_sdk-0.1.0/MANIFEST.in +9 -0
- sagemaker_mlp_sdk-0.1.0/PKG-INFO +569 -0
- sagemaker_mlp_sdk-0.1.0/README.md +519 -0
- sagemaker_mlp_sdk-0.1.0/docs/API_GUIDE.md +877 -0
- sagemaker_mlp_sdk-0.1.0/docs/CONFIGURATION_GUIDE.md +656 -0
- sagemaker_mlp_sdk-0.1.0/docs/ENCRYPTION_GUIDE.md +554 -0
- sagemaker_mlp_sdk-0.1.0/docs/SDK_V3_PARAMETER_GUIDE.md +314 -0
- sagemaker_mlp_sdk-0.1.0/docs/USAGE_EXAMPLES.md +788 -0
- sagemaker_mlp_sdk-0.1.0/examples/QUICKSTART.md +165 -0
- sagemaker_mlp_sdk-0.1.0/examples/README.md +132 -0
- sagemaker_mlp_sdk-0.1.0/examples/TRAINING_EXAMPLES.md +336 -0
- sagemaker_mlp_sdk-0.1.0/examples/basic_usage.py +157 -0
- sagemaker_mlp_sdk-0.1.0/examples/generate_admin_config.py +247 -0
- sagemaker_mlp_sdk-0.1.0/examples/sagemaker_operations.py +285 -0
- sagemaker_mlp_sdk-0.1.0/examples/xgboost_training_example.ipynb +4216 -0
- sagemaker_mlp_sdk-0.1.0/examples/xgboost_training_script.py +343 -0
- sagemaker_mlp_sdk-0.1.0/mlp_sdk/__init__.py +18 -0
- sagemaker_mlp_sdk-0.1.0/mlp_sdk/config.py +630 -0
- sagemaker_mlp_sdk-0.1.0/mlp_sdk/exceptions.py +421 -0
- sagemaker_mlp_sdk-0.1.0/mlp_sdk/models.py +62 -0
- sagemaker_mlp_sdk-0.1.0/mlp_sdk/session.py +1160 -0
- sagemaker_mlp_sdk-0.1.0/mlp_sdk/wrappers/__init__.py +11 -0
- sagemaker_mlp_sdk-0.1.0/mlp_sdk/wrappers/deployment.py +459 -0
- sagemaker_mlp_sdk-0.1.0/mlp_sdk/wrappers/feature_store.py +308 -0
- sagemaker_mlp_sdk-0.1.0/mlp_sdk/wrappers/pipeline.py +452 -0
- sagemaker_mlp_sdk-0.1.0/mlp_sdk/wrappers/processing.py +381 -0
- sagemaker_mlp_sdk-0.1.0/mlp_sdk/wrappers/training.py +492 -0
- sagemaker_mlp_sdk-0.1.0/pyproject.toml +157 -0
- sagemaker_mlp_sdk-0.1.0/sagemaker_mlp_sdk.egg-info/PKG-INFO +569 -0
- sagemaker_mlp_sdk-0.1.0/sagemaker_mlp_sdk.egg-info/SOURCES.txt +33 -0
- sagemaker_mlp_sdk-0.1.0/sagemaker_mlp_sdk.egg-info/dependency_links.txt +1 -0
- sagemaker_mlp_sdk-0.1.0/sagemaker_mlp_sdk.egg-info/requires.txt +26 -0
- sagemaker_mlp_sdk-0.1.0/sagemaker_mlp_sdk.egg-info/top_level.txt +1 -0
- sagemaker_mlp_sdk-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 [Your Name or Organization]
|
|
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,569 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sagemaker-mlp-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Python wrapper library for SageMaker SDK v3 with configuration-driven defaults
|
|
5
|
+
Author-email: Ram Vittal <rvvittal@amazon.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/aws-samples/genai-ml-platform-examples/tree/main/platform/mlp-sdk-v3
|
|
8
|
+
Project-URL: Documentation, https://github.com/aws-samples/genai-ml-platform-examples/blob/main/platform/mlp-sdk-v3/docs/
|
|
9
|
+
Project-URL: Repository, https://github.com/aws-samples/genai-ml-platform-examples/tree/main/platform/mlp-sdk-v3
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/aws-samples/genai-ml-platform-examples/issues
|
|
11
|
+
Keywords: sagemaker,aws,machine-learning,ml,sdk
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
22
|
+
Requires-Python: >=3.8
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: sagemaker>=3.0.0
|
|
26
|
+
Requires-Dist: boto3>=1.26.0
|
|
27
|
+
Requires-Dist: botocore>=1.29.0
|
|
28
|
+
Requires-Dist: pyyaml>=6.0
|
|
29
|
+
Requires-Dist: pydantic>=2.0.0
|
|
30
|
+
Requires-Dist: typing-extensions>=4.0.0
|
|
31
|
+
Requires-Dist: cryptography>=41.0.0
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-hypothesis>=6.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: black>=23.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: isort>=5.12.0; extra == "dev"
|
|
39
|
+
Requires-Dist: flake8>=6.0.0; extra == "dev"
|
|
40
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
41
|
+
Requires-Dist: moto[sagemaker]>=4.2.0; extra == "dev"
|
|
42
|
+
Requires-Dist: boto3-stubs[sagemaker]>=1.26.0; extra == "dev"
|
|
43
|
+
Provides-Extra: test
|
|
44
|
+
Requires-Dist: pytest>=7.0.0; extra == "test"
|
|
45
|
+
Requires-Dist: pytest-hypothesis>=6.0.0; extra == "test"
|
|
46
|
+
Requires-Dist: pytest-mock>=3.10.0; extra == "test"
|
|
47
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
|
|
48
|
+
Requires-Dist: moto[sagemaker]>=4.2.0; extra == "test"
|
|
49
|
+
Dynamic: license-file
|
|
50
|
+
|
|
51
|
+
> [!WARNING]
|
|
52
|
+
> This mlp_sdk_v3 example demonstrates how to develop an ML Platform SDK wrapper library, providing a way to simplify infrastructure configuration management and standardize ML workflows across teams. It is intended as a reference guide for customers to help them create their own customized SDK wrappers. Note: This library is provided for illustrative purposes only and should not be used directly in production environments.
|
|
53
|
+
>
|
|
54
|
+
# mlp_sdk_v3
|
|
55
|
+
|
|
56
|
+
A Python wrapper library for SageMaker SDK v3 with configuration-driven defaults.
|
|
57
|
+
|
|
58
|
+
## Overview
|
|
59
|
+
|
|
60
|
+
The mlp_sdk_v3 simplifies SageMaker operations by providing a session-based interface with configuration-driven defaults. Built on top of the SageMaker Python SDK v3, it abstracts infrastructure complexity while maintaining full compatibility with the underlying SDK.
|
|
61
|
+
|
|
62
|
+
### Key Features
|
|
63
|
+
|
|
64
|
+
- **Configuration-driven defaults**: Define AWS resources (VPCs, security groups, S3 buckets) in YAML configuration files
|
|
65
|
+
- **Simple session interface**: Single entry point for all SageMaker operations
|
|
66
|
+
- **Runtime parameter override**: Override any default configuration at runtime
|
|
67
|
+
- **Full SageMaker SDK compatibility**: Access underlying SageMaker SDK objects for advanced use cases
|
|
68
|
+
- **Comprehensive error handling**: Clear error messages with actionable guidance
|
|
69
|
+
- **Encryption support**: AES-256-GCM encryption for sensitive configuration values
|
|
70
|
+
- **Audit trail**: Track all operations for debugging and compliance
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install mlp_sdk_v3
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Quick Start
|
|
79
|
+
|
|
80
|
+
### Generate Configuration
|
|
81
|
+
|
|
82
|
+
First, generate your configuration file:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Interactive mode (recommended)
|
|
86
|
+
python examples/generate_admin_config.py --interactive
|
|
87
|
+
|
|
88
|
+
# Or use defaults
|
|
89
|
+
python examples/generate_admin_config.py --output /home/sagemaker-user/.config/admin-config.yaml
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
See [examples/QUICKSTART.md](examples/QUICKSTART.md) for a complete quick start guide.
|
|
93
|
+
|
|
94
|
+
### Basic Usage
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from mlp_sdk_v3 import MLP_Session
|
|
98
|
+
|
|
99
|
+
# Initialize session with default configuration
|
|
100
|
+
session = MLP_Session()
|
|
101
|
+
|
|
102
|
+
# Create a feature group
|
|
103
|
+
feature_group = session.create_feature_group(
|
|
104
|
+
feature_group_name="customer-features",
|
|
105
|
+
record_identifier_name="customer_id",
|
|
106
|
+
event_time_feature_name="event_time",
|
|
107
|
+
feature_definitions=[
|
|
108
|
+
{"FeatureName": "customer_id", "FeatureType": "String"},
|
|
109
|
+
{"FeatureName": "age", "FeatureType": "Integral"},
|
|
110
|
+
{"FeatureName": "income", "FeatureType": "Fractional"},
|
|
111
|
+
{"FeatureName": "event_time", "FeatureType": "String"}
|
|
112
|
+
]
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
# Run a processing job
|
|
116
|
+
processor = session.run_processing_job(
|
|
117
|
+
job_name="data-preprocessing",
|
|
118
|
+
processing_script="preprocess.py",
|
|
119
|
+
inputs=[{"source": "s3://my-bucket/raw-data/", "destination": "/opt/ml/processing/input"}],
|
|
120
|
+
outputs=[{"source": "/opt/ml/processing/output", "destination": "s3://my-bucket/processed-data/"}]
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
# Run a training job
|
|
124
|
+
trainer = session.run_training_job(
|
|
125
|
+
job_name="model-training",
|
|
126
|
+
training_image="763104351884.dkr.ecr.us-west-2.amazonaws.com/pytorch-training:2.0.0-cpu-py310",
|
|
127
|
+
source_code_dir="training-scripts",
|
|
128
|
+
entry_script="train.py",
|
|
129
|
+
inputs={"train": "s3://my-bucket/processed-data/"}
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
# Create a pipeline
|
|
133
|
+
from sagemaker.workflow.steps import ProcessingStep, TrainingStep
|
|
134
|
+
|
|
135
|
+
pipeline = session.create_pipeline(
|
|
136
|
+
pipeline_name="ml-workflow",
|
|
137
|
+
steps=[
|
|
138
|
+
ProcessingStep(name="preprocess", processor=processor),
|
|
139
|
+
TrainingStep(name="train", estimator=trainer)
|
|
140
|
+
]
|
|
141
|
+
)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Configuration
|
|
145
|
+
|
|
146
|
+
### Configuration File Location
|
|
147
|
+
|
|
148
|
+
By default, mlp_sdk_v3 loads configuration from:
|
|
149
|
+
```
|
|
150
|
+
/home/sagemaker-user/.config/admin-config.yaml
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
You can specify a custom configuration path:
|
|
154
|
+
```python
|
|
155
|
+
session = MLP_Session(config_path="/path/to/custom-config.yaml")
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### Configuration File Format
|
|
159
|
+
|
|
160
|
+
Create a YAML configuration file with the following structure:
|
|
161
|
+
|
|
162
|
+
```yaml
|
|
163
|
+
defaults:
|
|
164
|
+
# S3 Configuration
|
|
165
|
+
s3:
|
|
166
|
+
default_bucket: "my-sagemaker-bucket"
|
|
167
|
+
input_prefix: "input/"
|
|
168
|
+
output_prefix: "output/"
|
|
169
|
+
model_prefix: "models/"
|
|
170
|
+
|
|
171
|
+
# Networking Configuration
|
|
172
|
+
networking:
|
|
173
|
+
vpc_id: "vpc-12345678"
|
|
174
|
+
security_group_ids: ["sg-12345678"]
|
|
175
|
+
subnets: ["subnet-12345678", "subnet-87654321"]
|
|
176
|
+
|
|
177
|
+
# Compute Configuration
|
|
178
|
+
compute:
|
|
179
|
+
processing_instance_type: "ml.m5.large"
|
|
180
|
+
training_instance_type: "ml.m5.xlarge"
|
|
181
|
+
processing_instance_count: 1
|
|
182
|
+
training_instance_count: 1
|
|
183
|
+
|
|
184
|
+
# Feature Store Configuration
|
|
185
|
+
feature_store:
|
|
186
|
+
offline_store_s3_uri: "s3://my-sagemaker-bucket/feature-store/"
|
|
187
|
+
enable_online_store: false
|
|
188
|
+
|
|
189
|
+
# IAM Configuration
|
|
190
|
+
iam:
|
|
191
|
+
execution_role: "arn:aws:iam::123456789012:role/SageMakerExecutionRole"
|
|
192
|
+
|
|
193
|
+
# KMS Configuration (optional)
|
|
194
|
+
kms:
|
|
195
|
+
key_id: "arn:aws:kms:REGION:ACCOUNT-ID:key/KEY-ID"
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Configuration Precedence
|
|
199
|
+
|
|
200
|
+
Configuration values are applied in the following order (later values override earlier ones):
|
|
201
|
+
|
|
202
|
+
1. **SageMaker SDK defaults** - Built-in defaults from the SageMaker SDK
|
|
203
|
+
2. **YAML configuration** - Values from your configuration file
|
|
204
|
+
3. **Runtime parameters** - Values passed directly to method calls
|
|
205
|
+
|
|
206
|
+
Example:
|
|
207
|
+
```python
|
|
208
|
+
# This will use the training_instance_type from config (ml.m5.xlarge)
|
|
209
|
+
trainer = session.run_training_job(job_name="my-job", ...)
|
|
210
|
+
|
|
211
|
+
# This will override the config and use ml.p3.2xlarge
|
|
212
|
+
trainer = session.run_training_job(
|
|
213
|
+
job_name="my-job",
|
|
214
|
+
instance_type="ml.p3.2xlarge", # Runtime override
|
|
215
|
+
...
|
|
216
|
+
)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## Encryption Setup
|
|
220
|
+
|
|
221
|
+
mlp_sdk_v3 supports AES-256-GCM encryption for sensitive configuration values.
|
|
222
|
+
|
|
223
|
+
### Generating an Encryption Key
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
from mlp_sdk_v3.config import ConfigurationManager
|
|
227
|
+
|
|
228
|
+
# Generate a new encryption key
|
|
229
|
+
key = ConfigurationManager.generate_key()
|
|
230
|
+
print(f"Encryption key: {key}")
|
|
231
|
+
# Save this key securely!
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Loading Encryption Keys
|
|
235
|
+
|
|
236
|
+
#### From Environment Variable
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
import os
|
|
240
|
+
from mlp_sdk_v3.config import ConfigurationManager
|
|
241
|
+
|
|
242
|
+
# Set environment variable
|
|
243
|
+
os.environ['MLP_SDK_ENCRYPTION_KEY'] = 'your-base64-encoded-key'
|
|
244
|
+
|
|
245
|
+
# Load key from environment
|
|
246
|
+
key = ConfigurationManager.load_key_from_env()
|
|
247
|
+
session = MLP_Session(config_path="encrypted-config.yaml")
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
#### From File
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
from mlp_sdk_v3.config import ConfigurationManager
|
|
254
|
+
|
|
255
|
+
# Load key from file
|
|
256
|
+
key = ConfigurationManager.load_key_from_file("/path/to/keyfile")
|
|
257
|
+
config_manager = ConfigurationManager(
|
|
258
|
+
config_path="encrypted-config.yaml",
|
|
259
|
+
encryption_key=key
|
|
260
|
+
)
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
#### From AWS KMS
|
|
264
|
+
|
|
265
|
+
```python
|
|
266
|
+
from mlp_sdk_v3.config import ConfigurationManager
|
|
267
|
+
|
|
268
|
+
# Load key from KMS
|
|
269
|
+
key = ConfigurationManager.load_key_from_kms(
|
|
270
|
+
key_id="arn:aws:kms:REGION:ACCOUNT-ID:key/KEY-ID",
|
|
271
|
+
region="us-west-2"
|
|
272
|
+
)
|
|
273
|
+
config_manager = ConfigurationManager(
|
|
274
|
+
config_path="encrypted-config.yaml",
|
|
275
|
+
encryption_key=key
|
|
276
|
+
)
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Encrypting Configuration Files
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
from mlp_sdk_v3.config import ConfigurationManager
|
|
283
|
+
|
|
284
|
+
# Generate or load encryption key
|
|
285
|
+
key = ConfigurationManager.generate_key()
|
|
286
|
+
|
|
287
|
+
# Create configuration manager
|
|
288
|
+
config_manager = ConfigurationManager(encryption_key=key)
|
|
289
|
+
|
|
290
|
+
# Encrypt specific fields in configuration file
|
|
291
|
+
config_manager.encrypt_config_file(
|
|
292
|
+
input_path="plain-config.yaml",
|
|
293
|
+
output_path="encrypted-config.yaml",
|
|
294
|
+
fields_to_encrypt=[
|
|
295
|
+
"defaults.iam.execution_role",
|
|
296
|
+
"defaults.kms.key_id"
|
|
297
|
+
]
|
|
298
|
+
)
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Decrypting Configuration Files
|
|
302
|
+
|
|
303
|
+
```python
|
|
304
|
+
from mlp_sdk_v3.config import ConfigurationManager
|
|
305
|
+
|
|
306
|
+
# Load encryption key
|
|
307
|
+
key = ConfigurationManager.load_key_from_env()
|
|
308
|
+
|
|
309
|
+
# Create configuration manager
|
|
310
|
+
config_manager = ConfigurationManager(encryption_key=key)
|
|
311
|
+
|
|
312
|
+
# Decrypt specific fields
|
|
313
|
+
config_manager.decrypt_config_file(
|
|
314
|
+
input_path="encrypted-config.yaml",
|
|
315
|
+
output_path="decrypted-config.yaml",
|
|
316
|
+
fields_to_decrypt=[
|
|
317
|
+
"defaults.iam.execution_role",
|
|
318
|
+
"defaults.kms.key_id"
|
|
319
|
+
]
|
|
320
|
+
)
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
## Advanced Usage
|
|
324
|
+
|
|
325
|
+
### Accessing Underlying SageMaker SDK Objects
|
|
326
|
+
|
|
327
|
+
```python
|
|
328
|
+
session = MLP_Session()
|
|
329
|
+
|
|
330
|
+
# Access SageMaker session
|
|
331
|
+
sagemaker_session = session.sagemaker_session
|
|
332
|
+
|
|
333
|
+
# Access boto3 clients
|
|
334
|
+
s3_client = session.boto_session.client('s3')
|
|
335
|
+
sagemaker_client = session.sagemaker_client
|
|
336
|
+
runtime_client = session.sagemaker_runtime_client
|
|
337
|
+
|
|
338
|
+
# Get session properties
|
|
339
|
+
print(f"Region: {session.region_name}")
|
|
340
|
+
print(f"Account ID: {session.account_id}")
|
|
341
|
+
print(f"Default bucket: {session.default_bucket}")
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Audit Trail
|
|
345
|
+
|
|
346
|
+
Track all operations for debugging and compliance:
|
|
347
|
+
|
|
348
|
+
```python
|
|
349
|
+
# Initialize session with audit trail enabled (default)
|
|
350
|
+
session = MLP_Session(enable_audit_trail=True)
|
|
351
|
+
|
|
352
|
+
# Perform operations
|
|
353
|
+
session.create_feature_group(...)
|
|
354
|
+
session.run_processing_job(...)
|
|
355
|
+
|
|
356
|
+
# Get audit trail entries
|
|
357
|
+
entries = session.get_audit_trail(operation="create_feature_group")
|
|
358
|
+
print(f"Found {len(entries)} feature group operations")
|
|
359
|
+
|
|
360
|
+
# Get audit trail summary
|
|
361
|
+
summary = session.get_audit_trail_summary()
|
|
362
|
+
print(f"Total operations: {summary['total_entries']}")
|
|
363
|
+
print(f"Failed operations: {len(summary['failed_operations'])}")
|
|
364
|
+
|
|
365
|
+
# Export audit trail
|
|
366
|
+
session.export_audit_trail("audit-trail.json", format="json")
|
|
367
|
+
session.export_audit_trail("audit-trail.csv", format="csv")
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Logging Configuration
|
|
371
|
+
|
|
372
|
+
```python
|
|
373
|
+
import logging
|
|
374
|
+
|
|
375
|
+
# Initialize with custom log level
|
|
376
|
+
session = MLP_Session(log_level=logging.DEBUG)
|
|
377
|
+
|
|
378
|
+
# Change log level at runtime
|
|
379
|
+
session.set_log_level(logging.WARNING)
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Runtime Configuration Updates
|
|
383
|
+
|
|
384
|
+
```python
|
|
385
|
+
session = MLP_Session()
|
|
386
|
+
|
|
387
|
+
# Update session configuration at runtime
|
|
388
|
+
session.update_session_config(default_bucket="new-bucket-name")
|
|
389
|
+
|
|
390
|
+
# Get current configuration
|
|
391
|
+
config = session.get_config()
|
|
392
|
+
print(config)
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
## Error Handling
|
|
396
|
+
|
|
397
|
+
mlp_sdk_v3 provides detailed error messages with AWS error details:
|
|
398
|
+
|
|
399
|
+
```python
|
|
400
|
+
from mlp_sdk_v3 import MLP_Session, ValidationError, AWSServiceError, ConfigurationError
|
|
401
|
+
|
|
402
|
+
try:
|
|
403
|
+
session = MLP_Session()
|
|
404
|
+
feature_group = session.create_feature_group(
|
|
405
|
+
feature_group_name="", # Invalid: empty name
|
|
406
|
+
...
|
|
407
|
+
)
|
|
408
|
+
except ValidationError as e:
|
|
409
|
+
print(f"Validation error: {e}")
|
|
410
|
+
except AWSServiceError as e:
|
|
411
|
+
print(f"AWS error: {e}")
|
|
412
|
+
print(f"Error code: {e.error_code}")
|
|
413
|
+
print(f"Request ID: {e.request_id}")
|
|
414
|
+
print(f"Details: {e.get_error_details()}")
|
|
415
|
+
except ConfigurationError as e:
|
|
416
|
+
print(f"Configuration error: {e}")
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
## API Reference
|
|
420
|
+
|
|
421
|
+
### MLP_Session
|
|
422
|
+
|
|
423
|
+
Main interface for all mlp_sdk_v3 operations.
|
|
424
|
+
|
|
425
|
+
#### Methods
|
|
426
|
+
|
|
427
|
+
- `__init__(config_path=None, log_level=logging.INFO, enable_audit_trail=True, **kwargs)` - Initialize session
|
|
428
|
+
- `create_feature_group(feature_group_name, record_identifier_name, event_time_feature_name, feature_definitions, **kwargs)` - Create feature group
|
|
429
|
+
- `run_processing_job(job_name, processing_script=None, inputs=None, outputs=None, **kwargs)` - Execute processing job
|
|
430
|
+
- `run_training_job(job_name, training_image, source_code_dir=None, entry_script=None, requirements=None, inputs=None, **kwargs)` - Execute training job
|
|
431
|
+
- `create_pipeline(pipeline_name, steps, parameters=None, **kwargs)` - Create pipeline
|
|
432
|
+
- `upsert_pipeline(pipeline, **kwargs)` - Create or update pipeline
|
|
433
|
+
- `start_pipeline_execution(pipeline_name, **kwargs)` - Start pipeline execution
|
|
434
|
+
- `get_config()` - Get current configuration
|
|
435
|
+
- `get_execution_role()` - Get IAM execution role
|
|
436
|
+
- `set_log_level(level)` - Set logging level
|
|
437
|
+
- `get_audit_trail(operation=None, status=None, limit=None)` - Get audit trail entries
|
|
438
|
+
- `export_audit_trail(file_path, format='json')` - Export audit trail
|
|
439
|
+
|
|
440
|
+
#### Properties
|
|
441
|
+
|
|
442
|
+
- `sagemaker_session` - Underlying SageMaker session
|
|
443
|
+
- `boto_session` - Underlying boto3 session
|
|
444
|
+
- `sagemaker_client` - SageMaker boto3 client
|
|
445
|
+
- `sagemaker_runtime_client` - SageMaker Runtime boto3 client
|
|
446
|
+
- `region_name` - AWS region name
|
|
447
|
+
- `default_bucket` - Default S3 bucket
|
|
448
|
+
- `account_id` - AWS account ID
|
|
449
|
+
|
|
450
|
+
### ConfigurationManager
|
|
451
|
+
|
|
452
|
+
Handles configuration loading and encryption.
|
|
453
|
+
|
|
454
|
+
#### Methods
|
|
455
|
+
|
|
456
|
+
- `__init__(config_path=None, encryption_key=None)` - Initialize configuration manager
|
|
457
|
+
- `get_default(key, fallback=None)` - Get configuration value
|
|
458
|
+
- `merge_with_runtime(runtime_config)` - Merge runtime parameters with defaults
|
|
459
|
+
- `encrypt_value(plaintext, key=None)` - Encrypt a value
|
|
460
|
+
- `decrypt_value(encrypted, key=None)` - Decrypt a value
|
|
461
|
+
- `encrypt_config_file(input_path, output_path, fields_to_encrypt, key=None)` - Encrypt configuration file
|
|
462
|
+
- `decrypt_config_file(input_path, output_path, fields_to_decrypt, key=None)` - Decrypt configuration file
|
|
463
|
+
|
|
464
|
+
#### Static Methods
|
|
465
|
+
|
|
466
|
+
- `generate_key()` - Generate new encryption key
|
|
467
|
+
- `load_key_from_env(env_var='MLP_SDK_ENCRYPTION_KEY')` - Load key from environment
|
|
468
|
+
- `load_key_from_file(file_path)` - Load key from file
|
|
469
|
+
- `load_key_from_kms(key_id, region=None)` - Load key from AWS KMS
|
|
470
|
+
|
|
471
|
+
## Development
|
|
472
|
+
|
|
473
|
+
### Setup
|
|
474
|
+
|
|
475
|
+
```bash
|
|
476
|
+
# Clone the repository
|
|
477
|
+
git clone https://github.com/example/mlp_sdk_v3.git
|
|
478
|
+
cd mlp_sdk_v3
|
|
479
|
+
|
|
480
|
+
# Install in development mode with test dependencies
|
|
481
|
+
pip install -e ".[dev]"
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
### Testing
|
|
485
|
+
|
|
486
|
+
```bash
|
|
487
|
+
# Run all tests
|
|
488
|
+
pytest
|
|
489
|
+
|
|
490
|
+
# Run unit tests only
|
|
491
|
+
pytest tests/unit/
|
|
492
|
+
|
|
493
|
+
# Run property-based tests only
|
|
494
|
+
pytest tests/property/
|
|
495
|
+
|
|
496
|
+
# Run with coverage
|
|
497
|
+
pytest --cov=mlp_sdk_v3
|
|
498
|
+
|
|
499
|
+
# Run specific test file
|
|
500
|
+
pytest tests/unit/test_session.py
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
### Code Quality
|
|
504
|
+
|
|
505
|
+
```bash
|
|
506
|
+
# Format code
|
|
507
|
+
black mlp_sdk_v3 tests
|
|
508
|
+
|
|
509
|
+
# Sort imports
|
|
510
|
+
isort mlp_sdk_v3 tests
|
|
511
|
+
|
|
512
|
+
# Lint code
|
|
513
|
+
flake8 mlp_sdk_v3 tests
|
|
514
|
+
|
|
515
|
+
# Type checking
|
|
516
|
+
mypy mlp_sdk_v3
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
## Requirements
|
|
520
|
+
|
|
521
|
+
- Python >= 3.8
|
|
522
|
+
- sagemaker >= 3.0.0
|
|
523
|
+
- boto3 >= 1.26.0
|
|
524
|
+
- pyyaml >= 6.0
|
|
525
|
+
- pydantic >= 2.0.0
|
|
526
|
+
- cryptography >= 41.0.0
|
|
527
|
+
|
|
528
|
+
## License
|
|
529
|
+
|
|
530
|
+
MIT License - see LICENSE file for details.
|
|
531
|
+
|
|
532
|
+
## Contributing
|
|
533
|
+
|
|
534
|
+
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our GitHub repository.
|
|
535
|
+
|
|
536
|
+
## Support
|
|
537
|
+
|
|
538
|
+
For issues, questions, or contributions, please visit our [GitHub repository](https://github.com/example/mlp_sdk_v3).
|
|
539
|
+
|
|
540
|
+
## Examples
|
|
541
|
+
|
|
542
|
+
The `examples/` directory contains helpful scripts and guides:
|
|
543
|
+
|
|
544
|
+
- **[generate_admin_config.py](examples/generate_admin_config.py)** - Generate configuration files
|
|
545
|
+
- **[basic_usage.py](examples/basic_usage.py)** - Basic SDK usage examples
|
|
546
|
+
- **[sagemaker_operations.py](examples/sagemaker_operations.py)** - SageMaker operations examples
|
|
547
|
+
- **[xgboost_training_example.ipynb](examples/xgboost_training_example.ipynb)** - XGBoost training notebook ⭐
|
|
548
|
+
- **[xgboost_training_script.py](examples/xgboost_training_script.py)** - XGBoost training script
|
|
549
|
+
- **[QUICKSTART.md](examples/QUICKSTART.md)** - 5-minute quick start guide
|
|
550
|
+
- **[TRAINING_EXAMPLES.md](examples/TRAINING_EXAMPLES.md)** - Detailed training guide
|
|
551
|
+
- **[README.md](examples/README.md)** - Examples documentation
|
|
552
|
+
|
|
553
|
+
Run examples:
|
|
554
|
+
```bash
|
|
555
|
+
# Generate config
|
|
556
|
+
python examples/generate_admin_config.py --interactive
|
|
557
|
+
|
|
558
|
+
# Run basic examples
|
|
559
|
+
python examples/basic_usage.py
|
|
560
|
+
|
|
561
|
+
# Run SageMaker operations examples
|
|
562
|
+
python examples/sagemaker_operations.py
|
|
563
|
+
|
|
564
|
+
# Run XGBoost training (script)
|
|
565
|
+
python examples/xgboost_training_script.py --wait
|
|
566
|
+
|
|
567
|
+
# Run XGBoost training (notebook)
|
|
568
|
+
jupyter notebook examples/xgboost_training_example.ipynb
|
|
569
|
+
```
|