Defining Tasks
Use @davia_app.task to expose Python functions to the frontend.
In Davia, a task is a Python function that becomes available from the frontend.
You define the logic in Python — and Davia takes care of generating the UI: input fields, buttons, and result areas.
This is the main way to let users interact with your backend: they can trigger actions, pass data, and get responses, without you writing a single line of frontend code.
1. Create your first task
To create a task, use the @davia_app.task
decorator. Davia will generate a UI based on the function’s inputs and output type.
When you run this file, Davia will open the editor at:
🔗 https://dev.davia.ai/dashboard?entrypoint=http://127.0.0.1:2025
You’ll see:
- A single-line input for
text
- A button to run the task
- A display of the result in uppercase
2. Use input/output types
Davia uses function signatures to build the UI automatically.
For example:
This creates:
- Two numeric inputs
- A button to run the calculation
- The discounted price as the output
Supported input types include:
str
,int
,float``,
bool```- Lists and dictionaries
- Optional values using typing (e.g.
Optional[str]
)
3. Add a useful docstring
The docstring appears in the UI to explain what each task does.
It helps your users understand the purpose and behavior of the function.
✅ Use clear, action-oriented descriptions:
Returns the discounted price based on the input percentage.
🚫 Avoid vague or technical notes:
Test helper function for internal calculations.
4. Example: checkbox + output
Davia can generate:
- A checkbox labeled
show_details
- A response message area that updates based on the input
Best practices
- ✅ Always define input and output types
- ✅ Use descriptive names for functions and parameters
- ✅ Write helpful docstrings
- ❌ Don’t use unsupported dynamic arguments (like
*args
) - ❌ Avoid relying on global state or side effects