MCPcopy Create free account
hub / github.com/Materials-Consortia/optimade-python-tools / from_url

Method from_url

optimade/adapters/base.py:152–182  ·  view source on GitHub ↗

Convert OPTIMADE URL into the target entry type. Parameters: url (str): The OPTIMADE URL to convert. Returns: The converted URL.

(cls, url: str)

Source from the content-addressed store, hash-verified

150
151 @classmethod
152 def from_url(cls, url: str) -> Any:
153 """Convert OPTIMADE URL into the target entry type.
154
155 Parameters:
156 url (str): The OPTIMADE URL to convert.
157
158 Returns:
159 The converted URL.
160
161 """
162 import requests
163
164 response = requests.get(url, timeout=100)
165 if response.status_code != 200:
166 raise RuntimeError(
167 f"Could not retrieve OPTIMADE entry from URL {url} returned {response.status_code}"
168 )
169
170 try:
171 json_response = response.json()
172
173 except JSONDecodeError as exc:
174 raise RuntimeError(
175 f"Could not retrieve OPTIMADE entry from URL {url}: did not contain valid JSON response."
176 ) from exc
177
178 data: dict = json_response.get("data", {})
179 if isinstance(data, list):
180 raise RuntimeError(f"returned a list of {len(data)} entries.")
181
182 return cls(data)
183
184 @staticmethod
185 def _get_model_attributes(

Calls 2

getMethod · 0.45
jsonMethod · 0.45