openprotein-python 0.2.3__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.3 → openprotein_python-0.2.7}/PKG-INFO +2 -1
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/api/embedding.py +17 -1
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/base.py +42 -17
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/errors.py +9 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/models.py +2 -2
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/pyproject.toml +1 -1
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/LICENSE.txt +0 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/README.md +0 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/__init__.py +0 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/_version.py +0 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/api/__init__.py +0 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/api/data.py +0 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/api/design.py +0 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/api/jobs.py +0 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/api/poet.py +0 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/api/predict.py +0 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/api/train.py +0 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/config.py +0 -0
- {openprotein_python-0.2.3 → openprotein_python-0.2.7}/openprotein/fasta.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: openprotein-python
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: OpenProtein Python interface.
|
|
5
5
|
Home-page: https://docs.openprotein.ai/
|
|
6
6
|
License: MIT
|
|
@@ -14,6 +14,7 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.9
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.10
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
18
|
Requires-Dist: pandas (>=1)
|
|
18
19
|
Requires-Dist: pydantic (>=1)
|
|
19
20
|
Requires-Dist: requests (>=2)
|
|
@@ -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
|
"""
|
|
@@ -37,13 +37,16 @@ class APISession(requests.Session):
|
|
|
37
37
|
--------
|
|
38
38
|
>>> session = APISession("username", "password")
|
|
39
39
|
"""
|
|
40
|
+
|
|
40
41
|
|
|
41
42
|
def __init__(self, username:str,
|
|
42
43
|
password:str,
|
|
43
|
-
backend:str = "https://api.openprotein.ai/api/"
|
|
44
|
+
backend:str = "https://api.openprotein.ai/api/",
|
|
45
|
+
timeout:int = 180):
|
|
44
46
|
super().__init__()
|
|
45
47
|
self.backend = backend
|
|
46
48
|
self.verify = True
|
|
49
|
+
self.timeout = timeout
|
|
47
50
|
|
|
48
51
|
# Custom retry strategies
|
|
49
52
|
#auto retry for pesky connection reset errors and others
|
|
@@ -55,6 +58,28 @@ class APISession(requests.Session):
|
|
|
55
58
|
self.mount('https://', adapter)
|
|
56
59
|
self.login(username, password)
|
|
57
60
|
|
|
61
|
+
|
|
62
|
+
def post(self, url, data=None, json=None, **kwargs):
|
|
63
|
+
r"""Sends a POST request. Returns :class:`Response` object.
|
|
64
|
+
|
|
65
|
+
:param url: URL for the new :class:`Request` object.
|
|
66
|
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
|
67
|
+
object to send in the body of the :class:`Request`.
|
|
68
|
+
:param json: (optional) json to send in the body of the :class:`Request`.
|
|
69
|
+
:param \*\*kwargs: Optional arguments that ``request`` takes.
|
|
70
|
+
:rtype: requests.Response
|
|
71
|
+
"""
|
|
72
|
+
timeout = self.timeout
|
|
73
|
+
if 'timeout' in kwargs:
|
|
74
|
+
timeout = kwargs.pop('timeout')
|
|
75
|
+
|
|
76
|
+
return self.request("POST",
|
|
77
|
+
url,
|
|
78
|
+
data=data,
|
|
79
|
+
json=json,
|
|
80
|
+
timeout=timeout,
|
|
81
|
+
**kwargs)
|
|
82
|
+
|
|
58
83
|
def login(self, username:str, password:str):
|
|
59
84
|
"""
|
|
60
85
|
Authenticate connection to OpenProtein with your credentials.
|
|
@@ -71,28 +96,28 @@ class APISession(requests.Session):
|
|
|
71
96
|
def _get_auth_token(self, username:str, password:str):
|
|
72
97
|
endpoint = "v1/login/user-access-token"
|
|
73
98
|
url = urljoin(self.backend, endpoint)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if response.status_code == 200:
|
|
78
|
-
result = response.json()
|
|
79
|
-
token = result["access_token"]
|
|
80
|
-
return BearerAuth(token)
|
|
81
|
-
else:
|
|
82
|
-
raise AuthError(
|
|
83
|
-
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
|
|
84
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)
|
|
85
112
|
|
|
86
113
|
def request(
|
|
87
114
|
self, method: Union[str, bytes], url: Union[str, bytes], *args, **kwargs
|
|
88
115
|
):
|
|
89
116
|
full_url = urljoin(self.backend, url)
|
|
90
117
|
response = super().request(method, full_url, *args, **kwargs)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
raise
|
|
94
|
-
f"Request failed: \n\t status: {response.status_code} \n\t message: {response.text} "
|
|
95
|
-
)
|
|
118
|
+
if not response.ok:
|
|
119
|
+
# raise custom exception that prints better error message than requests.HTTPError
|
|
120
|
+
raise HTTPError(response)
|
|
96
121
|
return response
|
|
97
122
|
|
|
98
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"):
|
|
@@ -69,7 +69,7 @@ class DesignMetadata(NewModel):
|
|
|
69
69
|
y_var: Optional[float] = None
|
|
70
70
|
|
|
71
71
|
class DesignSubscore(NewModel):
|
|
72
|
-
score:
|
|
72
|
+
score: float
|
|
73
73
|
metadata: DesignMetadata
|
|
74
74
|
|
|
75
75
|
class DesignStep(NewModel):
|
|
@@ -78,7 +78,7 @@ class DesignStep(NewModel):
|
|
|
78
78
|
sequence: str
|
|
79
79
|
# scores: List[int]
|
|
80
80
|
# subscores_metadata: List[List[DesignSubscore]]
|
|
81
|
-
initial_scores: List[
|
|
81
|
+
initial_scores: List[float] = Field(
|
|
82
82
|
..., alias="scores"
|
|
83
83
|
) # renaming 'scores' to 'initial_scores' # noqa: E501
|
|
84
84
|
scores: List[List[DesignSubscore]] = Field(
|
|
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
|