OpenBB Workspace Backend Template
June 12, 2026 ยท View on GitHub
A comprehensive FastAPI application template for OpenBB Workspace that demonstrates various widget types and features.
Setup
- Install the required dependencies:
pip install fastapi uvicorn requests plotly
- Run the application:
uvicorn main:app --reload --host 0.0.0.0 --port 7779
The application will be available at http://localhost:7779
Architecture
This FastAPI application is designed to work as a backend for OpenBB Workspace. Here's a breakdown of its architecture:
Core Application Structure
- FastAPI backend service running on port 7779
- CORS enabled specifically for
https://pro.openbb.co - Widget registration using the
@register_widgetdecorator pattern - Modular organization of endpoints and widgets
Widget Registration Pattern
The application uses a decorator-based approach to register widgets, which combines the UI/UX configuration with the API endpoint implementation. This is achieved through the @register_widget decorator that:
- Defines the widget's appearance and behavior in the OpenBB Workspace UI
- Automatically registers the widget configuration in the
WIDGETSregistry - Links the UI configuration directly to its corresponding API endpoint
- Maintains a single source of truth for widget definitions
Available Widget Types
-
Markdown Widgets
- Basic markdown display
- Support for images (URL and local)
- Error handling
- Run button functionality
- Auto-refresh capabilities
- Stale time indicators
-
Table Widgets
- Basic table display
- Column definitions and formatting
- Render functions (color coding, hover cards)
- Chart integration
- Time series visualization
- API endpoint integration
-
Chart Widgets
- Plotly integration
- Theme support
- Toolbar configuration
- Heatmap visualization
- TradingView integration
-
Form Widgets
- Text input
- Number input
- Date picker
- Boolean toggle
- Dropdown selection
- Multi-select options
- Dependent dropdowns
-
PDF Widgets
- Base64 encoded PDF display
- URL-based PDF display
- Multi-PDF viewer
Widget Features
-
Auto-refresh
refetchInterval: Time between automatic refreshesstaleTime: Time after which data is considered stalerunButton: Manual refresh option
-
Parameter Management
- Shared parameters between widgets
- Dependent parameters
- Parameter grouping
- Default values
- Validation
To see a widget push a parameter update back to Workspace (so one widget can drive the rest of a synced group), see the iframe & HtmlViewer parameter bridge example.
-
Data Visualization
- Table formatting
- Chart integration
- Color coding
- Hover information
- Interactive elements
-
Error Handling
- HTTP exception handling
- Error messages
- Status codes
- User feedback
API Endpoints
-
Core Endpoints:
GET /: Basic API informationGET /widgets.json: Widget configurationGET /templates.json: Template configuration
-
Widget Endpoints:
- Various widget-specific endpoints for different functionalities
- Form submission endpoints
- Data fetching endpoints
- Configuration endpoints
Security & Configuration
- CORS properly configured for OpenBB Workspace domain
- FastAPI metadata includes title, description, and version
- All endpoints documented with docstrings
- Input validation and error handling
Best Practices
-
Widget Organization
- Use categories and subcategories for better organization
- Group related widgets together
- Use consistent naming conventions
-
Parameter Management
- Share parameters between related widgets
- Use dependent parameters when appropriate
- Provide clear descriptions and labels
-
Error Handling
- Implement proper error handling
- Provide meaningful error messages
- Use appropriate HTTP status codes
-
Performance
- Use appropriate refresh intervals
- Implement stale time indicators
- Optimize data fetching
-
Security
- Validate all inputs
- Handle errors gracefully
- Use proper CORS configuration
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request