bokeh.core.property.bases¶
Provide base classes for the Bokeh property system.
Note
These classes form part of the very low-level machinery that implements the Bokeh model and property system. It is unlikely that any of these classes or their methods will be applicable to any standard usage or to anyone who is not directly developing on Bokeh’s own infrastructure.
- class ContainerProperty(default: Init[T] = Intrinsic, help: str | None = None, serialized: bool | None = None, readonly: bool = False)[source]¶
A base class for Container-like type properties.
- class PrimitiveProperty(default: Init[T] = Intrinsic, help: str | None = None, serialized: bool | None = None, readonly: bool = False)[source]¶
A base class for simple property types.
Subclasses should define a class attribute
_underlying_type
that is a tuple of acceptable type values for the property.Example
A trivial version of a
Float
property might look like:class Float(PrimitiveProperty): _underlying_type = (numbers.Real,)
- from_json(json: Any, *, models: Dict[str, HasProps] | None = None) T [source]¶
Convert from JSON-compatible values into a value for this property.
JSON-compatible values are: list, dict, number, string, bool, None
- validate(value: Any, detail: bool = True) None [source]¶
Determine whether we can set this property from this value.
Validation happens before transform()
- Parameters
value (obj) – the value to validate against this property type
detail (bool, options) –
whether to construct detailed exceptions
Generating detailed type validation error messages can be expensive. When doing type checks internally that will not escape exceptions to users, these messages can be skipped by setting this value to False (default: True)
- Returns
None
- Raises
ValueError if the value is not valid for this property type –
- class Property(default: Init[T] = Intrinsic, help: str | None = None, serialized: bool | None = None, readonly: bool = False)[source]¶
Base class for Bokeh property instances, which can be added to Bokeh Models.
- Parameters
default (obj, optional) – A default value for attributes created from this property to have.
help (str or None, optional) – A documentation string for this property. It will be automatically used by the bokeh_prop extension when generating Spinx documentation. (default: None)
serialized (bool, optional) – Whether attributes created from this property should be included in serialization (default: True)
readonly (bool, optional) – Whether attributes created from this property are read-only. (default: False)
- __init__(default: Init[T] = Intrinsic, help: str | None = None, serialized: bool | None = None, readonly: bool = False)[source]¶
- accepts(tp: Union[Type[bokeh.core.property.bases.Property[Any]], bokeh.core.property.bases.Property[Any]], converter: Callable[[bokeh.core.property.bases.Property[Any]], bokeh.core.property.bases.T]) bokeh.core.property.bases.Property[bokeh.core.property.bases.T] [source]¶
Declare that other types may be converted to this property type.
- Parameters
tp (Property) – A type that may be converted automatically to this property type.
converter (callable) – A function accepting
value
to perform conversion of the value to this property type.
- Returns
self
- asserts(fn: Callable[[HasProps, T], bool], msg_or_fn: str | Callable[[HasProps, str, T], None]) Property[T] [source]¶
Assert that prepared values satisfy given conditions.
Assertions are intended in enforce conditions beyond simple value type validation. For instance, this method can be use to assert that the columns of a
ColumnDataSource
all collectively have the same length at all times.- Parameters
fn (callable) – A function accepting
(obj, value)
that returns True if the value passes the assertion, or False otherwise.msg_or_fn (str or callable) – A message to print in case the assertion fails, or a function accepting
(obj, name, value)
to call in in case the assertion fails.
- Returns
self
- from_json(json: Any, *, models: Dict[ID, HasProps] | None = None) T [source]¶
Convert from JSON-compatible values into a value for this property.
JSON-compatible values are: list, dict, number, string, bool, None
- is_valid(value: Any) bool [source]¶
Whether the value passes validation
- Parameters
value (obj) – the value to validate against this property type
- Returns
True if valid, False otherwise
- make_descriptors(name: str) List[bokeh.core.property.descriptors.PropertyDescriptor[bokeh.core.property.bases.T]] [source]¶
Return a list of
PropertyDescriptor
instances to install on a class, in order to delegate attribute access to this property.- Parameters
name (str) – the name of the property these descriptors are for
- Returns
list[PropertyDescriptor]
The descriptors returned are collected by the
MetaHasProps
metaclass and added toHasProps
subclasses during class creation.
- matches(new: bokeh.core.property.bases.T, old: bokeh.core.property.bases.T) bool [source]¶
Whether two parameters match values.
If either
new
orold
is a NumPy array or Pandas Series or Index, then the result ofnp.array_equal
will determine if the values match.Otherwise, the result of standard Python equality will be returned.
- Returns
True, if new and old match, False otherwise
- serialize_value(value: bokeh.core.property.bases.T) Any [source]¶
Change the value into a JSON serializable format.
- themed_default(cls: Type[HasProps], name: str, theme_overrides: Dict[str, Any] | None) T [source]¶
The default, transformed by prepare_value() and the theme overrides.
- transform(value: Any) bokeh.core.property.bases.T [source]¶
Change the value into the canonical format for this property.
- Parameters
value (obj) – the value to apply transformation to.
- Returns
transformed value
- Return type
obj
- validate(value: Any, detail: bool = True) None [source]¶
Determine whether we can set this property from this value.
Validation happens before transform()
- Parameters
value (obj) – the value to validate against this property type
detail (bool, options) –
whether to construct detailed exceptions
Generating detailed type validation error messages can be expensive. When doing type checks internally that will not escape exceptions to users, these messages can be skipped by setting this value to False (default: True)
- Returns
None
- Raises
ValueError if the value is not valid for this property type –
- wrap(value: bokeh.core.property.bases.T) bokeh.core.property.bases.T [source]¶
Some property types need to wrap their values in special containers, etc.