frontend
The `frontend` library (version 0.0.3) allows developers to build complex and beautiful user interfaces using Python. It abstracts away traditional web technologies, enabling Python developers to create interactive frontends with a Pythonic syntax. As an early-stage project, it is actively developing its core features and API, with a relatively low release cadence reflecting its current development phase.
Common errors
-
ModuleNotFoundError: No module named 'frontend'
cause The `frontend` library has not been installed in the current Python environment, or the environment where the code is being run differs from where it was installed.fixEnsure `frontend` is installed using `pip install frontend`. Verify you are running your script with the Python interpreter associated with that installation. -
TypeError: render() missing 1 required positional argument: 'self'
cause The `render` method (or another instance method) within your `View` class was defined without `self` as its first argument.fixAll instance methods in Python classes, including `render` and event handlers, must accept `self` as their first parameter. Correct the method signature to `def render(self):`. -
NameError: name 'self' is not defined
cause You are attempting to use the `self` keyword outside of an instance method within a `View` class, or in a static method that doesn't implicitly receive `self`.fixEnsure that any code referencing `self` (to access instance attributes or methods) is located within an instance method (e.g., `__init__`, `render`, or custom event handlers) of your `View` class.
Warnings
- gotcha The `frontend` library is in a very early development stage (version 0.0.x). The API surface and core components are subject to rapid and potentially breaking changes between minor versions (e.g., 0.0.3 to 0.0.4).
- gotcha To trigger UI re-renders after state changes in a `View`, you must explicitly call `self.update()` within your event handlers or state-modifying methods. Without this call, changes to instance attributes will not reflect in the browser.
- gotcha The `app.run()` method provided in quickstarts is suitable for basic local development and testing. For production deployments or more robust development setups, it's recommended to use a standard ASGI server like `uvicorn`.
Install
-
pip install frontend
Imports
- Frontend
from frontend.main import Frontend
- View
from frontend.views import View
Quickstart
from frontend.main import Frontend
from frontend.views import View
app = Frontend()
@app.route("/")
class MyView(View):
def render(self):
return self.Div(self.H1("Hello, Frontend!"))
if __name__ == "__main__":
# In a real application, you might run this with uvicorn directly:
# uvicorn your_module:app --reload
# For this quickstart, app.run() provides a basic server.
app.run()