11from dataclasses import dataclass
2+ from typing import Literal
23
34from dataclasses_json import dataclass_json
45
56INSTANCE_TYPES_ENDPOINT = '/instance-types'
67
8+ Currency = Literal ['usd' , 'eur' ]
9+
710
811@dataclass_json
912@dataclass
1013class InstanceType :
1114 """Instance type.
1215
1316 Attributes:
14- id: instance type id .
15- instance_type: instance type, e.g. '8V100.48M'.
16- price_per_hour: instance type price per hour.
17- spot_price_per_hour: instance type spot price per hour.
18- description: instance type description.
19- cpu: instance type cpu details.
20- gpu: instance type gpu details.
21- memory: instance type memory details.
22- gpu_memory: instance type gpu memory details.
23- storage: instance type storage details.
17+ id: Instance type ID .
18+ instance_type: Instance type, e.g. '8V100.48M'.
19+ price_per_hour: Instance type price per hour.
20+ spot_price_per_hour: Instance type spot price per hour.
21+ description: Instance type description.
22+ cpu: Instance type CPU details.
23+ gpu: Instance type GPU details.
24+ memory: Instance type memory details.
25+ gpu_memory: Instance type GPU memory details.
26+ storage: Instance type storage details.
2427 """
2528
2629 id : str
@@ -33,6 +36,19 @@ class InstanceType:
3336 memory : dict
3437 gpu_memory : dict
3538 storage : dict
39+ best_for : list [str ]
40+ model : str
41+ name : str
42+ p2p : str
43+ currency : Currency
44+ manufacturer : str
45+ display_name : str
46+ supported_os : list [str ]
47+ deploy_warning : str | None = None
48+ dynamic_price : float | None = None
49+ max_dynamic_price : float | None = None
50+ serverless_price : float | None = None
51+ serverless_spot_price : float | None = None
3652
3753
3854class InstanceTypesService :
@@ -41,13 +57,16 @@ class InstanceTypesService:
4157 def __init__ (self , http_client ) -> None :
4258 self ._http_client = http_client
4359
44- def get (self ) -> list [InstanceType ]:
60+ def get (self , currency : Currency = 'usd' ) -> list [InstanceType ]:
4561 """Get all instance types.
4662
4763 :return: list of instance type objects
4864 :rtype: list[InstanceType]
4965 """
50- instance_types = self ._http_client .get (INSTANCE_TYPES_ENDPOINT ).json ()
66+ instance_types = self ._http_client .get (
67+ INSTANCE_TYPES_ENDPOINT ,
68+ params = {'currency' : currency },
69+ ).json ()
5170 instance_type_objects = [
5271 InstanceType (
5372 id = instance_type ['id' ],
@@ -60,8 +79,41 @@ def get(self) -> list[InstanceType]:
6079 memory = instance_type ['memory' ],
6180 gpu_memory = instance_type ['gpu_memory' ],
6281 storage = instance_type ['storage' ],
82+ best_for = instance_type ['best_for' ],
83+ model = instance_type ['model' ],
84+ name = instance_type ['name' ],
85+ p2p = instance_type ['p2p' ],
86+ currency = instance_type ['currency' ],
87+ manufacturer = instance_type ['manufacturer' ],
88+ display_name = instance_type ['display_name' ],
89+ supported_os = instance_type ['supported_os' ],
90+ deploy_warning = instance_type .get ('deploy_warning' ),
91+ dynamic_price = (
92+ float (instance_type ['dynamic_price' ])
93+ if instance_type .get ('dynamic_price' ) is not None
94+ else None
95+ ),
96+ max_dynamic_price = (
97+ float (instance_type ['max_dynamic_price' ])
98+ if instance_type .get ('max_dynamic_price' ) is not None
99+ else None
100+ ),
101+ serverless_price = (
102+ float (instance_type ['serverless_price' ])
103+ if instance_type .get ('serverless_price' ) is not None
104+ else None
105+ ),
106+ serverless_spot_price = (
107+ float (instance_type ['serverless_spot_price' ])
108+ if instance_type .get ('serverless_spot_price' ) is not None
109+ else None
110+ ),
63111 )
64112 for instance_type in instance_types
65113 ]
66114
67115 return instance_type_objects
116+
117+ def get_price_history (self ):
118+ """Get the deprecated dynamic price history endpoint as raw JSON."""
119+ return self ._http_client .get (f'{ INSTANCE_TYPES_ENDPOINT } /price-history' ).json ()
0 commit comments