Skip to main content

base_definitions

DaraBaseModel

from dara.core.base_definitions import DaraBaseModel

class DaraBaseModel(BaseModel)

Custom BaseModel which handles TemplateMarkers. If TemplateMarkers are present, validation is skipped.

CacheType

from dara.core.base_definitions import CacheType

class CacheType(str, Enum)

Cache types enum

Methods

get_member

@classmethod
def get_member(cls, value: str)

Get a member of the enum by value

BaseCachePolicy

from dara.core.base_definitions import BaseCachePolicy

class BaseCachePolicy(BaseModel, abc.ABC)

Base class for cache policies.

Attributes

  • policy: str
  • cache_type: CacheType

LruCachePolicy

from dara.core.base_definitions import LruCachePolicy

class LruCachePolicy(BaseCachePolicy)

Least-recently-used cache policy.

Evicts the least recently used item when adding a new item to the cache if the number of items exceeds the max_size.

Arguments:

  • max_size: maximum number of items to keep in the cache - globally or per user/session, depending on cache_type set in the policy

Attributes

  • policy: str
  • max_size: int

MostRecentCachePolicy

from dara.core.base_definitions import MostRecentCachePolicy

class MostRecentCachePolicy(LruCachePolicy)

Most recent cache policy. Only keeps the most recent item in the cache.

Attributes

  • policy: str
  • max_size: int

KeepAllCachePolicy

from dara.core.base_definitions import KeepAllCachePolicy

class KeepAllCachePolicy(BaseCachePolicy)

Keep all items in the cache, regardless of the number of items.

Should be used with caution as it can lead to memory leaks.

Attributes

  • policy: str

TTLCachePolicy

from dara.core.base_definitions import TTLCachePolicy

class TTLCachePolicy(BaseCachePolicy)

Time-to-live cache policy.

Evicts items from the cache after the specified time-to-live.

Arguments:

  • ttl: time-to-live in seconds

Attributes

  • policy: str
  • ttl: int

Cache

from dara.core.base_definitions import Cache

class Cache()

Convenience class aggregating all available cache policies and types

Policy

from dara.core.base_definitions import Policy

class Policy()

Available cache policies

Methods

from_arg

@classmethod
def from_arg(cls, arg: CacheArgType) -> BaseCachePolicy

Construct a cache policy from a cache arg. Defaults to LRU if a type is provided.

from_dict

@classmethod
def from_dict(cls, arg: dict) -> Optional[BaseCachePolicy]

Construct a cache policy from its serialized dict represetnation

CachedRegistryEntry

from dara.core.base_definitions import CachedRegistryEntry

class CachedRegistryEntry(BaseModel)

Represents a registry item with associated cache entries which can be controlled via the cache policy.

Attributes

  • cache: Optional[BaseCachePolicy]
  • uid: str

Methods

to_store_key

def to_store_key()

Returns a unique store key for this entry.

BaseTask

from dara.core.base_definitions import BaseTask

class BaseTask(abc.ABC)

Generic BaseTask that can be used for type checking tasks

Attributes

  • cache_key: Optional[str]
  • reg_entry: Optional[CachedRegistryEntry]
  • notify_channels: List[str]
  • task_id: str

PendingTask

from dara.core.base_definitions import PendingTask

class PendingTask(BaseTask)

Represents a running pending task. Is associated to an underlying task definition.

Attributes

  • cache_key: None
  • reg_entry: None

Methods

run

async def run(
send_stream: Optional[MemoryObjectSendStream[TaskMessage]] = None)

Wait for the task to complete

resolve

def resolve(value: Any)

Resolve the pending state and send values to the waiting code

Arguments:

  • value: the value to resolve as the result

fail

def fail(exc: BaseException)

Resolve the pending state with an error and send it to the waiting code

Arguments:

  • exc: exception to resolve as the result

cancel

async def cancel()

Stop the task

add_subscriber

def add_subscriber()

Add 1 to the subscriber count

remove_subscriber

def remove_subscriber()

Remove 1 from the subscriber count

PendingValue

from dara.core.base_definitions import PendingValue

class PendingValue()

An internal class that's used to represent a pending value. Holds a future object that can be awaited by multiple consumers.

Methods

wait

async def wait()

Wait for the underlying event to be set

resolve

def resolve(value: Any)

Resolve the pending state and send values to the waiting code

Arguments:

  • value: the value to resolve as the result

error

def error(exc: Exception)

Resolve the pending state with an error and send it to the waiting code

Arguments:

  • exc: exception to resolve as the result

AnnotatedAction

from dara.core.base_definitions import AnnotatedAction

class AnnotatedAction(BaseModel)

Represents a single call to an @action-annotated action.

from dara.core import action

@action
def my_action(ctx: action.Ctx, ...):
...

result = my_action(...)
type(result) == AnnotatedAction

Attributes

  • uid: str
  • definition_uid: str
  • dynamic_kwargs: Mapping[str, Any]
  • loading: Variable

uid

Instance uid of the action. Used to find static kwargs for the instance

definition_uid

Uid of the action definition

dynamic_kwargs

Dynamic kwargs of the action; uid -> variable instance

loading

Loading Variable instance

ActionImpl

from dara.core.base_definitions import ActionImpl

class ActionImpl(DaraBaseModel)

Base class for action implementations

Arguments:

  • js_module: JS module including the implementation of the action. Required for non-local actions which have a JS implementation.

Attributes

  • js_module:
  • py_name:

Methods

execute

async def execute(ctx: ActionCtx) -> Any

Execute the action.

Default implementation sends the args to the frontend which can be called by subclasses.

Arguments:

  • context: ActionContext instance

dict

def dict(*args, **kwargs)

This structure is expected by the frontend, must match the JS implementation

ActionInstance

@deprecated alias for backwards compatibility

Action

Definition of an action that can be executed by the frontend. Supports:

  • AnnotatedAction: an @action annotated function
  • ActionImpl: an instance of a subclass of ActionImpl
  • a list of either of the above

@deprecated when passing a list only ActionImpl will be supported in dara 2.0

ActionDef

from dara.core.base_definitions import ActionDef

class ActionDef(BaseModel)

Action definition required to register actions in the app.

Links the name of the action with its JS implementation.

Arguments:

  • name: name of the action, must match the Python definition and JS implementation
  • py_module: name of the PY module with action definition, used for versioning
  • js_module: JS module where the action implementation lives. Not required for local actions as they are located via dara.config.json

Attributes

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

ActionResolverDef

from dara.core.base_definitions import ActionResolverDef

class ActionResolverDef(BaseModel)

Attributes

  • uid: str
  • resolver: Optional[Callable]
  • execute_action: Callable[Awaitable[Any]]

uid

Unique id of the action definition

resolver

Resolver function for the action

execute_action

Handler to execute the action, default dara.core.internal.execute_action.execute_action

UploadResolverDef

from dara.core.base_definitions import UploadResolverDef

class UploadResolverDef(BaseModel)

Attributes

  • resolver: Optional[Callable]
  • upload: Callable

resolver

Optional custom resolver function for the upload

upload

Upload handling function, default dara.core.interactivity.any_data_variable.upload

ComponentType

from dara.core.base_definitions import ComponentType

class ComponentType(Enum)

Component types enum

TemplateMarker

from dara.core.base_definitions import TemplateMarker

class TemplateMarker(BaseModel)

Template marker used to mark fields that should be replaced with a data field on the client before being rendered. See dara_core.definitions.template for details

Attributes

  • field_name: str