It's a robust webserver (http/ws) for hosting htag apps on the web
MIT License
This module exposes htag's runners for the web. It's the official runners to expose htag apps on the web, to handle multiple clients/session in the right way.
It's the real runner to expose htag apps in a real production environment, and provide all features, while maintaining tag instances like classical/desktop htag runners.
All htag apps are runned in its own process, and an user can only have an instance of an htag app. (so process are recreated when query params changes) Process live as long as the server live
Features
Like a classical starlette'app :
from htagweb import Runner
from yourcode import YourApp # <-- your htag class
app=Runner( YourApp, ... )
if __name__=="__main__":
app.run()
You can use the following parameters :
The host to bind to. (default is "0.0.0.0")
The port to bind to. (default is 8000)
non-sense in http_only mode.
this parameter is available on app.handle(request, obj, ... parano=True|False ...)
too, to override defaults !
this parameter is available on app.handle(request, obj, ... http_only=True|False ...)
too, to override defaults !
It's the time (in seconds) for an interaction (or an initialization) for answering. If the timeout happens : the process/instance is killed.
By default, it's 60
seconds (1 minute).
It's the time (in seconds) of inactivities, after that : the process is detroyed.
By default, it's 0
(process lives as long as the server lives).
IMPORTANT : the "tag.update" feature doesn't reset the inactivity timeout !
Example to add a static endpoint :
from starlette.responses import PlainTextResponse
async def serve(req):
return PlainTextResponse("body {}")
app=Runner( App, debug=False, ssl=True )
app.add_route("/my.css", serve)
Example to add another htag app on another endpoint :
async def serve(req):
return await req.app.handle(req, App2 )
app=Runner( App, debug=False, ssl=True )
app.add_route("/my_other_app", serve)
A "hello world" could be :
from htag import Tag
class App(Tag.div):
def init(self):
self<= "hello world"
from htagweb import Runner
Runner( App ).run()
or, with gunicorn (in a server.py
file, as following):
from htag import Tag
class App(Tag.div):
def init(self):
self<= "hello world"
from htagweb import Runner
app=Runner( App )
and run server :
gunicorn -w 4 -k uvicorn.workers.UvicornH11Worker -b localhost:8000 --preload server:app
See a more advanced example in examples folder
python3 examples/main.py