### BioLM Python SDK Quickstart Example Source: https://docs.biolm.ai/latest/sdk/overview Demonstrates how to use the BioLM Python SDK for common tasks like encoding sequences, predicting protein structures, and generating new sequences. It shows the basic function call structure with different entities and actions. ```python from biolmai import biolm # Encode a sequence (e.g. ESM2-8M) result = biolm(entity="esm2-8m", action="encode", type="sequence", items="MSILVTRPSPAGEEL") # Predict structure (e.g. ESMFold) result = biolm(entity="esmfold", action="predict", type="sequence", items=["MDNELE", "MENDEL"]) # Generate sequences (e.g. ProGen2-OAS) result = biolm( entity="progen2-oas", action="generate", type="context", items="M", params={"temperature": 0.7, "num_samples": 2, "max_length": 17} ) ``` -------------------------------- ### Generate BioLM Model SDK Examples via CLI Source: https://docs.biolm.ai/latest/cli/model This command generates example code snippets for using BioLM models with the SDK. It can target specific models and actions, and output the examples to a file. Requires the BioLM CLI. ```bash biolmai model example biolmai model example esm2-8m biolmai model example esm2-8m --action encode biolmai model example esm2-8m --output example.py ``` -------------------------------- ### Install BioLM AI from source Source: https://docs.biolm.ai/latest/getting-started/installation Installs BioLM AI after downloading the source code, either by cloning the repository or downloading a tarball. This command should be run from the root of the source directory. ```bash python setup.py install ``` -------------------------------- ### Install BioLM AI Package Source: https://docs.biolm.ai/latest/getting-started/quickstart Installs the BioLM AI Python package using pip. This is the first step to using the BioLM AI SDK. ```bash pip install biolmai ``` -------------------------------- ### BioLM Simple Sync Interface Example (Python) Source: https://docs.biolm.ai/latest/getting-started/concepts Demonstrates the simplest synchronous interface for making single or batch calls to BioLM. It requires no setup and directly returns results as a dictionary for single items or a list of dictionaries for batch calls. This interface uses an asynchronous backend for performance. ```python from biolmai import biolm # Single item: returns a dict result = biolm(entity="esmfold", action="predict", items="MDNELE") print(result["mean_plddt"]) # Batch: returns a list of dicts result = biolm(entity="esmfold", action="predict", items=["MDNELE", "MENDEL"]) ``` -------------------------------- ### Async Context Manager Usage Example Source: https://docs.biolm.ai/latest/sdk/usage/async-sync Provides a practical example of using BioLMApiClient with an asynchronous context manager to perform a prediction. ```python async with BioLMApiClient("esmfold") as model: result = await model.predict(items=[{"sequence": "MDNELE"}]) ``` -------------------------------- ### BioLM AI Quickstart: Basic Usage (biolm function) Source: https://docs.biolm.ai/latest/getting-started/quickstart Demonstrates basic, synchronous usage of the `biolm()` function for encoding sequences, predicting with models like esmfold, and writing results to disk. It also shows how to handle errors when `raise_httpx` is set to `False`. ```python from biolmai import biolm # Encode a single sequence result = biolm(entity="esm2-8m", action="encode", type="sequence", items="MSILVTRPSPAGEEL") # Predict a batch of sequences result = biolm(entity="esmfold", action="predict", type="sequence", items=["SEQ1", "SEQ2"]) # Write results to disk biolm(entity="esmfold", action="predict", type="sequence", items=["SEQ1", "SEQ2"], output='disk', file_path="results.jsonl") # Check for errors when not raising (raise_httpx=False) result = biolm(entity="esmfold", action="predict", type="sequence", items=["SEQ1", "BADSEQ"], raise_httpx=False) for r in result: if isinstance(r, dict) and "error" in r: print("Error:", r["error"]) else: print("OK") ``` -------------------------------- ### Start Local OAuth Callback Server Source: https://docs.biolm.ai/latest/_modules/biolmai/core/auth Starts a simple HTTP server on a specified port to listen for OAuth 2.0 callback requests. It parses the callback URL to extract authorization codes or error information. ```python import http.server import queue import urllib.parse def _start_local_callback_server(expected_state: str, port: int = 8765, timeout: int = 180) -> queue.Queue: """Start a local HTTP server to receive OAuth callback. Args: expected_state: Expected OAuth state parameter for CSRF protection port: Port to bind to (default 8765, must match OAUTH_REDIRECT_URI) timeout: Timeout in seconds to wait for callback Returns: Queue that will receive the authorization code """ received = queue.Queue() class CallbackHandler(http.server.BaseHTTPRequestHandler): def do_GET(self): parsed = urllib.parse.urlparse(self.path) if parsed.path != "/callback": self.send_response(404) self.end_headers() return params = dict(urllib.parse.parse_qsl(parsed.query)) code = params.get("code") state = params.get("state") error = params.get("error") error_description = params.get("error_description") if error: self.send_response(400) self.send_header("Content-Type", "text/html") self.end_headers() error_msg = error_description or error error_html = f"""