Defining Tasks
Use @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.
Create your first task
To create a task, use the @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
Davia and FastAPI Integration
Davia is built on top of FastAPI. When you create your app with app = Davia()
, you are actually creating a FastAPI application. This means you can use all FastAPI features and add your own endpoints alongside Davia tasks.
Example: Adding a FastAPI Endpoint
Best Practices
Follow these essential guidelines to ensure your Davia tasks are robust, maintainable, and user-friendly:
- Use clear prefixes for function names
- Start task names with
action_
for operations that take inputs, anddisplay_
for those that simply show information. This makes your codebase easier to navigate and your UI more intuitive.
- Start task names with
- Always define input and output types with type annotations
- Type annotations help Davia generate the correct UI and improve code reliability.
- Document your functions with concise, purpose-focused docstrings
- A short docstring helps users understand what each task does, and can be displayed in the UI.
- Avoid dynamic arguments like *args or **kwargs
- Use explicit parameters and types so Davia can generate the right input fields and validation.
- Keep each function focused on a single responsibility
- Design tasks to do one thing well. This makes them easier to test, reuse, and maintain.
- Restart your server after adding tasks
- When you add or modify endpoints, restart your server to ensure Davia detects all changes and updates the editor interface accordingly.
If you want to extend your app with custom endpoints or advanced features, see the FastAPI documentation.