API Reference
Client
Client for the OmniPath web API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Base URL of the OmniPath API. |
DEFAULT_BASE_URL
|
backend
|
BackendType
|
Default DataFrame backend. |
'auto'
|
cache
|
bool
|
Whether to cache downloaded files. |
True
|
Attributes
endpoint_registry
property
All registered endpoints.
Functions
entities(backend=None, **filters)
Export entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
BackendType | None
|
Override the default DataFrame backend. |
None
|
**filters
|
Any
|
Filter parameters (entity_ids, entity_types, sources, taxonomy_ids, etc.). |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
A DataFrame of entities. |
relations(as_graph=False, backend=None, **filters)
Export relations (interactions, memberships, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
as_graph
|
bool
|
If True, return an |
False
|
backend
|
BackendType | None
|
Override the default DataFrame backend. |
None
|
**filters
|
Any
|
Filter parameters (sources, predicates, interaction_types, relation_categories, subject_entity_pks, object_entity_pks, etc.). |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
A DataFrame of relations, or an |
annotations(backend=None, **filters)
Export ontology annotations attached to entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
BackendType | None
|
Override the default DataFrame backend. |
None
|
**filters
|
Any
|
Filter parameters (prefixes, ontology_prefixes, entity_pks). |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
A DataFrame of annotations. |
resolve(identifiers)
Resolve free-text identifiers to entity primary keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
identifiers
|
list[str]
|
List of identifier strings (UniProt accessions, ChEBI IDs, gene symbols, free-text names, etc.). |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A dict with |
Any
|
|
entities_slice(filters=None, query='', limit=50, offset=0)
Page through entities with filters and free-text search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
dict[str, Any] | None
|
|
None
|
query
|
str
|
Free-text search across canonical identifiers and aliases. |
''
|
limit
|
int
|
Maximum number of rows. |
50
|
offset
|
int
|
Row offset. |
0
|
Returns:
| Type | Description |
|---|---|
Any
|
A dict with |
relations_slice(filters=None, query='', limit=50, offset=0)
Page through relations with filters and free-text search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filters
|
dict[str, Any] | None
|
|
None
|
query
|
str
|
Free-text search. |
''
|
limit
|
int
|
Maximum number of rows. |
50
|
offset
|
int
|
Row offset. |
0
|
Returns:
| Type | Description |
|---|---|
Any
|
A dict with |
resources()
List the resource catalog with build statistics.
Returns:
| Type | Description |
|---|---|
Any
|
List of resource records (resource_id, resource_name, |
Any
|
categories, entity_count, interaction_count, etc.). |
ontology_terms(term_ids)
Batch lookup of ontology terms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
term_ids
|
list[str]
|
List of term IDs (e.g. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A dict with term information. |
ontology_tree(term_ids)
Get merged hierarchy tree for terms.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
term_ids
|
list[str]
|
List of term IDs. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A tree structure dict. |
search_terms(queries, limit=10)
Search ontology terms by name or synonym.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
queries
|
list[str]
|
Search strings. |
required |
limit
|
int
|
Maximum number of results per query. |
10
|
Returns:
| Type | Description |
|---|---|
Any
|
A dict with search results. |
ontologies()
List all available ontologies.
Returns:
| Type | Description |
|---|---|
Any
|
A dict with ontology information. |
relation_evidence(relation_pk)
Get full evidence for a single relation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relation_pk
|
int
|
The relation primary key. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Evidence data as a dict. |
lookup(query, id_types=DEFAULT_ID_TYPES, *, keep_canonical=False)
Resolve free-text or PK input and return enriched entity rows.
Wraps resolve() + entities() and pivots the requested
id_types into named columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | int | Sequence[str | int]
|
A name, accession, or entity_pk; or a list of any combination thereof. Strings are auto-resolved. |
required |
id_types
|
Sequence[str]
|
Aliases (or raw codes) to surface as columns. See
|
DEFAULT_ID_TYPES
|
keep_canonical
|
bool
|
Retain |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
A polars DataFrame with one row per matched entity_pk. |
related(query=None, *, subject=None, object=None, sources=None, predicates=None, relation_categories=None, participant_types=None, id_types=DEFAULT_ID_TYPES, group_by=None, limit=None, keep_canonical=False)
Pull joined relations around a query in one call.
Resolves any string inputs, fetches the matching relations,
fetches the entity records for every involved PK, and joins
them back into a wide DataFrame with subject_* / object_*
columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str | int | Sequence[str | int] | None
|
Positional argument matching the entity on either
side of the relation. Use |
None
|
subject
|
str | int | Sequence[str | int] | None
|
Restrict to relations where this entity is the subject. |
None
|
object
|
str | int | Sequence[str | int] | None
|
Restrict to relations where this entity is the object. |
None
|
sources
|
Sequence[str] | None
|
Resource IDs to include (e.g. |
None
|
predicates
|
Sequence[str] | None
|
Predicate filter (e.g. |
None
|
relation_categories
|
Sequence[str] | None
|
Category filter ( |
None
|
participant_types
|
Sequence[str] | None
|
Friendly aliases ( |
None
|
id_types
|
Sequence[str]
|
Identifier aliases to pivot as |
DEFAULT_ID_TYPES
|
group_by
|
str | None
|
Sort the result by this column (e.g.
|
None
|
limit
|
int | None
|
Truncate the output to this many rows. |
None
|
keep_canonical
|
bool
|
Retain canonical_identifier / raw identifiers columns. |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
A wide polars DataFrame. |
cache_clear()
Remove every cached response (incl. the cached OpenAPI spec). Returns the number of entries removed.
fresh()
Context manager that re-downloads any response touched within the block on first use, then serves subsequent identical requests from the freshly populated cache.
Example::
with client.fresh():
df = client.related('caffeine', sources=['bindingdb'])
params(endpoint)
Parameters for an endpoint.
values(endpoint, param)
Allowed values for a parameter on an endpoint.
Module-level functions
High-level helpers
Export endpoints
Lookup and slice
Ontology
Cache control
Context manager that re-downloads any responses touched within the block (first-touch refresh, then served from the freshly populated cache).
Example::
import omnipath_client as oc
with oc.fresh():
df = oc.related('caffeine', sources=['bindingdb'])
Response parsing
Parse an API response and convert to the requested backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path | BytesIO
|
Path to a file or an in-memory buffer. |
required |
response_format
|
ResponseFormat
|
The format of the response data. |
'parquet'
|
backend
|
BackendType
|
The target DataFrame backend. Use |
'auto'
|
Returns:
| Type | Description |
|---|---|
Any
|
A DataFrame in the requested backend format. |
Graph conversion
Convert a relations DataFrame to an annnet Graph.
Maps relation columns to annnet edge format:
subject_entity_pk -> source, object_entity_pk -> target.
Vertex IDs are entity primary keys; resolve them via
OmniPath.entities_slice if you need human-readable labels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
Any
|
A relations DataFrame (any backend). |
required |
Returns:
| Type | Description |
|---|---|
Any
|
An |
Pivots and aliases
Pivot the long-form identifiers column into wide columns.
For each alias in id_types the entity's matching identifiers
are collected, the shortest value is picked as the
representative, and a new column is added.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entities_df
|
Any
|
A polars DataFrame with at least |
required |
id_types
|
Sequence[str]
|
Aliases (or raw codes) to pivot into columns. |
DEFAULT_ID_TYPES
|
prefix
|
str
|
String prefixed to each new column name (e.g. |
''
|
keep_canonical
|
bool
|
If True, retain the raw |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
A polars DataFrame with one row per input row and one new |
Any
|
column per requested |
Left-join entities to both sides of a relations table.
Produces subject_* and object_* columns for every
id_types entry plus subject_entity_type /
object_entity_type. The original relation columns
(relation_pk, predicate, relation_category,
evidence_count, sources) are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
relations_df
|
Any
|
A polars DataFrame from |
required |
entities_df
|
Any
|
A polars DataFrame from |
required |
id_types
|
Sequence[str]
|
Aliases to pivot. |
DEFAULT_ID_TYPES
|
keep_canonical
|
bool
|
Whether to retain canonical_identifier / identifiers columns on each side. |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
A wide polars DataFrame. |
Inventory
Registry of all known API endpoints and parameters.
Fetches the OpenAPI schema from the server and parses it into endpoint definitions. Falls back to static definitions on failure.
Attributes
endpoints
property
All registered endpoints.
Functions
load(force_refresh=False)
Load the inventory from the server or static fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force_refresh
|
bool
|
If True, bypass any cached inventory and re-fetch. |
False
|
params(endpoint)
Parameters for a given endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The endpoint key, e.g.
|
required |
Returns:
| Type | Description |
|---|---|
dict[str, ParamDef]
|
A dict mapping parameter names to |
allowed_values(endpoint, param)
Allowed values for a parameter on an endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The endpoint key. |
required |
param
|
str
|
The parameter name. |
required |
Returns:
| Type | Description |
|---|---|
list[str] | None
|
A list of allowed values, or |
Query
Builds and validates queries against the API inventory.
Functions
build(endpoint, **params)
Build a validated query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint
|
str
|
The endpoint key, e.g.
|
required |
**params
|
Any
|
Query parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
Query
|
A validated |
Raises:
| Type | Description |
|---|---|
UnknownEndpointError
|
If the endpoint is not in the inventory. |
UnknownParameterError
|
If a parameter is not recognized. |
InvalidParameterValueError
|
If a value is not in the allowed set. |
A validated query for an OmniPath API endpoint.
Attributes
url
property
Full URL for this query.
json_body
property
JSON request body for POST endpoints.
Returns None for GET endpoints.
query_params
property
URL query parameters for GET endpoints.
Returns an empty dict for POST endpoints.
path_params
property
Path parameters extracted from the query params.
resolved_url
property
URL with path parameters substituted.
Data classes
Exceptions
Exception hierarchy for omnipath-client.
Classes
OmniPathError
Bases: Exception
Base exception for all omnipath-client errors.
OmniPathAPIError
OmniPathConnectionError
Bases: OmniPathError
Network or connection error when contacting the API.
QueryValidationError
Bases: OmniPathError
Base for query parameter validation errors.
UnknownEndpointError
Bases: QueryValidationError
The requested endpoint is not in the inventory.
UnknownParameterError
Bases: QueryValidationError
A parameter name is not recognized for the endpoint.
InvalidParameterValueError
Bases: QueryValidationError
A parameter value is not in the set of allowed values.
MissingParameterError
Bases: QueryValidationError
A required parameter was not provided.
BackendNotAvailableError
Bases: OmniPathError
The requested DataFrame backend is not installed.
Utils: ID Translation
Translate a DataFrame column via the web service.
Works with pandas, polars, and pyarrow DataFrames via narwhals.