3030from tqdm .auto import tqdm
3131from urllib3 .util .retry import Retry
3232
33+ from mp_api .client .core .exceptions import MPRestError
3334from mp_api .client .core .settings import MAPIClientSettings
3435from mp_api .client .core .utils import load_json , validate_ids
3536
@@ -92,11 +93,11 @@ def __init__(
9293 session : requests .Session | None = None ,
9394 s3_client : Any | None = None ,
9495 debug : bool = False ,
95- monty_decode : bool = True ,
9696 use_document_model : bool = True ,
9797 timeout : int = 20 ,
9898 headers : dict | None = None ,
9999 mute_progress_bars : bool = SETTINGS .MUTE_PROGRESS_BARS ,
100+ ** kwargs ,
100101 ):
101102 """Initialize the REST API helper class.
102103
@@ -121,13 +122,13 @@ def __init__(
121122 advanced usage only.
122123 s3_client: boto3 S3 client object with which to connect to the object stores.ct to the object stores.ct to the object stores.
123124 debug: if True, print the URL for every request
124- monty_decode: Decode the data using monty into python objects
125125 use_document_model: If False, skip the creating the document model and return data
126126 as a dictionary. This can be simpler to work with but bypasses data validation
127127 and will not give auto-complete for available fields.
128128 timeout: Time in seconds to wait until a request timeout error is thrown
129129 headers: Custom headers for localhost connections.
130130 mute_progress_bars: Whether to disable progress bars.
131+ **kwargs: access to legacy kwargs that may be in the process of being deprecated
131132 """
132133 # TODO: think about how to migrate from PMG_MAPI_KEY
133134 self .api_key = api_key or os .getenv ("MP_API_KEY" )
@@ -136,7 +137,6 @@ def __init__(
136137 )
137138 self .debug = debug
138139 self .include_user_agent = include_user_agent
139- self .monty_decode = monty_decode
140140 self .use_document_model = use_document_model
141141 self .timeout = timeout
142142 self .headers = headers or {}
@@ -151,6 +151,12 @@ def __init__(
151151 self ._session = session
152152 self ._s3_client = s3_client
153153
154+ if "monty_decode" in kwargs :
155+ warnings .warn (
156+ "Ignoring `monty_decode`, as it is no longer a supported option in `mp_api`."
157+ "The client by default returns results consistent with `monty_decode=True`."
158+ )
159+
154160 @property
155161 def session (self ) -> requests .Session :
156162 if not self ._session :
@@ -265,7 +271,7 @@ def _post_resource(
265271 response = self .session .post (url , json = payload , verify = True , params = params )
266272
267273 if response .status_code == 200 :
268- data = load_json (response .text , deser = self . monty_decode )
274+ data = load_json (response .text )
269275 if self .document_model and use_document_model :
270276 if isinstance (data ["data" ], dict ):
271277 data ["data" ] = self .document_model .model_validate (data ["data" ]) # type: ignore
@@ -333,7 +339,7 @@ def _patch_resource(
333339 response = self .session .patch (url , json = payload , verify = True , params = params )
334340
335341 if response .status_code == 200 :
336- data = load_json (response .text , deser = self . monty_decode )
342+ data = load_json (response .text )
337343 if self .document_model and use_document_model :
338344 if isinstance (data ["data" ], dict ):
339345 data ["data" ] = self .document_model .model_validate (data ["data" ]) # type: ignore
@@ -384,10 +390,7 @@ def _query_open_data(
384390 Returns:
385391 dict: MontyDecoded data
386392 """
387- if not decoder :
388-
389- def decoder (x ):
390- return load_json (x , deser = self .monty_decode )
393+ decoder = decoder or load_json
391394
392395 file = open (
393396 f"s3://{ bucket } /{ key } " ,
@@ -997,7 +1000,7 @@ def _submit_request_and_process(
9971000 )
9981001
9991002 if response .status_code == 200 :
1000- data = load_json (response .text , deser = self . monty_decode )
1003+ data = load_json (response .text )
10011004 # other sub-urls may use different document models
10021005 # the client does not handle this in a particularly smart way currently
10031006 if self .document_model and use_document_model :
@@ -1302,12 +1305,10 @@ def count(self, criteria: dict | None = None) -> int | str:
13021305 """
13031306 criteria = criteria or {}
13041307 user_preferences = (
1305- self .monty_decode ,
13061308 self .use_document_model ,
13071309 self .mute_progress_bars ,
13081310 )
1309- self .monty_decode , self .use_document_model , self .mute_progress_bars = (
1310- False ,
1311+ self .use_document_model , self .mute_progress_bars = (
13111312 False ,
13121313 True ,
13131314 ) # do not waste cycles decoding
@@ -1329,7 +1330,6 @@ def count(self, criteria: dict | None = None) -> int | str:
13291330 )
13301331
13311332 (
1332- self .monty_decode ,
13331333 self .use_document_model ,
13341334 self .mute_progress_bars ,
13351335 ) = user_preferences
@@ -1351,11 +1351,3 @@ def __str__(self): # pragma: no cover
13511351 f"{ self .__class__ .__name__ } connected to { self .endpoint } \n \n "
13521352 f"Available fields: { ', ' .join (self .available_fields )} \n \n "
13531353 )
1354-
1355-
1356- class MPRestError (Exception ):
1357- """Raised when the query has problems, e.g., bad query format."""
1358-
1359-
1360- class MPRestWarning (Warning ):
1361- """Raised when a query is malformed but interpretable."""
0 commit comments