Skip to main content

definitions

HttpMethod

from dara.core.definitions import HttpMethod

class HttpMethod(Enum)

HTTP Methods enum

ErrorHandlingConfig

from dara.core.definitions import ErrorHandlingConfig

class ErrorHandlingConfig(BaseModel)

Attributes

  • title: str
  • description: str
  • raw_css:

title

Title to display in the error boundary

description

Description to display in the error boundary

raw_css

Raw styling to apply to the displayed error boundary

TemplateMarkerCreator

from dara.core.definitions import TemplateMarkerCreator

class TemplateMarkerCreator()

Creates a TemplateMarker instance for a given field name when accessing any attribute on the instance. Should not be used standalone, it is injected into function parameters when using the @template decorator.

Example

from dara.core.definitions import TemplateMarkerCreator

creator = TemplateMarkerCreator()
creator.foo
# <TemplateMarker field_name='foo'>

BaseFallback

from dara.core.definitions import BaseFallback

class BaseFallback(DaraBaseModel)

Attributes

  • suspend_render: Union[bool, int]

suspend_render

Arguments:

  • suspend_render: bool or int, optional Determines the suspense behavior of the component during state updates.

  • If True, the component will always use suspense during state updates. This means the component will suspend rendering and show a fallback UI until the new state is ready.

  • If False, the component will always show the previous state while loading the new state. This means the component will never suspend during state updates. The fallback UI will only be shown on the first render.

  • If a positive integer (default is 200), this denotes the threshold in milliseconds. The component will show the previous state while loading the new state, but will suspend and show a fallback UI after the given timeout if the new state is not ready.

ComponentInstance

from dara.core.definitions import ComponentInstance

class ComponentInstance(DaraBaseModel)

Definition of a Component Instance

Attributes

  • uid: Optional[str]
  • js_module:
  • py_component:
  • js_component:
  • required_routes:
  • raw_css:
  • templated: bool
  • track_progress: Optional[bool]
  • error_handler: Optional[ErrorHandlingConfig]
  • fallback: Optional[BaseFallback]
  • id_: Optional[str]
  • for_: Optional[str]

js_module

JS module including the implementation of the component.

Required for non-local components.

py_component

Python unique component name. If not set, defaults to the class name.

js_component

JS component name. If not set, defaults to the class name.

required_routes

List of routes the component depends on. Will be implicitly added to the app if this component is used

raw_css

Raw styling to apply to the component. Can be an dict/CSSProperties instance representing the styles tag, or a string injected directly into the CSS of the wrapping component.


from dara.core import CSSProperties

# `style` - use the class for autocompletion/typesense
Stack(..., raw_css=CSSProperties(maxWidth='100px'))

# `style` - you can also use plain dict
Stack(..., raw_css={'maxWidth': '100px'})

