spot-optimizer 1.0.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,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,192 @@
1
+ Metadata-Version: 2.3
2
+ Name: spot-optimizer
3
+ Version: 1.0.0
4
+ Summary: AWS EC2 spot instance optimizer
5
+ Keywords: aws,ec2,spot,optimizer
6
+ Author: Amar Prakash
7
+ Author-email: amar.om1994@gmail.com
8
+ Requires-Python: >=3.9
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Dist: appdirs (>=1.4.4,<2.0.0)
16
+ Requires-Dist: diskcache (>=5.6.3,<6.0.0)
17
+ Requires-Dist: duckdb (>=1.1.3,<2.0.0)
18
+ Requires-Dist: pandas (>=2.2.0,<3.0.0)
19
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
20
+ Project-URL: Repository, https://github.com/amarlearning/spot-optimizer
21
+ Description-Content-Type: text/markdown
22
+
23
+ # Spot Optimizer
24
+
25
+ [![Python Tests](https://github.com/amarlearning/spot-optimizer/actions/workflows/python-tests.yml/badge.svg)](https://github.com/amarlearning/spot-optimizer/actions/workflows/python-tests.yml)
26
+
27
+ 🚀 Spot Optimizer is a Python library that helps users select the best AWS spot instances based on their resource requirements, including cores, RAM, storage type (SSD), instance architecture (x86 or ARM), AWS region, EMR version compatibility, and instance family preferences.
28
+
29
+ It replaces complex, in-house logic for finding the best spot instances with a simple and powerful abstraction. No more manual guesswork — just the right instances at the right time.
30
+
31
+ ## Why Spot Optimizer?
32
+ Managing spot instance selection within your codebase can be tedious and error-prone. Spot Optimizer provides a clean, abstracted solution to intelligently select the most stable and cost-effective instances.
33
+
34
+ ### Configuration Guarantee
35
+ It ensures that the selected configuration meets or exceeds the user's requirements. For example, if you request 20 cores and 100GB of RAM, the library will suggest a configuration with at least those resources, rounding up to the nearest available configuration.
36
+
37
+ ---
38
+
39
+ ## Key Benefits
40
+ - **💡 Informed Decisions**: Picks instances with the lowest interruption rates and the best fit for your workload.
41
+ - **🧠 Dynamic Reliability**: Smartly updates interruption rates every hour to ensure the most stable instance selection.
42
+ - **🛠️ Operational Efficiency**: No more homegrown scripts or complex logic — just plug and play.
43
+ - **⚡ High Flexibility**: Supports diverse use cases like Spark/EMR clusters, ML workloads, gaming servers, and more.
44
+ - **🏗️ Scalable and Reliable**: Automatically adjusts to changing resource needs while minimizing downtime.
45
+
46
+ ---
47
+
48
+ ## Installation
49
+
50
+ ### For Users
51
+ ```bash
52
+ pip install spot-optimizer
53
+ ```
54
+
55
+ ### For Development
56
+ ```bash
57
+ # Clone the repository
58
+ git clone git@github.com:amarlearning/spot-optimizer.git
59
+ cd spot-optimizer
60
+
61
+ # Install dependencies and set up development environment
62
+ make install
63
+ ```
64
+
65
+ ---
66
+
67
+ ## Usage
68
+
69
+ ### API Usage
70
+
71
+ ```python
72
+ from spot_optimizer import optimize
73
+
74
+ # Basic usage
75
+ result = optimize(cores=8, memory=32)
76
+
77
+ # Advanced usage with all options
78
+ result = optimize(
79
+ cores=8,
80
+ memory=32,
81
+ region="us-east-1",
82
+ ssd_only=True,
83
+ arm_instances=False,
84
+ instance_family=["m6i", "r6i"],
85
+ mode="balanced"
86
+ )
87
+
88
+ print(result)
89
+ # Output:
90
+ # {
91
+ # "instances": {
92
+ # "type": "m6i.2xlarge",
93
+ # "count": 1
94
+ # },
95
+ # "mode": "balanced",
96
+ # "total_cores": 8,
97
+ # "total_ram": 32
98
+ # }
99
+ ```
100
+
101
+ ### CLI Usage
102
+
103
+ ```bash
104
+ # Basic usage
105
+ spot-optimizer optimize --cores 8 --memory 32
106
+
107
+ # Advanced usage
108
+ spot-optimizer optimize \
109
+ --cores 8 \
110
+ --memory 32 \
111
+ --region us-east-1 \
112
+ --ssd-only \
113
+ --no-arm \
114
+ --instance-family m6i r6i \
115
+ --mode balanced
116
+
117
+ # Get help
118
+ spot-optimizer --help
119
+ ```
120
+
121
+ ---
122
+
123
+ ## Inputs
124
+
125
+ ### Required Parameters
126
+
127
+ 1. **cores (int)**: The total number of CPU cores required.
128
+ 2. **memory (int)**: The total amount of memory required in GB.
129
+
130
+ ### Optional Parameters
131
+
132
+ 1. **region (str)**: AWS region for spot instance selection (default: "us-west-2").
133
+ 2. **ssd_only (bool)**: If `True`, only suggest instances with SSD-backed storage (default: False).
134
+ 3. **arm_instances (bool)**: If `True`, include ARM-based instances (default: True).
135
+ 4. **instance_family (List[str])**: Filter by specific instance families (e.g., ['m6i', 'r6i']).
136
+ 5. **emr_version (str)**: Optional EMR version to ensure instance compatibility.
137
+ 6. **mode (str)**:
138
+ - **`latency`**: Optimize for fewer, larger nodes (lower latency).
139
+ - **`fault_tolerance`**: Optimize for more, smaller nodes (better fault tolerance).
140
+ - **`balanced`**: Aim for a middle ground between fewer and more nodes.
141
+
142
+ ---
143
+
144
+ ## Future Enhancements
145
+
146
+ 1. **Cost Optimization**:
147
+ - Include estimated instance costs and recommend the most cost-effective configuration.
148
+ 2. **Support for Other Cloud Providers**:
149
+ - Extend the library to support GCP and Azure instance types.
150
+ 3. **Spot Interruption Rates**:
151
+ - Include interruption rates in the selection criteria for spot instances.
152
+
153
+ ---
154
+
155
+ ## Development
156
+
157
+ ### Make Commands
158
+
159
+ ```bash
160
+ # Install dependencies
161
+ make install
162
+
163
+ # Run tests
164
+ make test
165
+
166
+ # Check test coverage
167
+ make coverage
168
+
169
+ # Clean up build artifacts
170
+ make clean
171
+ ```
172
+
173
+ ---
174
+
175
+ # Performance Optimisations
176
+
177
+ - Efficiently updates the instance interruption table only every hour, avoiding unnecessary data fetches.
178
+ - Focuses on providing the most stable instances based on the latest interruption rate data.
179
+
180
+ ---
181
+
182
+ ## Issues
183
+
184
+ If you encounter any bugs, please report them on the [issue tracker](https://github.com/amarlearning/spark-cluster-optimiser/issues).
185
+ Alternatively, feel free to [tweet me](https://twitter.com/iamarpandey) if you're having trouble. In fact, you should tweet me anyway.
186
+
187
+ ---
188
+
189
+ ## License
190
+
191
+ Built with ♥ by Amar Prakash Pandey([@amarlearning](http://github.com/amarlearning)) under Apache License 2.0.
192
+
@@ -0,0 +1,169 @@
1
+ # Spot Optimizer
2
+
3
+ [![Python Tests](https://github.com/amarlearning/spot-optimizer/actions/workflows/python-tests.yml/badge.svg)](https://github.com/amarlearning/spot-optimizer/actions/workflows/python-tests.yml)
4
+
5
+ 🚀 Spot Optimizer is a Python library that helps users select the best AWS spot instances based on their resource requirements, including cores, RAM, storage type (SSD), instance architecture (x86 or ARM), AWS region, EMR version compatibility, and instance family preferences.
6
+
7
+ It replaces complex, in-house logic for finding the best spot instances with a simple and powerful abstraction. No more manual guesswork — just the right instances at the right time.
8
+
9
+ ## Why Spot Optimizer?
10
+ Managing spot instance selection within your codebase can be tedious and error-prone. Spot Optimizer provides a clean, abstracted solution to intelligently select the most stable and cost-effective instances.
11
+
12
+ ### Configuration Guarantee
13
+ It ensures that the selected configuration meets or exceeds the user's requirements. For example, if you request 20 cores and 100GB of RAM, the library will suggest a configuration with at least those resources, rounding up to the nearest available configuration.
14
+
15
+ ---
16
+
17
+ ## Key Benefits
18
+ - **💡 Informed Decisions**: Picks instances with the lowest interruption rates and the best fit for your workload.
19
+ - **🧠 Dynamic Reliability**: Smartly updates interruption rates every hour to ensure the most stable instance selection.
20
+ - **🛠️ Operational Efficiency**: No more homegrown scripts or complex logic — just plug and play.
21
+ - **⚡ High Flexibility**: Supports diverse use cases like Spark/EMR clusters, ML workloads, gaming servers, and more.
22
+ - **🏗️ Scalable and Reliable**: Automatically adjusts to changing resource needs while minimizing downtime.
23
+
24
+ ---
25
+
26
+ ## Installation
27
+
28
+ ### For Users
29
+ ```bash
30
+ pip install spot-optimizer
31
+ ```
32
+
33
+ ### For Development
34
+ ```bash
35
+ # Clone the repository
36
+ git clone git@github.com:amarlearning/spot-optimizer.git
37
+ cd spot-optimizer
38
+
39
+ # Install dependencies and set up development environment
40
+ make install
41
+ ```
42
+
43
+ ---
44
+
45
+ ## Usage
46
+
47
+ ### API Usage
48
+
49
+ ```python
50
+ from spot_optimizer import optimize
51
+
52
+ # Basic usage
53
+ result = optimize(cores=8, memory=32)
54
+
55
+ # Advanced usage with all options
56
+ result = optimize(
57
+ cores=8,
58
+ memory=32,
59
+ region="us-east-1",
60
+ ssd_only=True,
61
+ arm_instances=False,
62
+ instance_family=["m6i", "r6i"],
63
+ mode="balanced"
64
+ )
65
+
66
+ print(result)
67
+ # Output:
68
+ # {
69
+ # "instances": {
70
+ # "type": "m6i.2xlarge",
71
+ # "count": 1
72
+ # },
73
+ # "mode": "balanced",
74
+ # "total_cores": 8,
75
+ # "total_ram": 32
76
+ # }
77
+ ```
78
+
79
+ ### CLI Usage
80
+
81
+ ```bash
82
+ # Basic usage
83
+ spot-optimizer optimize --cores 8 --memory 32
84
+
85
+ # Advanced usage
86
+ spot-optimizer optimize \
87
+ --cores 8 \
88
+ --memory 32 \
89
+ --region us-east-1 \
90
+ --ssd-only \
91
+ --no-arm \
92
+ --instance-family m6i r6i \
93
+ --mode balanced
94
+
95
+ # Get help
96
+ spot-optimizer --help
97
+ ```
98
+
99
+ ---
100
+
101
+ ## Inputs
102
+
103
+ ### Required Parameters
104
+
105
+ 1. **cores (int)**: The total number of CPU cores required.
106
+ 2. **memory (int)**: The total amount of memory required in GB.
107
+
108
+ ### Optional Parameters
109
+
110
+ 1. **region (str)**: AWS region for spot instance selection (default: "us-west-2").
111
+ 2. **ssd_only (bool)**: If `True`, only suggest instances with SSD-backed storage (default: False).
112
+ 3. **arm_instances (bool)**: If `True`, include ARM-based instances (default: True).
113
+ 4. **instance_family (List[str])**: Filter by specific instance families (e.g., ['m6i', 'r6i']).
114
+ 5. **emr_version (str)**: Optional EMR version to ensure instance compatibility.
115
+ 6. **mode (str)**:
116
+ - **`latency`**: Optimize for fewer, larger nodes (lower latency).
117
+ - **`fault_tolerance`**: Optimize for more, smaller nodes (better fault tolerance).
118
+ - **`balanced`**: Aim for a middle ground between fewer and more nodes.
119
+
120
+ ---
121
+
122
+ ## Future Enhancements
123
+
124
+ 1. **Cost Optimization**:
125
+ - Include estimated instance costs and recommend the most cost-effective configuration.
126
+ 2. **Support for Other Cloud Providers**:
127
+ - Extend the library to support GCP and Azure instance types.
128
+ 3. **Spot Interruption Rates**:
129
+ - Include interruption rates in the selection criteria for spot instances.
130
+
131
+ ---
132
+
133
+ ## Development
134
+
135
+ ### Make Commands
136
+
137
+ ```bash
138
+ # Install dependencies
139
+ make install
140
+
141
+ # Run tests
142
+ make test
143
+
144
+ # Check test coverage
145
+ make coverage
146
+
147
+ # Clean up build artifacts
148
+ make clean
149
+ ```
150
+
151
+ ---
152
+
153
+ # Performance Optimisations
154
+
155
+ - Efficiently updates the instance interruption table only every hour, avoiding unnecessary data fetches.
156
+ - Focuses on providing the most stable instances based on the latest interruption rate data.
157
+
158
+ ---
159
+
160
+ ## Issues
161
+
162
+ If you encounter any bugs, please report them on the [issue tracker](https://github.com/amarlearning/spark-cluster-optimiser/issues).
163
+ Alternatively, feel free to [tweet me](https://twitter.com/iamarpandey) if you're having trouble. In fact, you should tweet me anyway.
164
+
165
+ ---
166
+
167
+ ## License
168
+
169
+ Built with ♥ by Amar Prakash Pandey([@amarlearning](http://github.com/amarlearning)) under Apache License 2.0.
@@ -0,0 +1,32 @@
1
+ [tool.poetry]
2
+ name = "spot-optimizer"
3
+ version = "1.0.0"
4
+ description = "AWS EC2 spot instance optimizer"
5
+ authors = ["Amar Prakash <amar.om1994@gmail.com>"]
6
+ readme = "README.md"
7
+ repository = "https://github.com/amarlearning/spot-optimizer"
8
+ keywords = ["aws", "ec2", "spot", "optimizer"]
9
+ packages = [
10
+ { include = "spot_optimizer" },
11
+ { include = "spot_optimizer/resources/*.json" }
12
+ ]
13
+
14
+ [tool.poetry.dependencies]
15
+ python = ">=3.9"
16
+ requests = "^2.32.3"
17
+ diskcache = "^5.6.3"
18
+ appdirs = "^1.4.4"
19
+ duckdb = "^1.1.3"
20
+ pandas = "^2.2.0"
21
+
22
+ [tool.poetry.group.dev.dependencies]
23
+ pytest = "^8.3.4"
24
+ types-requests = "^2.32.0.20241016"
25
+ pytest-cov = "^4.1.0"
26
+
27
+ [build-system]
28
+ requires = ["poetry-core"]
29
+ build-backend = "poetry.core.masonry.api"
30
+
31
+ [tool.poetry.scripts]
32
+ spot-optimizer = "spot_optimizer.cli:main"
@@ -0,0 +1,61 @@
1
+ from spot_optimizer.optimizer_mode import Mode
2
+ from spot_optimizer.spot_optimizer import SpotOptimizer
3
+
4
+ default_optimizer = SpotOptimizer()
5
+
6
+ __all__ = ['optimize', 'Mode', 'SpotOptimizer']
7
+
8
+ def optimize(
9
+ cores: int,
10
+ memory: int,
11
+ region: str = "us-west-2",
12
+ ssd_only: bool = False,
13
+ arm_instances: bool = True,
14
+ instance_family: list[str] = None,
15
+ emr_version: str = None,
16
+ mode: str = Mode.BALANCED.value,
17
+ ) -> dict:
18
+ """
19
+ Optimize spot instance configuration based on requirements.
20
+
21
+ Args:
22
+ cores: Number of CPU cores required
23
+ memory: Amount of RAM required (in GB)
24
+ region: AWS region (default: "us-west-2")
25
+ ssd_only: Whether to only consider instances with SSD storage
26
+ arm_instances: Whether to include ARM-based instances
27
+ instance_family: List of instance families to consider
28
+ emr_version: EMR version if using with EMR
29
+ mode: Optimization mode (default: BALANCED)
30
+
31
+ Returns:
32
+ dict: Optimized instance configuration
33
+
34
+ Example:
35
+ >>> from spot_optimizer import optimize
36
+ >>> config = optimize(
37
+ ... cores=8,
38
+ ... memory=32,
39
+ ... region="us-east-1"
40
+ ... )
41
+ >>> print(config)
42
+ {
43
+ "instances": {
44
+ "type": "m6i.2xlarge",
45
+ "count": 1
46
+ },
47
+ "mode": "balanced",
48
+ "total_cores": 8,
49
+ "total_ram": 32
50
+ }
51
+ """
52
+ return default_optimizer.optimize(
53
+ cores=cores,
54
+ memory=memory,
55
+ region=region,
56
+ ssd_only=ssd_only,
57
+ arm_instances=arm_instances,
58
+ instance_family=instance_family,
59
+ emr_version=emr_version,
60
+ mode=mode,
61
+ )