Skip to main content

It's a robust webserver (http/ws) for hosting htag apps on the web (a process by user)

Project description

htagweb

Test

Package version

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.

There are 3 runners:

  • AppServer : the real one ;-)
  • SimpleServer : for tests purposes
  • HtagServer : (use SimpleServer) to browse/expose python/htag files in an UI.

AppServer

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 (TODO: a TIMEOUT will be back soon)

Features

  • based on starlette
  • multiple ways to handle sessions (file, mem, etc ...)
  • compatible with uvloop !!!
  • compatible with multiple gunicorn/uvicorn/webworkers !!!
  • compatible with tag.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 websocket

Instanciate

Like a classical starlette'app :

from htagweb import AppServer
from yourcode import YourApp # <-- your htag class

app=AppServer( YourApp, ... )
if __name__=="__main__":
    app.run()

You can use the following parameters :

debug (bool)

  • When False: (default) no debugging facilities
  • When True: use starlette debugger.

ssl (bool)

  • When False: (default) use "ws://" to connect the websocket
  • When True: use "wss://" to connect the websocket

non-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 on app.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 on app.handle(request, obj, ... http_only=True|False ...) too, to override defaults !

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 reboot

SimpleServer

It'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 uses htagweb.sessions.FileDict as session manager.

HtagServer

It's a special runner, which is mainly used by the python3 -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 / futur

  • make it works with gunicorn again !!!!!!!!!!!!!!!!!!!!!!!!!
  • better unittests !!!!!!!!!!!!!!!!
  • better logging !!!!!!!!!!!!!!!!
  • process lives : timeout !
  • parano mode : use public/private keys ?

Examples

A "hello world" could be :

from htag import Tag

class App(Tag.div):
    def init(self):
        self+= "hello world"

from htagweb import AppServer
AppServer( 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 AppServer
app=AppServer( 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

Standalone module can act as server

The module can act as "development server", providing a way to quickly run any htag class in a browser. And let you browse current *.py files in a browser.

$ python3 -m htagweb

htagweb will look for an "index:App" (a file index.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 -m htagweb main:App

if you want to point the "/" (home path) to a file main.py (wich contains a htag.Tag subclass 'App').

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

htagweb-0.14.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

htagweb-0.14.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file htagweb-0.14.0.tar.gz.

File metadata

  • Download URL: htagweb-0.14.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.2 Linux/6.2.0-1012-azure

File hashes

Hashes for htagweb-0.14.0.tar.gz
Algorithm Hash digest
SHA256 c7e97ea6e8950059306fb47f5785d2f0ed0cc7edf369740829284aa414e126a5
MD5 6250fcc4e1d34d7668701679a93c79bc
BLAKE2b-256 f1671e0cc248710e0d2634fa6e7a94784df13532d10b4d3280088b6195bbd132

See more details on using hashes here.

File details

Details for the file htagweb-0.14.0-py3-none-any.whl.

File metadata

  • Download URL: htagweb-0.14.0-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.2 Linux/6.2.0-1012-azure

File hashes

Hashes for htagweb-0.14.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bac6f65adf320b7becc6e24222a5a5bdc31360da6555ff4e40d68b02fb483048
MD5 f1c347eee2340d4f4e51eff7f2aba954
BLAKE2b-256 b0aaf1098a627236ac25e3f59dd39e7fef69380d245b161cf6e1dff6122ef271

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page