biolmai 0.2.3__py2.py3-none-any.whl → 0.2.5__py2.py3-none-any.whl
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.
Potentially problematic release.
This version of biolmai might be problematic. Click here for more details.
- biolmai/__init__.py +17 -3
- biolmai/auth.py +56 -4
- biolmai-0.2.5.dist-info/METADATA +134 -0
- {biolmai-0.2.3.dist-info → biolmai-0.2.5.dist-info}/RECORD +9 -9
- {biolmai-0.2.3.dist-info → biolmai-0.2.5.dist-info}/WHEEL +1 -1
- biolmai-0.2.3.dist-info/METADATA +0 -76
- {biolmai-0.2.3.dist-info → biolmai-0.2.5.dist-info}/entry_points.txt +0 -0
- {biolmai-0.2.3.dist-info → biolmai-0.2.5.dist-info}/licenses/AUTHORS.rst +0 -0
- {biolmai-0.2.3.dist-info → biolmai-0.2.5.dist-info}/licenses/LICENSE +0 -0
- {biolmai-0.2.3.dist-info → biolmai-0.2.5.dist-info}/top_level.txt +0 -0
biolmai/__init__.py
CHANGED
|
@@ -1,10 +1,24 @@
|
|
|
1
1
|
"""Top-level package for BioLM AI."""
|
|
2
2
|
__author__ = """Nikhil Haas"""
|
|
3
3
|
__email__ = "nikhil@biolm.ai"
|
|
4
|
-
__version__ = '0.2.
|
|
4
|
+
__version__ = '0.2.5'
|
|
5
5
|
|
|
6
|
-
from biolmai.cls import *
|
|
7
6
|
from biolmai.client import BioLMApi, BioLMApiClient
|
|
8
7
|
from biolmai.biolmai import BioLM
|
|
8
|
+
from typing import Optional, Union, List, Any
|
|
9
9
|
|
|
10
|
-
__all__ = []
|
|
10
|
+
__all__ = ['biolm']
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def biolm(
|
|
14
|
+
*,
|
|
15
|
+
entity: str,
|
|
16
|
+
action: str,
|
|
17
|
+
type: Optional[str] = None,
|
|
18
|
+
items: Union[Any, List[Any]],
|
|
19
|
+
params: Optional[dict] = None,
|
|
20
|
+
api_key: Optional[str] = None,
|
|
21
|
+
**kwargs
|
|
22
|
+
) -> Any:
|
|
23
|
+
"""Top-level convenience function that wraps the BioLM class and returns the result."""
|
|
24
|
+
return BioLM(entity=entity, action=action, type=type, items=items, params=params, api_key=api_key, **kwargs)
|
biolmai/auth.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ast
|
|
1
2
|
import json
|
|
2
3
|
import os
|
|
3
4
|
import pprint
|
|
@@ -9,6 +10,47 @@ import requests
|
|
|
9
10
|
from biolmai.const import ACCESS_TOK_PATH, BASE_DOMAIN, GEN_TOKEN_URL, USER_BIOLM_DIR
|
|
10
11
|
|
|
11
12
|
|
|
13
|
+
def parse_credentials_file(file_path):
|
|
14
|
+
"""Parse credentials file, handling JSON, Python dict syntax, and mixed types.
|
|
15
|
+
|
|
16
|
+
Returns a dict with 'access' and 'refresh' keys as strings, or None if parsing fails.
|
|
17
|
+
Uses ast.literal_eval() which is safe and only evaluates Python literals.
|
|
18
|
+
"""
|
|
19
|
+
try:
|
|
20
|
+
with open(file_path, 'r') as f:
|
|
21
|
+
content = f.read().strip()
|
|
22
|
+
|
|
23
|
+
# Try JSON first
|
|
24
|
+
try:
|
|
25
|
+
data = json.loads(content)
|
|
26
|
+
except json.JSONDecodeError:
|
|
27
|
+
# Fall back to safe Python literal evaluation for dict syntax like {access: 123, refresh: 456}
|
|
28
|
+
# ast.literal_eval() is safe - it only evaluates literals, no code execution
|
|
29
|
+
try:
|
|
30
|
+
data = ast.literal_eval(content)
|
|
31
|
+
except (ValueError, SyntaxError):
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
# Ensure we have a dictionary
|
|
35
|
+
if not isinstance(data, dict):
|
|
36
|
+
return None
|
|
37
|
+
|
|
38
|
+
# Extract access and refresh, converting to strings
|
|
39
|
+
access = data.get("access")
|
|
40
|
+
refresh = data.get("refresh")
|
|
41
|
+
|
|
42
|
+
# Convert to strings if they exist
|
|
43
|
+
if access is not None:
|
|
44
|
+
access = str(access)
|
|
45
|
+
if refresh is not None:
|
|
46
|
+
refresh = str(refresh)
|
|
47
|
+
|
|
48
|
+
return {"access": access, "refresh": refresh}
|
|
49
|
+
|
|
50
|
+
except Exception:
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
|
|
12
54
|
def validate_user_auth(api_token=None, access=None, refresh=None):
|
|
13
55
|
"""Validates an API token, to be used as 'Authorization: Token 1235abc'
|
|
14
56
|
authentication method."""
|
|
@@ -61,8 +103,12 @@ def get_auth_status():
|
|
|
61
103
|
elif os.path.exists(ACCESS_TOK_PATH):
|
|
62
104
|
msg = f"Credentials file found {ACCESS_TOK_PATH}. Validating token..."
|
|
63
105
|
click.echo(msg)
|
|
64
|
-
|
|
65
|
-
|
|
106
|
+
access_refresh_dict = parse_credentials_file(ACCESS_TOK_PATH)
|
|
107
|
+
if access_refresh_dict is None:
|
|
108
|
+
click.echo(f"Error reading credentials file {ACCESS_TOK_PATH}.")
|
|
109
|
+
click.echo("The file may be corrupted or contain invalid data.")
|
|
110
|
+
click.echo("Please login again by running `biolmai login`.")
|
|
111
|
+
return
|
|
66
112
|
access = access_refresh_dict.get("access")
|
|
67
113
|
refresh = access_refresh_dict.get("refresh")
|
|
68
114
|
resp = validate_user_auth(access=access, refresh=refresh)
|
|
@@ -156,8 +202,14 @@ def get_user_auth_header():
|
|
|
156
202
|
if api_token:
|
|
157
203
|
headers = {"Authorization": f"Token {api_token}"}
|
|
158
204
|
elif os.path.exists(ACCESS_TOK_PATH):
|
|
159
|
-
|
|
160
|
-
|
|
205
|
+
access_refresh_dict = parse_credentials_file(ACCESS_TOK_PATH)
|
|
206
|
+
if access_refresh_dict is None:
|
|
207
|
+
err = (
|
|
208
|
+
f"Error reading credentials file {ACCESS_TOK_PATH}. "
|
|
209
|
+
"The file may be corrupted or contain invalid data. "
|
|
210
|
+
"Please run `biolmai login` to re-authenticate."
|
|
211
|
+
)
|
|
212
|
+
raise AssertionError(err)
|
|
161
213
|
access = access_refresh_dict.get("access")
|
|
162
214
|
refresh = access_refresh_dict.get("refresh")
|
|
163
215
|
headers = {
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: biolmai
|
|
3
|
+
Version: 0.2.5
|
|
4
|
+
Summary: BioLM Python client
|
|
5
|
+
Home-page: https://github.com/BioLM/py-biolm
|
|
6
|
+
Author: BioLM
|
|
7
|
+
Author-email: BioLM <support@biolm.ai>
|
|
8
|
+
License: Apache Software License 2.0
|
|
9
|
+
Keywords: biolmai
|
|
10
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Natural Language :: English
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Requires-Python: >=3.7
|
|
22
|
+
Description-Content-Type: text/x-rst
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
License-File: AUTHORS.rst
|
|
25
|
+
Requires-Dist: httpx>=0.23.0
|
|
26
|
+
Requires-Dist: httpcore
|
|
27
|
+
Requires-Dist: Click>=6.0
|
|
28
|
+
Requires-Dist: requests
|
|
29
|
+
Requires-Dist: aiodns
|
|
30
|
+
Requires-Dist: synchronicity>=0.5.0
|
|
31
|
+
Requires-Dist: aiohttp<=3.8.6; python_version < "3.12"
|
|
32
|
+
Requires-Dist: aiohttp>=3.9.0; python_version >= "3.12"
|
|
33
|
+
Requires-Dist: async-lru
|
|
34
|
+
Requires-Dist: aiofiles
|
|
35
|
+
Dynamic: author
|
|
36
|
+
Dynamic: home-page
|
|
37
|
+
Dynamic: license-file
|
|
38
|
+
Dynamic: requires-python
|
|
39
|
+
|
|
40
|
+
========
|
|
41
|
+
BioLM AI
|
|
42
|
+
========
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
.. image:: https://img.shields.io/pypi/v/biolmai.svg
|
|
46
|
+
:target: https://pypi.python.org/pypi/biolmai
|
|
47
|
+
|
|
48
|
+
.. image:: https://api.travis-ci.com/BioLM/py-biolm.svg?branch=production
|
|
49
|
+
:target: https://travis-ci.org/github/BioLM/py-biolm
|
|
50
|
+
|
|
51
|
+
.. image:: https://readthedocs.org/projects/biolm-ai/badge/?version=latest
|
|
52
|
+
:target: https://biolm-ai.readthedocs.io/en/latest/?version=latest
|
|
53
|
+
:alt: Documentation Status
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
Python client and SDK for `BioLM <https://biolm.ai>`_
|
|
59
|
+
|
|
60
|
+
Install the package:
|
|
61
|
+
|
|
62
|
+
.. code-block:: bash
|
|
63
|
+
|
|
64
|
+
pip install biolmai
|
|
65
|
+
|
|
66
|
+
Basic usage:
|
|
67
|
+
|
|
68
|
+
.. code-block:: python
|
|
69
|
+
|
|
70
|
+
from biolmai import biolm
|
|
71
|
+
|
|
72
|
+
# Encode a single sequence
|
|
73
|
+
result = biolm(entity="esm2-8m", action="encode", type="sequence", items="MSILVTRPSPAGEEL")
|
|
74
|
+
|
|
75
|
+
# Predict a batch of sequences
|
|
76
|
+
result = biolm(entity="esmfold", action="predict", type="sequence", items=["SEQ1", "SEQ2"])
|
|
77
|
+
|
|
78
|
+
# Write results to disk
|
|
79
|
+
biolm(entity="esmfold", action="predict", type="sequence", items=["SEQ1", "SEQ2"], output='disk', file_path="results.jsonl")
|
|
80
|
+
|
|
81
|
+
Asynchronous usage:
|
|
82
|
+
|
|
83
|
+
.. code-block:: python
|
|
84
|
+
|
|
85
|
+
from biolmai.client import BioLMApiClient
|
|
86
|
+
import asyncio
|
|
87
|
+
|
|
88
|
+
async def main():
|
|
89
|
+
model = BioLMApiClient("esmfold")
|
|
90
|
+
result = await model.predict(items=[{"sequence": "MDNELE"}])
|
|
91
|
+
print(result)
|
|
92
|
+
|
|
93
|
+
asyncio.run(main())
|
|
94
|
+
|
|
95
|
+
Overview
|
|
96
|
+
========
|
|
97
|
+
|
|
98
|
+
The BioLM Python client provides a high-level, user-friendly interface for interacting with the BioLM API. It supports both synchronous and asynchronous usage, automatic batching, flexible error handling, and efficient processing of biological data.
|
|
99
|
+
|
|
100
|
+
Main features:
|
|
101
|
+
|
|
102
|
+
- High-level BioLM constructor for quick requests
|
|
103
|
+
- Sync and async interfaces
|
|
104
|
+
- Automatic or custom rate limiting/throttling
|
|
105
|
+
- Schema-based batch size detection
|
|
106
|
+
- Flexible input formats (single key + list, or list of dicts)
|
|
107
|
+
- Low memory usage via generators
|
|
108
|
+
- Flexible error handling (raise, continue, or stop on error)
|
|
109
|
+
- Universal HTTP client for both sync and async
|
|
110
|
+
|
|
111
|
+
Features
|
|
112
|
+
========
|
|
113
|
+
|
|
114
|
+
- **High-level constructor**: Instantly run an API call with a single line.
|
|
115
|
+
- **Sync and async**: Use `BioLM` for sync, or `BioLMApiClient` for async.
|
|
116
|
+
- **Flexible rate limiting**: Use API throttle, disable, or set your own (e.g., '1000/second').
|
|
117
|
+
- **Schema-based batching**: Automatically queries API for max batch size.
|
|
118
|
+
- **Flexible input**: Accepts a single key and list, or list of dicts, or list of lists for advanced batching.
|
|
119
|
+
- **Low memory**: Uses generators for validation and batching.
|
|
120
|
+
- **Error handling**: Raise HTTPX errors, continue on error, or stop on first error.
|
|
121
|
+
- **Disk output**: Write results as JSONL to disk.
|
|
122
|
+
- **Universal HTTP client**: Efficient for both sync and async.
|
|
123
|
+
- **Direct access to schema and batching**: Use `BioLMApi` for advanced workflows, including `.schema()`, `.call()`, and `._batch_call_autoschema_or_manual()`.
|
|
124
|
+
|
|
125
|
+
**Example endpoints and actions:**
|
|
126
|
+
|
|
127
|
+
- `esm2-8m/encode`: Embedding for protein sequences.
|
|
128
|
+
- `esmfold/predict`: Structure prediction for protein sequences.
|
|
129
|
+
- `progen2-oas/generate`: Sequence generation from a context string.
|
|
130
|
+
- `dnabert2/predict`: Masked prediction for protein sequences.
|
|
131
|
+
- `ablang2/encode`: Embeddings for paired-chain antibodies.
|
|
132
|
+
|
|
133
|
+
* Free software: Apache Software License 2.0
|
|
134
|
+
* Documentation: https://docs.biolm.ai
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
biolmai/__init__.py,sha256=
|
|
1
|
+
biolmai/__init__.py,sha256=Gt1leXWNTQMB_CEaZP16IqKYBHVx5Rl8gKFmwS_-uSI,693
|
|
2
2
|
biolmai/api.py,sha256=tqxQ-FoZosE88YmLJPQKskjNQdcb5jzZccywGP73lDc,13002
|
|
3
3
|
biolmai/asynch.py,sha256=BVypJhhEEK2Bek2AhqNGn7FIRJehAbJflUdeeslbXFE,9073
|
|
4
|
-
biolmai/auth.py,sha256=
|
|
4
|
+
biolmai/auth.py,sha256=cjU0ZTJAWTg8IdOYYQ1d-jLXinkYN1EbAyt12lJohgg,8317
|
|
5
5
|
biolmai/biolmai.py,sha256=_NxDPiwT7cnKgnRCRoGZvzBd4jVHJ8DNCuSu3FTznCs,4373
|
|
6
6
|
biolmai/cli.py,sha256=bdb4q8QlN73A6Ttz0e-dBIwoct7PYqy5WSc52jCMIyU,1967
|
|
7
7
|
biolmai/client.py,sha256=nD6sjjnQGinn0tzDVxaKWhsw2AQ3VNhgbsX-Smm9ghc,28310
|
|
@@ -10,10 +10,10 @@ biolmai/const.py,sha256=vCSj-itsusZWoLR27DYQSpuq024GQz3-uKJuDUoPF0Y,1153
|
|
|
10
10
|
biolmai/ltc.py,sha256=al7HZc5tLyUR5fmpIb95hOz5ctudVsc0xzjd_c2Ew3M,49
|
|
11
11
|
biolmai/payloads.py,sha256=BOhEKl9kWkKMXy1YiNw2_eC6MJ4Dn6vKNvkhEBsM7Lw,1735
|
|
12
12
|
biolmai/validate.py,sha256=58XMWrdWoDRmfiNAayWqrYaH3_bjRmEpG_yx6XSjTrM,4168
|
|
13
|
-
biolmai-0.2.
|
|
14
|
-
biolmai-0.2.
|
|
15
|
-
biolmai-0.2.
|
|
16
|
-
biolmai-0.2.
|
|
17
|
-
biolmai-0.2.
|
|
18
|
-
biolmai-0.2.
|
|
19
|
-
biolmai-0.2.
|
|
13
|
+
biolmai-0.2.5.dist-info/licenses/AUTHORS.rst,sha256=TB_ACuFPgVmxn1NspYwksTdT6jdZeShcxfafmi-XWKQ,158
|
|
14
|
+
biolmai-0.2.5.dist-info/licenses/LICENSE,sha256=8yt0SdP38I7a3g0zWqZjNe0VSDQhJA4bWLQSqqKtAVg,583
|
|
15
|
+
biolmai-0.2.5.dist-info/METADATA,sha256=oIrF-Bn8ujjYoZmJfbofhQ4alJBzGEQ-vt27pOTWK0s,4619
|
|
16
|
+
biolmai-0.2.5.dist-info/WHEEL,sha256=JNWh1Fm1UdwIQV075glCn4MVuCRs0sotJIq-J6rbxCU,109
|
|
17
|
+
biolmai-0.2.5.dist-info/entry_points.txt,sha256=ylQnDpCYrxF1F9z_T7NRQcYMWYF5ia_KsTUuboxjEAM,44
|
|
18
|
+
biolmai-0.2.5.dist-info/top_level.txt,sha256=jyQO45JN3g_jbdI8WqMnb0aEIzf4h1MrmPAZkKgfnwY,8
|
|
19
|
+
biolmai-0.2.5.dist-info/RECORD,,
|
biolmai-0.2.3.dist-info/METADATA
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: biolmai
|
|
3
|
-
Version: 0.2.3
|
|
4
|
-
Summary: BioLM Python client
|
|
5
|
-
Home-page: https://github.com/BioLM/py-biolm
|
|
6
|
-
Author: BioLM
|
|
7
|
-
Author-email: BioLM <support@biolm.ai>
|
|
8
|
-
License: Apache Software License 2.0
|
|
9
|
-
Keywords: biolmai
|
|
10
|
-
Classifier: Development Status :: 2 - Pre-Alpha
|
|
11
|
-
Classifier: Intended Audience :: Developers
|
|
12
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
-
Classifier: Natural Language :: English
|
|
14
|
-
Classifier: Programming Language :: Python :: 3
|
|
15
|
-
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
-
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
-
Requires-Python: >=3.7
|
|
22
|
-
Description-Content-Type: text/x-rst
|
|
23
|
-
License-File: LICENSE
|
|
24
|
-
License-File: AUTHORS.rst
|
|
25
|
-
Requires-Dist: httpx>=0.23.0
|
|
26
|
-
Requires-Dist: httpcore
|
|
27
|
-
Requires-Dist: Click>=6.0
|
|
28
|
-
Requires-Dist: requests
|
|
29
|
-
Requires-Dist: aiodns
|
|
30
|
-
Requires-Dist: synchronicity>=0.5.0
|
|
31
|
-
Requires-Dist: aiohttp<=3.8.6; python_version < "3.12"
|
|
32
|
-
Requires-Dist: aiohttp>=3.9.0; python_version >= "3.12"
|
|
33
|
-
Requires-Dist: async-lru
|
|
34
|
-
Requires-Dist: aiofiles
|
|
35
|
-
Dynamic: author
|
|
36
|
-
Dynamic: home-page
|
|
37
|
-
Dynamic: license-file
|
|
38
|
-
Dynamic: requires-python
|
|
39
|
-
|
|
40
|
-
========
|
|
41
|
-
BioLM AI
|
|
42
|
-
========
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.. image:: https://img.shields.io/pypi/v/biolmai.svg
|
|
46
|
-
:target: https://pypi.python.org/pypi/biolmai
|
|
47
|
-
|
|
48
|
-
.. image:: https://api.travis-ci.com/BioLM/py-biolm.svg?branch=production
|
|
49
|
-
:target: https://travis-ci.org/github/BioLM/py-biolm
|
|
50
|
-
|
|
51
|
-
.. image:: https://readthedocs.org/projects/biolm-ai/badge/?version=latest
|
|
52
|
-
:target: https://biolm-ai.readthedocs.io/en/latest/?version=latest
|
|
53
|
-
:alt: Documentation Status
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
Python client and SDK for https://biolm.ai
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
* Free software: Apache Software License 2.0
|
|
62
|
-
* Documentation: https://biolm-ai.readthedocs.io.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
Features
|
|
66
|
-
--------
|
|
67
|
-
|
|
68
|
-
* TODO
|
|
69
|
-
|
|
70
|
-
Credits
|
|
71
|
-
-------
|
|
72
|
-
|
|
73
|
-
This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.
|
|
74
|
-
|
|
75
|
-
.. _Cookiecutter: https://github.com/audreyr/cookiecutter
|
|
76
|
-
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|