Python
This guide will show how to use hop in a Python project.
We start by creating a hop.toml file.
toml
[compile]
target = "python"
output_path = "frontend.py"
[dev]
server_commands = ["flask run"]We continue by writing a simple .hop file.
hop
<Index {name: String}>
Hello {name}!
</Index>Now we compile the hop code to Python.
bash
hop compileNow the generated Python code is available in the folder ./frontend so we can import it in the backend.
Now, let's define a simple backend using Flask.
python
from flask import Flask
import frontend
app = Flask(__name__)
@app.route('/')
def index():
return frontend.page_index(
frontend.PageIndexParams(
name="Tobi"
)
)
if __name__ == '__main__':
app.run(port=8080)Now hop is integrated into the backend, and we can run hop dev to start the server and get hot-reloading.