Skip to main content



from dara.core.configuration import Configuration

class Configuration(GenericModel)

Definition of the main framework configuration


  • auth_config: BaseAuthConfig
  • registry_lookup: CustomRegistryLookup
  • actions:
  • endpoint_configurations:
  • components:
  • context_components:
  • enable_devtools: bool
  • live_reload: bool
  • pages:
  • routes:
  • scheduled_jobs:
  • startup_functions:
  • static_folders:
  • static_files_dir: str
  • package_tag_processors:
  • template_extra_js: str
  • task_module:
  • template: str
  • template_renderers:
  • theme:
  • title: str
  • ws_handlers:
  • encoders:
  • middlewares:



def get_package_map() -> Dict[str, str]

Get a map of python package names to js package names, based on currently registered components, actions etc.


from dara.core.configuration import ConfigurationBuilder

class ConfigurationBuilder()

The ConfigurationBuilder class lets you build a Configuration object up piece by piece using helper methods that aid setup and point users in the right direction.


  • auth_config: BaseAuthConfig
  • registry_lookup: CustomRegistryLookup
  • _actions:
  • _components:
  • _errors:
  • enable_devtools: bool
  • live_reload: bool
  • _pages:
  • _template_renderers:
  • _endpoint_configurations:
  • _static_folders:
  • _package_tags_processors:
  • _template_extra_js: str
  • _custom_ws_handlers:
  • _custom_encoders:
  • _middlewares:
  • routes:
  • static_files_dir: str
  • scheduled_jobs:
  • startup_functions:
  • context_components:
  • task_module:
  • template: str
  • theme: BaseTheme
  • title: str



def add_action(action: Type[ActionImpl], local: bool = False)

Register an Action with the application.

For example the below would explicitly import the UpdateVariable action from dara.core.


Note that in most cases explicitly registering a action is not necessary in most cases for non-local actionts. Actions are auto-discovered based on imports within your application.


  • action: ActionImpl-subclass definition
  • local: whether the action is a local one. For local actions js_module is not required, as their location is defined via dara.config.json


def add_endpoint(endpoint: ApiRoute)

Register an API endpoint in the application


def add_context_component(component: ComponentInstance)

Add a ContextComponent to the application.

Context components are rendered recursively in order around the application. E.g.


# Results in

This can be used by packages outside of core to provide global functionality to components on the page and hook into other application contexts, e.g. the router.


  • component: component instance


def add_component(component: Type[ComponentInstance], local: bool = False)

Register a Component with the application.

For example the below would import the Menu component from dara.core.


Note that in most cases explicitly registering a component is not necessary in most cases for non-local components. Components are auto-discovered based on imports within your application.


  • component: ComponentInstance-subclass definition
  • local: whether the component is a local one. For local components js_module is not required, as their location is defined via dara.config.json


def add_configuration(config: EndpointConfiguration)

Register an EndpointConfiguration instance with the application.


def add_static_folder(path: str)

Register a static folder, its contents can be then addressed with /static/{asset} URLs.

Its contents will be moved into the local 'static' folder to be served when:

  • running the app locally
  • running the build script


def add_ws_handler(kind: str, handler: Callable[[str, Any], Any])

Register a custom websocket handler, which will be called when a message of a given kind is received.


# Received message
"type": "custom",
"message": {
"kind": "my_custom_kind",
"data": "some arbitrary data"

# Handler
config.add_ws_handler(kind='my_custom_kind', handler=my_custom_handler)

def my_custom_handler(channel: str, data: Any):
print(f'Received message on channel {channel} with data {data}')
return 'some response'

# Message sent back
"type": "custom",
"message": {
"kind": "my_custom_kind",
"data": "some response"


def add_encoder(typ: Type[EncoderType], serialize: Callable[[EncoderType],
deserialize: Callable[[Any], EncoderType])

Register a custom encoder, which serialize and deserialize the type


  • typ: The type of object
  • serialize: The handler to serialize the object to basic python type
  • deserialize: The handler to deserialize the object Example: import numpy config.add_encoder(typ=np.array, serialize=lambda x: x.tolist(), deserialize=lambda y: np.array(y))


def add_package_tags_processor(processor: Callable[[Dict[str, List[str]]],
Dict[str, List[str]]])

Append a package tag processor. This is a function that takes a dictionary of package names to lists of script/link tags included when running in the UMD mode.

All processors are called in order, and the output of each processor is passed to the next one.


def add_page(name: str,
content: Union[ComponentInstanceType,
Type[CallableClassComponent], str],
icon: Optional[str] = None,
route: Optional[str] = None,
include_in_menu: Optional[bool] = True,
reset_vars_on_load: Optional[List[AnyVariable]] = [],
on_load: Optional[Action] = None)

Add a new page to the layout of the platform. Switching between pages relies on the template implementing a

router for switching between the pages. The default template will do this automatically, but refer to the template documentation for more details on this.


  • name: the name of the page
  • content: the content for the page
  • icon: an optional icon for the page, see dara_core.css.get_icon for more detail
  • route: an optional url for the page, if not provided it's generated based on the page name
  • include_in_menu: an optional flag for not including the page in the main menu
  • on_load: optional action to execute upon visiting the page


def add_template_renderer(name: str,
template_renderer: Callable[..., Template]) -> str

Add a new template renderer that can be selected by name as part of the configuration. By default calling this

function will update the template name to match automatically


  • name: the template name
  • template_renderer: the ComponentInstance to use for the template


def add_registry_lookup(registry_lookup: CustomRegistryLookup)

Register custom external registry lookup handlers, which will be called when a uid its not in the server registry


from dara.core import ConfigurationBuilder
config = ConfigurationBuilder()

def get_derived_variable(uid)-> DerivedVariableRegistryEntry:
# return derived variable

def get_action(uid)-> Callable:
# return action

'DerivedVariable': get_derived_variable,
'Action Handler': get_action,

#### add\_middleware

def add_middleware(middleware: Union[type, Callable], **options: Any)

Add a middleware to the application. The middleware can be a class or a callable.


def set_theme(main_theme: Optional[Union[ThemeDef, Literal['light'],
Literal['dark']]] = None,
base_theme: Optional[Union[Literal['light'],
Literal['dark']]] = None)

Sets the color theme of the app. Takes ThemeDef models for the app, and reverts

to the default themes if they are not supplied.


  • main_theme: ThemeDef defining colors for the app, alternatively can be either 'light' or 'dark' to use default Dara colors


def on_startup(startup_function: Callable)

Adds a function to be run upon startup of a Dara app


  • startup_function: The function to be run