Developing web-based user interfaces often requires significant knowledge of HTML, CSS, and JavaScript. For data scientists and backend developers who primarily work with Python, this creates a steep learning curve and slows down the prototyping process. While existing libraries like Streamlit exist, they often offer limited customization or produce heavy overhead for simple applications. There is a need for a lightweight, modular UI library that allows developers to create premium-looking interfaces using pure Python syntax while maintaining high performance and modern aesthetics.
FlexUI is a lightweight Python-based user interface library designed to bridge the gap between backend logic and frontend presentation. It utilizes a Waiter-Chef architecture where a core engine (the waiter) tracks UI components and a rendering system (the chef) converts them into optimized HTML and CSS. The goal of FlexUI is to provide a seamless development experience where UI elements are treated as Python objects, and the browser-based interface is generated dynamically and served through a lightweight Flask backend.
The primary objective of this project is to develop a modular and extensible UI framework that:
- Simplifies the creation of web-based dashboards and portals using only Python.
- Provides modern, pre-styled components (Buttons, Inputs, Cards, etc.) that meet current design standards.
- Implements a hot-reloading mechanism to enhance developer productivity during the design phase.
- Maintains a small footprint with minimal dependencies.
- Enables easy local installation and global access for various projects.
The scope of this project includes the development of the core orchestration engine, a recursive rendering system for nested components, and a suite of standard UI elements. It also encompasses a documentation site built using the framework itself and a command-line interface for application management. The project is focused on local development and prototyping environments.
- The current version does not support real-time state management (e.g., updating a text field instantly without a refresh).
- It relies on a flat rendering cycle which may require manual refreshes for certain complex logic updates.
- Advanced layouts like multi-column grids or flex-box alignment are currently in the experimental phase.
- There is no built-in support for client-side JavaScript execution through Python methods yet.
FlexUI significantly reduces the time required to build and deploy simple internal tools and dashboards. By abstracting the complexities of frontend development, it empowers Python developers to take full ownership of the user experience. The library is particularly significant for students and researchers who need to present their data or tools in a professional manner without investing time in learning web technology stacks.
- The system must allow the definition of UI components (Text, Buttons, Inputs, Cards) in a standard Python script.
- The system must automatically register all created components with a centralized engine.
- The renderer must generate semantic HTML5 and modern CSS3 for every registered component.
- The system must start a local web server to display the generated interface.
- The system must detect changes in the source code and restart the server automatically (Hot-Reloading).
- The system must support nested layouts where components like Cards can serve as containers for other elements.
- Performance: The rendering of components should be near-instantaneous.
- Usability: The API should be intuitive and require minimal lines of code to produce a working interface.
- Maintainability: The code should be modular, allowing for easy addition of new components.
- Compatibility: The library must work across all standard Python 3.8+ environments and modern web browsers.
- Reliability: The server should handle multiple requests locally without crashing.
- Principal Language: Python 3.x
- Backend Framework: Flask (for serving the UI)
- Styling: Pure CSS3 (Embedded/Internal)
- Markup: HTML5
- Tooling: Setuptools (for packaging), Click (for CLI implementation), Webbrowser/Threading (for automation).
- User Interface: The final output must be rendered in a standard web browser at a local address (typically http://localhost:5000).
- Engine Logic: The engine must follow the Singleton pattern to ensure global state consistency.
- Rendering Logic: The renderer must be able to process nested component structures recursively.
- Installation Support: The project must include a setup script compatible with PIP to allow for editable installation.
- Error Handling: The server should provide clear console logs for any Python-side errors during execution.
- Unit Testing: Individual components like Button and Text were tested to ensure they correctly register their properties (e.g., variants and colors) with the engine.
- Integration Testing: The connection between the Engine and the HTML Renderer was tested to ensure JSON-to-HTML translation is accurate.
- Functional Testing: Multiple example apps (basic_app.py, form_app.py, card_app.py) were executed to verify if the components appear correctly in the browser.
- Hot-Reloading Testing: The system was tested by modifying script values during runtime to ensure the server restarts and reflects changes upon browser refresh.
- UI/UX Testing: The documentation site was tested across different browser window sizes to ensure responsiveness and readability.