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
@@ -94,11 +95,11 @@ def __init__(
9495 session : requests .Session | None = None ,
9596 s3_client : Any | None = None ,
9697 debug : bool = False ,
97- monty_decode : bool = True ,
9898 use_document_model : bool = True ,
9999 timeout : int = 20 ,
100100 headers : dict | None = None ,
101101 mute_progress_bars : bool = SETTINGS .MUTE_PROGRESS_BARS ,
102+ ** kwargs ,
102103 ):
103104 """Initialize the REST API helper class.
104105
@@ -123,13 +124,13 @@ def __init__(
123124 advanced usage only.
124125 s3_client: boto3 S3 client object with which to connect to the object stores.ct to the object stores.ct to the object stores.
125126 debug: if True, print the URL for every request
126- monty_decode: Decode the data using monty into python objects
127127 use_document_model: If False, skip the creating the document model and return data
128128 as a dictionary. This can be simpler to work with but bypasses data validation
129129 and will not give auto-complete for available fields.
130130 timeout: Time in seconds to wait until a request timeout error is thrown
131131 headers: Custom headers for localhost connections.
132132 mute_progress_bars: Whether to disable progress bars.
133+ **kwargs: access to legacy kwargs that may be in the process of being deprecated
133134 """
134135 # TODO: think about how to migrate from PMG_MAPI_KEY
135136 self .api_key = api_key or os .getenv ("MP_API_KEY" )
@@ -138,7 +139,6 @@ def __init__(
138139 )
139140 self .debug = debug
140141 self .include_user_agent = include_user_agent
141- self .monty_decode = monty_decode
142142 self .use_document_model = use_document_model
143143 self .timeout = timeout
144144 self .headers = headers or {}
@@ -153,6 +153,12 @@ def __init__(
153153 self ._session = session
154154 self ._s3_client = s3_client
155155
156+ if "monty_decode" in kwargs :
157+ warnings .warn (
158+ "Ignoring `monty_decode`, as it is no longer a supported option in `mp_api`."
159+ "The client by default returns results consistent with `monty_decode=True`."
160+ )
161+
156162 @property
157163 def session (self ) -> requests .Session :
158164 if not self ._session :
@@ -267,7 +273,7 @@ def _post_resource(
267273 response = self .session .post (url , json = payload , verify = True , params = params )
268274
269275 if response .status_code == 200 :
270- data = load_json (response .text , deser = self . monty_decode )
276+ data = load_json (response .text )
271277 if self .document_model and use_document_model :
272278 if isinstance (data ["data" ], dict ):
273279 data ["data" ] = self .document_model .model_validate (data ["data" ]) # type: ignore
@@ -335,7 +341,7 @@ def _patch_resource(
335341 response = self .session .patch (url , json = payload , verify = True , params = params )
336342
337343 if response .status_code == 200 :
338- data = load_json (response .text , deser = self . monty_decode )
344+ data = load_json (response .text )
339345 if self .document_model and use_document_model :
340346 if isinstance (data ["data" ], dict ):
341347 data ["data" ] = self .document_model .model_validate (data ["data" ]) # type: ignore
@@ -386,10 +392,7 @@ def _query_open_data(
386392 Returns:
387393 dict: MontyDecoded data
388394 """
389- if not decoder :
390-
391- def decoder (x ):
392- return load_json (x , deser = self .monty_decode )
395+ decoder = decoder or load_json
393396
394397 file = open (
395398 f"s3://{ bucket } /{ key } " ,
@@ -999,7 +1002,7 @@ def _submit_request_and_process(
9991002 )
10001003
10011004 if response .status_code == 200 :
1002- data = load_json (response .text , deser = self . monty_decode )
1005+ data = load_json (response .text )
10031006 # other sub-urls may use different document models
10041007 # the client does not handle this in a particularly smart way currently
10051008 if self .document_model and use_document_model :
@@ -1304,12 +1307,10 @@ def count(self, criteria: dict | None = None) -> int | str:
13041307 """
13051308 criteria = criteria or {}
13061309 user_preferences = (
1307- self .monty_decode ,
13081310 self .use_document_model ,
13091311 self .mute_progress_bars ,
13101312 )
1311- self .monty_decode , self .use_document_model , self .mute_progress_bars = (
1312- False ,
1313+ self .use_document_model , self .mute_progress_bars = (
13131314 False ,
13141315 True ,
13151316 ) # do not waste cycles decoding
@@ -1331,7 +1332,6 @@ def count(self, criteria: dict | None = None) -> int | str:
13311332 )
13321333
13331334 (
1334- self .monty_decode ,
13351335 self .use_document_model ,
13361336 self .mute_progress_bars ,
13371337 ) = user_preferences
@@ -1389,11 +1389,3 @@ def __getattr__(self, v: str):
13891389
13901390 def __dir__ (self ):
13911391 return dir (self .__class__ ) + list (self ._sub_resters )
1392-
1393-
1394- class MPRestError (Exception ):
1395- """Raised when the query has problems, e.g., bad query format."""
1396-
1397-
1398- class MPRestWarning (Warning ):
1399- """Raised when a query is malformed but interpretable."""
0 commit comments