openprotein-python 0.2.6__tar.gz → 0.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/PKG-INFO +1 -1
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/api/embedding.py +17 -1
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/base.py +16 -16
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/errors.py +9 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/pyproject.toml +1 -1
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/LICENSE.txt +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/README.md +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/__init__.py +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/_version.py +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/api/__init__.py +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/api/data.py +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/api/design.py +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/api/jobs.py +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/api/poet.py +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/api/predict.py +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/api/train.py +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/config.py +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/fasta.py +0 -0
- {openprotein_python-0.2.6 → openprotein_python-0.2.7}/openprotein/models.py +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from openprotein.base import APISession
|
|
2
2
|
from openprotein.api.jobs import (
|
|
3
3
|
Job,
|
|
4
|
+
AsyncJobFuture,
|
|
4
5
|
MappedAsyncJobFuture,
|
|
5
6
|
PagedAsyncJobFuture,
|
|
6
7
|
job_get,
|
|
@@ -504,7 +505,7 @@ class ProtembedModel:
|
|
|
504
505
|
return SVDModel(self.session, metadata)
|
|
505
506
|
|
|
506
507
|
|
|
507
|
-
class SVDModel:
|
|
508
|
+
class SVDModel(AsyncJobFuture):
|
|
508
509
|
"""
|
|
509
510
|
Class providing embedding endpoint for SVD models. \
|
|
510
511
|
Also allows retrieving embeddings of sequences used to fit the SVD with `get`.
|
|
@@ -513,6 +514,7 @@ class SVDModel:
|
|
|
513
514
|
def __init__(self, session: APISession, metadata: SVDMetadata):
|
|
514
515
|
self.session = session
|
|
515
516
|
self._metadata = metadata
|
|
517
|
+
self._job = None
|
|
516
518
|
|
|
517
519
|
def __str__(self) -> str:
|
|
518
520
|
return str(self.metadata)
|
|
@@ -563,6 +565,20 @@ class SVDModel:
|
|
|
563
565
|
def get_job(self) -> Job:
|
|
564
566
|
"""Get job associated with this SVD model"""
|
|
565
567
|
return job_get(self.session, self.id)
|
|
568
|
+
|
|
569
|
+
def get(self):
|
|
570
|
+
# overload for AsyncJobFuture
|
|
571
|
+
return self
|
|
572
|
+
|
|
573
|
+
@property
|
|
574
|
+
def job(self) -> Job:
|
|
575
|
+
if self._job is None:
|
|
576
|
+
self._job = self.get_job()
|
|
577
|
+
return self._job
|
|
578
|
+
|
|
579
|
+
@job.setter
|
|
580
|
+
def job(self, j):
|
|
581
|
+
self._job = j
|
|
566
582
|
|
|
567
583
|
def get_inputs(self) -> List[bytes]:
|
|
568
584
|
"""
|
|
@@ -7,7 +7,7 @@ from typing import Union
|
|
|
7
7
|
from requests.adapters import HTTPAdapter
|
|
8
8
|
from requests.packages.urllib3.util.retry import Retry
|
|
9
9
|
|
|
10
|
-
from openprotein.errors import
|
|
10
|
+
from openprotein.errors import HTTPError, APIError, AuthError
|
|
11
11
|
|
|
12
12
|
class BearerAuth(requests.auth.AuthBase):
|
|
13
13
|
"""
|
|
@@ -96,28 +96,28 @@ class APISession(requests.Session):
|
|
|
96
96
|
def _get_auth_token(self, username:str, password:str):
|
|
97
97
|
endpoint = "v1/login/user-access-token"
|
|
98
98
|
url = urljoin(self.backend, endpoint)
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if response.status_code == 200:
|
|
103
|
-
result = response.json()
|
|
104
|
-
token = result["access_token"]
|
|
105
|
-
return BearerAuth(token)
|
|
106
|
-
else:
|
|
107
|
-
raise AuthError(
|
|
108
|
-
f"Unable to authenticate with given credentials: {response.status_code} : {response.text}"
|
|
99
|
+
try:
|
|
100
|
+
response = self.post(
|
|
101
|
+
url, params={"username": username, "password": password}, timeout=3
|
|
109
102
|
)
|
|
103
|
+
except HTTPError as e:
|
|
104
|
+
# if an error occured during auth, we raise an AuthError with reference to the HTTPError
|
|
105
|
+
raise AuthError(
|
|
106
|
+
f"Authentication failed. Please check your credentials and connection."
|
|
107
|
+
) from e
|
|
108
|
+
|
|
109
|
+
result = response.json()
|
|
110
|
+
token = result["access_token"]
|
|
111
|
+
return BearerAuth(token)
|
|
110
112
|
|
|
111
113
|
def request(
|
|
112
114
|
self, method: Union[str, bytes], url: Union[str, bytes], *args, **kwargs
|
|
113
115
|
):
|
|
114
116
|
full_url = urljoin(self.backend, url)
|
|
115
117
|
response = super().request(method, full_url, *args, **kwargs)
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
raise
|
|
119
|
-
f"Request failed: \n\t status: {response.status_code} \n\t message: {response.text} "
|
|
120
|
-
)
|
|
118
|
+
if not response.ok:
|
|
119
|
+
# raise custom exception that prints better error message than requests.HTTPError
|
|
120
|
+
raise HTTPError(response)
|
|
121
121
|
return response
|
|
122
122
|
|
|
123
123
|
|
|
@@ -17,6 +17,15 @@ class APIError(Exception):
|
|
|
17
17
|
self.message = message
|
|
18
18
|
super().__init__(self.message)
|
|
19
19
|
|
|
20
|
+
class HTTPError(APIError):
|
|
21
|
+
def __init__(self, response):
|
|
22
|
+
self.response = response
|
|
23
|
+
self.status_code = response.status_code
|
|
24
|
+
self.text = response.text
|
|
25
|
+
self.url = response.url
|
|
26
|
+
message = f"Status code {self.status_code}\non resource: {self.url}\n{self.text}"
|
|
27
|
+
super().__init__(message)
|
|
28
|
+
|
|
20
29
|
class AuthError(Exception):
|
|
21
30
|
"""InvalidParameterError"""
|
|
22
31
|
def __init__(self, message="Invalid authorization"):
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|