Package: htagweb
htagwebThis 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.There are 3 runners:AppServer: the real one ;-)SimpleServer : for tests purposesHtagServer : (use SimpleServer) to browse/expose python/htag files in an UI.AppServerIt'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 (TODO: a TIMEOUT will be back soon)Featuresbased onstarletteuse sessions (multiple ways to handle sessions (file, mem, etc ...))compatible withuvloop!!!compatible with multiple gunicorn/uvicorn/webworkers !!!compatible withtag.update()works on gnu/linux, ios or windows (from py3.7 to py3.11)!real starlette session available (in tag.state, and starlette request.session)compatible with oauth2 authent (authlib)'parano mode' (can aes encrypt all communications between client & server ... to avoid mitm'proxies on ws/http interactions)auto reconnect websocketInstanciateLike a classical starlette'app :fromhtagwebimportAppServerfromyourcodeimportYourApp# <-- your htag classapp=AppServer(YourApp,...)if__name__=="__main__":app.run()You can use the following parameters :debug (bool)When False: (default) no debugging facilitiesWhen True: use starlette debugger.ssl (bool)When False: (default) use "ws://" to connect the websocketWhen True: use "wss://" to connect the websocketnon-sense in http_only mode.parano (bool)When False: (default) interactions between front/ui and back are in clear text (json), readable by a MITM.When True: interactions will be encrypted (less readable by a MITM, TODO: will try to use public/private keys in future)this parameter is available onapp.handle(request, obj, ... parano=True|False ...)too, to override defaults !http_only (bool)When False: (default) it will use websocket interactions (between front/ui and back), with auto-reconnect feature.When True: it will use http interactions (between front/ui and back). But "tag.update" feature will not be available.this parameter is available onapp.handle(request, obj, ... http_only=True|False ...)too, to override defaults !timeout_interaction (int)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's60seconds (1 minute).timeout_inactivity (int)It's the time (in seconds) of inactivities, after that : the process is detroyed.
By default, it's0(process lives as long as the server lives).IMPORTANT : the "tag.update" feature doesn't reset the inactivity timeout !session_factory (htagweb.sessions)You can provide a Session Factory to handle the session in different modes.htagweb.sessions.MemDict (default) : sessions are stored in memory (renewed on reboot)htagweb.sessions.FileDict : sessions are stored in filesystem (renewed on reboot)htagweb.sessions.FilePersistentDict : make sessions persistent after rebootSimpleServerIt's a special runner for tests purposes. It doesn't provide all features (parano mode, ssl, session factory...).
Its main goal is to provide a simple runner during dev process, befause when you hit "F5" :
it will destroy/recreate the tag instances.SimpleServer uses only websocket interactions (tag instances exist only during websocket connexions)And it useshtagweb.sessions.FileDictas session manager.HtagServerIt's a special runner, which is mainly used by thepython3 -m htagweb, to expose
current python/htag files in a browser. Its main goal is to test quickly the files
whose are in your folder, using an UI in your browser.It uses the SimpleServer, so it does'nt provide all features (parano mode, ssl, session factory ...)Roadmap / futurmake it works with gunicorn again !!!!!!!!!!!!!!!!!!!!!!!!!better unittests !!!!!!!!!!!!!!!!better logging !!!!!!!!!!!!!!!!process lives : timeout !parano mode : use public/private keys ?ExamplesA "hello world" could be :fromhtagimportTagclassApp(Tag.div):definit(self):self+="hello world"fromhtagwebimportAppServerAppServer(App).run()or, with gunicorn (in aserver.pyfile, as following):fromhtagimportTagclassApp(Tag.div):definit(self):self+="hello world"fromhtagwebimportAppServerapp=AppServer(App)and run server :gunicorn-w4-kuvicorn.workers.UvicornH11Worker-blocalhost:8000--preloadserver:appSee a more advanced example inexamples folderpython3examples/main.pyStandalone module can act as serverThe module can act as "development server", providing a way to quickly run any htag class in a browser. And let you browse current*.pyfiles in a browser.$python3-mhtagwebhtagweb will look for an "index:App" (a fileindex.py(wich contains a htag.Tag subclass 'App').), and if it can't found it : expose its own htag app to let user browse pythons files in the browser (/!\)or$python3-mhtagwebmain:Appif you want to point the "/" (home path) to a filemain.py(wich contains a htag.Tag subclass 'App').