Skip to content

Commit 5eb63b6

Browse files
committed
Add get_document method to EnzymeMLSuite
Introduces a get_document method to retrieve an EnzymeML document by ID from the service, handling connection errors and response validation.
1 parent 6a89bc9 commit 5eb63b6

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

pyenzyme/suite.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,23 @@ def get_current(self) -> EnzymeMLDocument:
4545

4646
return EnzymeMLHandler.read_enzymeml_from_string(content)
4747

48+
def get_document(self, id: str) -> EnzymeMLDocument:
49+
"""
50+
Retrieves an EnzymeML document from the service.
51+
"""
52+
try:
53+
response = self.client.get(f"/docs/{id}")
54+
except httpx.ConnectError:
55+
raise ConnectionError(
56+
"Could not connect to the EnzymeML suite. Make sure it is running."
57+
)
58+
59+
response.raise_for_status()
60+
61+
content = response.json()["data"]["content"]
62+
63+
return EnzymeMLHandler.read_enzymeml_from_string(content)
64+
4865
def update_current(self, doc: EnzymeMLDocument):
4966
"""
5067
Updates the current EnzymeML document on the service.

0 commit comments

Comments
 (0)