bokeh.document.models#
Encapsulate the management of Document models with a DocumentModelManager class.
- class DocumentModelManager(document: Document)[source]#
Manage and provide access to all of the models that belong to a Bokeh Document.
The set of “all models” means specifically all the models reachable from references form a Document’s roots.
- __init__(document: Document)[source]#
- Parameters:
document (Document) – A Document to manage models for A weak reference to the Document will be retained
- flush_synced(is_still_new: Callable[[Model], bool] | None = None) None[source]#
Clean up transient state of the document’s models.
- freeze() Generator[None, None, None][source]#
Defer expensive model recomputation until intermediate updates are complete.
Making updates to the model graph might trigger events that cause more updates. This context manager can be used to prevent expensive model recomputation from happening until all events have finished and the Document state is quiescent.
Example:
with models.freeze(): # updates that might change the model graph, that might trigger # updates that change the model graph, etc. Recomputation will # happen once at the end.
- get_all_by_name(name: str) list[Model][source]#
Find all the models for this Document with a given name.
- Parameters:
name (str) – the name of a model to search for
- Returns
A list of models
- get_by_id(id: ID) Model | None[source]#
Find the model for this Document with a given ID.
- Parameters:
id (ID) – model ID to search for If no model with the given ID exists, returns None
- Returns:
a Model or None
- get_one_by_name(name: str) Model | None[source]#
Find a single model for this Document with a given name.
If multiple models are found with the name, an error is raised.
- Parameters:
name (str) – the name of a model to search for
- Returns
A model with the given name, or None
- recompute() None[source]#
Recompute the set of all models based on references reachable from the Document’s current roots.
This computation can be expensive. Use
freezeto wrap operations that update the model object graph to avoid over-recomputationNote
Any models that remove during recomputation will be noted as “previously seen”
- seen(id: ID) bool[source]#
Report whether a model id has ever previously belonged to this Document.
- Parameters:
id (ID) – the model id of a model to check
- Returns:
bool
- update_name(model: Model, old_name: str | None, new_name: str | None) None[source]#
Update the name for a model.
Note
This function and the internal name mapping exist to support optimizing the common case of name lookup for models. Keeping a dedicated name index is faster than using generic
bokeh.queryfunctions with a name selector