# You can also provide CSS to inject directly
Stack(..., raw_css=\"\"\"
max-width: 100px;
\"\"\")

templated

Whether the component is templated, created by the @template decorator

track_progress

Whether to use ProgressTracker to display progress updates from a task the component is subscribed to

error_handler

Configure the error handling for the component

fallback

Fallback component to render in place of the actual UI if it has not finished loading

id_

An optional unique identifier for the component, defaults to None

This has no runtime effect and are intended to help identify components with human-readable names in the serialized trees, not in the DOM

for_

An optional for attribute for the component, defaults to None

This has no runtime effect and are intended to help identify components with human-readable names in the serialized trees, not in the DOM

CallableClassComponent

from dara.core.definitions import CallableClassComponent

@runtime_checkable
class CallableClassComponent(Protocol)

Callable class component protocol. Describes any class with a call instance method returning a component instance.

discover

def discover(outer_obj: DiscoverT) -> DiscoverT

Special marker for the Dara component discovery to continue the discovery.

Will make sure to statically register all encountered dependencies of marked functional component or component class. Should not be necessary in most cases, mainly useful when creating component libraries.

StyledComponentInstance

from dara.core.definitions import StyledComponentInstance

class StyledComponentInstance(ComponentInstance)

Base class for a component implementing the common styling props

Arguments:

  • align: an alignment string, any flexbox alignment or start/center/end are accepted
  • background: set a background color on the component
  • basis: the flex-basis of the component, see css guidelines for flex-basis for formats
  • bold: whether to bold the font, defaults to False
  • border: whether to apply a border to the component, see css guidelines for formats
  • border_radius: set the radius of a components corners (i.e. round them), see css guidelines for formats
  • color: the text color of the component, defaults to inherit from document
  • font: the font to use for this component, defaults to inherit from document
  • font_size: the size of the font, defaults to inherit from document
  • gap: the gap between the flex components children
  • grow: the flex-grow of the component, see css guidelines for flex-grow for formats
  • height: the height of the component, can be an number, which will be converted to pixels, or a string
  • hug: Whether to hug the content, defaults to False
  • italic: whether to italicize the font, defaults to False
  • margin: the amount of margin to apply to the component, see css guidelines for formats
  • max_height: the maximum height of the component, can be an number or a string
  • max_width: the maximum width of the component, can be an number or a string
  • min_height: the minimum height of the component, can be an number or a string
  • min_width: the minimum width of the component, can be an number or a string
  • overflow: whether to apply overflow to the component, see css guidelines for formats
  • padding: the amount of padding to apply to the component, see css guidelines for formats
  • shrink: the flex-shrink of the component, see css guidelines for flex-shrink for formats
  • underline: whether to underline the font, defaults to False
  • width: the width of the component, can be an number, which will be converted to pixels, or a string

Attributes

  • align: Optional[str]
  • background: Optional[str]
  • basis:
  • bold: bool
  • border: Optional[str]
  • border_radius:
  • children:
  • color: Optional[str]
  • font: Optional[str]
  • font_size: Optional[str]
  • gap:
  • grow:
  • height:
  • hug: Optional[bool]
  • italic: bool
  • margin:
  • max_height:
  • max_width:
  • min_height:
  • min_width:
  • overflow: Optional[str]
  • position: Optional[str]
  • padding:
  • shrink:
  • underline: bool
  • width:

JsComponentDef

from dara.core.definitions import JsComponentDef

class JsComponentDef(BaseModel)

Definition of a JS Component

Attributes

  • js_module: Optional[str]
  • js_component: Optional[str]
  • py_module: str
  • name: str
  • type: str

js_module

JS module where the component implementation lives.

Not required for local components as they are located via dara.config.json

js_component

JS component name. If not set, defaults to name property.

py_module

Name of the PY module with component definition, used for versioning

name

Name of the component, must match the Python definition and JS implementation

PyComponentDef

from dara.core.definitions import PyComponentDef

class PyComponentDef(BaseModel)

Definition of a Python Component

Attributes

  • func:
  • name: str
  • dynamic_kwargs:
  • fallback: Optional[BaseFallback]
  • polling_interval: Optional[int]
  • render_component: Callable[Awaitable[Any]]
  • type: str

render_component

Handler to render the component. Defaults to dara.core.visual.dynamic_component.render_component

TemplateComponentDef

from dara.core.definitions import TemplateComponentDef

class TemplateComponentDef(GenericModel, Generic[ComponentT])

Definition of a Template Component, as returned by the @template decorator. When called, executes the decorated function with the marker creator injected and returns a component instance, annotated with templated=True.

Attributes

  • func: Callable[ComponentT]
  • name: str

template

from dara.core.definitions import template

class template(Generic[ComponentT])

The @template decorator is used to define reusable components that can be dynamically rendered based on input data. It allows you to create template components with customizable properties that can be injected into certain components equipped to handle such templates.

Usage:

  1. Define a template component using the @template decorator and provide a function that accepts a first argument of type template.Value. This argument is automatically injected by the decorator, and its name can be chosen by the user. Inside the function, use the first argument to access properties that will be injected into the component when rendered.

Example:

from dara.core import template
from dara_dashboarding_extension import Card, Heading, Text, Button

@template
def ExperimentCard(data: template.Value):
return Card(
Heading(data.title, level=2),
Text(data.description),
Button(data.button_text, raw_css={'backgroundColor': data.button_color}),
...
)
  1. Use the template component in certain components that can handle such templates, like the For component.

Example:

from dara.core import Variable, For

var = Variable([
{
'title': 'Experiment 1',
'description': 'This is a description of experiment 1',
'button_text': 'Run Experiment 1',
'button_color': 'red',
},
...
])

For(
key_accessor='title',
data=var,
template=ExperimentCard(),
)

The For component will dynamically render elements according to the template, using the properties specified by the template.Value. As opposed to py_component, the decorated component only executes once, when called.

Note that only certain components are equipped to handle template components, so refer to the component documentation for compatibility information.

Value

The template.Value is a special class used with the @template decorator to define dynamic properties that will be injected into a template component when it is rendered.

When defining a template component, use the template.Value as the type for the first argument of the function. This argument is automatically injected by the @template decorator, and its name can be chosen by the user. Access the properties of the Value within the function to create dynamic components based on the injected data.

Example usage:

from dara.core import template
from dara_dashboarding_extension import Card, Heading, Text, Button

@template
def ExperimentCard(data: template.Value):
return Card(
Heading(data.title, level=2),
Text(data.description),
Button(data.button_text, raw_css={'backgroundColor': data.button_color}),
...
)

EndpointConfiguration

from dara.core.definitions import EndpointConfiguration

class EndpointConfiguration(BaseModel)

Base class for endpoint configurations

ApiRoute

from dara.core.definitions import ApiRoute

class ApiRoute(BaseModel)

Definition of a route for the application's api

Attributes

  • dependencies: List[Depends]
  • handler: Callable
  • method: HttpMethod
  • url: str

Page

from dara.core.definitions import Page

class Page(BaseModel)

Definition of a Page

Attributes

  • icon: Optional[str]
  • content: ComponentInstanceType
  • name: str
  • sub_pages:
  • url_safe_name: str
  • include_in_menu: Optional[bool]
  • on_load: Optional[Action]

TemplateRoute

from dara.core.definitions import TemplateRoute

class TemplateRoute(BaseModel)

Definition of a route for the TemplateRouter

Attributes

  • content: ComponentInstance
  • icon: Optional[str]
  • name: str
  • route: str
  • include_in_menu: Optional[bool]
  • on_load: Optional[Action]
from dara.core.definitions import TemplateRouterLink

class TemplateRouterLink(BaseModel)

Definition of a link for the TemplateRouter

Attributes

  • icon: Optional[str]
  • name: str
  • route: str

TemplateRouterContent

from dara.core.definitions import TemplateRouterContent

class TemplateRouterContent(BaseModel)

Definition of a content section for the TemplateRouter

Attributes

  • content: ComponentInstance
  • route: str
  • on_load: Optional[Action]
  • name: Optional[str]

Template

from dara.core.definitions import Template

class Template(BaseModel)

Definition of a template

Attributes

  • layout: ComponentInstance
  • name: str