It's a robust webserver (http/ws) for hosting htag apps on the web (a process by user)
Project description
htagweb
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.
Runner
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
- based on starlette
- use session
- compatible with uvloop !!!
- compatible with multiple gunicorn/uvicorn/webworkers !!!
- compatible with tag.update()
- works on gnu/linux, ios
or windows(from py3.8 to py3.11)! (not py3.7 anymore ;-() - 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 Runner
from yourcode import YourApp # <-- your htag class
app=Runner( YourApp, ... )
if __name__=="__main__":
app.run()
You can use the following parameters :
host (str)
The host to bind to. (default is "0.0.0.0")
port (int)
The port to bind to. (default is 8000)
debug (bool)
- When False: (default) no debugging facilities
- When True: use starlette debugger.
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 !
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's 60 seconds (1 minute).
timeout_inactivity (int)
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 !
to add an endpoint (add_route)
Example to add a static endpoint :
from starlette.responses import PlainTextResponse
async def serve(req):
return PlainTextResponse("body {}")
app=Runner( App, debug=False )
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 )
app.add_route("/my_other_app", serve)
Roadmap / futur
- more unittests !!!!!!!!!!!!!!!!
- better logging !!!!!!!!!!!!!!!!
- 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 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file htagweb-0.60.3.tar.gz.
File metadata
- Download URL: htagweb-0.60.3.tar.gz
- Upload date:
- Size: 145.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ae1153caa9b26b536dcc735baf87b7ae7432569d880ae5c39ff1cd8bb86e512
|
|
| MD5 |
b24671739f3cd29d310b0cfafa1e1a07
|
|
| BLAKE2b-256 |
2451d31bb81badcd8f3537e2a5589c30017bf847e61cc5d904d45d74ffcaff7b
|
Provenance
The following attestation bundles were made for htagweb-0.60.3.tar.gz:
Publisher:
on_tag_do_release_and_deploy_pypi.yml on manatlan/htagweb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
htagweb-0.60.3.tar.gz -
Subject digest:
7ae1153caa9b26b536dcc735baf87b7ae7432569d880ae5c39ff1cd8bb86e512 - Sigstore transparency entry: 813116327
- Sigstore integration time:
-
Permalink:
manatlan/htagweb@786b4e2388ed4b162471d8273383917af9126476 -
Branch / Tag:
refs/tags/v0.60.3 - Owner: https://github.com/manatlan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on_tag_do_release_and_deploy_pypi.yml@786b4e2388ed4b162471d8273383917af9126476 -
Trigger Event:
push
-
Statement type:
File details
Details for the file htagweb-0.60.3-py3-none-any.whl.
File metadata
- Download URL: htagweb-0.60.3-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
02995e35b1c0cb111c874e92a4dc553d3c59e397a85845c1ba05c1ce792d0242
|
|
| MD5 |
d31aa554d928d414363b1fbe59532bba
|
|
| BLAKE2b-256 |
6f468575c9928ddd8bafc24309d31d54bc8a04632e4cf070dfe42518f3bcb846
|
Provenance
The following attestation bundles were made for htagweb-0.60.3-py3-none-any.whl:
Publisher:
on_tag_do_release_and_deploy_pypi.yml on manatlan/htagweb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
htagweb-0.60.3-py3-none-any.whl -
Subject digest:
02995e35b1c0cb111c874e92a4dc553d3c59e397a85845c1ba05c1ce792d0242 - Sigstore transparency entry: 813116328
- Sigstore integration time:
-
Permalink:
manatlan/htagweb@786b4e2388ed4b162471d8273383917af9126476 -
Branch / Tag:
refs/tags/v0.60.3 - Owner: https://github.com/manatlan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
on_tag_do_release_and_deploy_pypi.yml@786b4e2388ed4b162471d8273383917af9126476 -
Trigger Event:
push
-
Statement type: