biolm.models

Model

Recommended interface for model inference: bind to a model slug once, then call encode, predict, generate, or lookup. Wraps the HTTP client in biolm.core with a simpler, product-focused API.

Catalog and example helpers live in biolm.models.examples (also re-exported from biolm as get_example and list_models).

When to use

  • Model — preferred for scripts, notebooks, and apps that call the same model repeatedly.

  • Lower-level clientsbiolm(), BioLMApi, and BioLMApiClient for advanced batching, async, and schema control; see biolm.core.

Examples

python
from biolm import Model

model = Model("esm2-8m")
embeddings = model.encode(type="sequence", items=["SEQ1", "SEQ2"])

model = Model("esmfold")
structures = model.predict(type="sequence", items=["SEQ1", "SEQ2"])

model = Model("progen2-oas")
sequences = model.generate(
    type="context",
    items="M",
    params={"temperature": 0.7, "num_samples": 2, "max_length": 17},
)

Example generation

Generate copy-pasteable Python for a model action, or browse the model catalog:

python
from biolm import Model
from biolm.models.examples import get_example, list_models

model = Model("esm2-8m")
print(model.get_example("encode"))
print(get_example("esm2-8m", "encode"))

for entry in list_models():
    print(entry.get("model_slug") or entry.get("name"))

From the terminal: biolm model example esm2-8m encode. See biolm model.

API

class biolm.models.Model(name: str, api_key: str | None = None, **kwargs)

User-friendly model interface for BioLM API.

Args:

name (str): The model name (e.g., ‘esm2-8m’, ‘esmfold’). api_key (Optional[str]): API key for authentication. **kwargs: Additional arguments passed to BioLMApi.

encode(items: Any | List[Any], type: str | None = None, params: dict | None = None, progress: bool = True, progress_callback: Callable[[int, int], None] | None = None, **kwargs)

Encode using the model.

Args:

items: Single item or list of items to encode. type: Type of item (e.g., ‘sequence’). Required if items are not dicts. params: Optional parameters for the encoding. progress: If True (default), show Rich progress bar (multiple items only). progress_callback: Optional (completed, total) callback; overrides progress=True if provided. **kwargs: Additional arguments (stop_on_error, output, file_path, etc.).

Returns:

Encoding results.

generate(items: Any | List[Any], type: str | None = None, params: dict | None = None, progress: bool = True, progress_callback: Callable[[int, int], None] | None = None, **kwargs)

Generate using the model.

Args:

items: Single item or list of items to generate from. type: Type of item (e.g., ‘context’, ‘pdb’). Required if items are not dicts. params: Optional parameters for the generation. progress: If True (default), show Rich progress bar (multiple items only). progress_callback: Optional (completed, total) callback; overrides progress=True if provided. **kwargs: Additional arguments (stop_on_error, output, file_path, etc.).

Returns:

Generation results.

get_example(action: str | None = None, format: str = 'python', **kwargs) str

Get SDK usage example for this model.

Args:

action: Action name (encode, predict, generate, lookup). If None, generates for first available action. format: Output format (‘python’, ‘markdown’, ‘rst’, ‘json’). **kwargs: Additional arguments passed to ExampleGenerator (base_url).

Returns:

Formatted example string.

get_examples(format: str = 'python', **kwargs) str

Get SDK usage examples for all supported actions of this model.

Args:

format: Output format (‘python’, ‘markdown’, ‘rst’, ‘json’). **kwargs: Additional arguments passed to ExampleGenerator (base_url).

Returns:

Formatted examples string with all actions.

lookup(query: dict | List[dict], **kwargs)

Lookup using the model.

Args:

query: Query dict or list of query dicts. **kwargs: Additional arguments (raw, output, file_path).

Returns:

Lookup results.

predict(items: Any | List[Any], type: str | None = None, params: dict | None = None, progress: bool = True, progress_callback: Callable[[int, int], None] | None = None, **kwargs)

Predict using the model.

Args:

items: Single item or list of items to predict. type: Type of item (e.g., ‘sequence’, ‘pdb’). Required if items are not dicts. params: Optional parameters for the prediction. progress: If True (default), show Rich progress bar (multiple items only). progress_callback: Optional (completed, total) callback; overrides progress=True if provided. **kwargs: Additional arguments (stop_on_error, output, file_path, etc.).

Returns:

Prediction results.

biolm.models.examples.get_example(model_name: str, action: str | None = None, format: str = 'python', api_key: str | None = None, base_url: str | None = None) str

Generate SDK usage example for a model (synchronous).

Args:

model_name: Name of the model. action: Action name (optional, will try to detect). format: Output format (‘python’, ‘markdown’, ‘rst’, ‘json’). api_key: Optional API key. base_url: Optional base URL.

Returns:

Formatted example string.

biolm.models.examples.list_models(api_key: str | None = None, base_url: str | None = None) List[Dict[str, Any]]

List all available models from community-api-models endpoint (synchronous).

Args:

api_key: Optional API key. base_url: Optional base URL.

Returns:

List of model dictionaries.

See also

We speak the language of bio-AI

© 2022 - 2026 BioLM. All Rights Reserved.