This is a light Framework for Python HTTP server.
The purpose of this Framework is to ease POC development.
It supports both HTTP 1.1 and WebSocket
(RFC 6455) protocols.
HTTP actions and WebSocket handlers are hot reload
ed without killing running processes.
This Framework needs Python 3+.
To run the GUI, tkinter is needed.
chmod +x ./setup.py
./setup.py build
This command generates a pyweb.pyz
.
Generate a SSL pair of keys:
./setup.py ssl
creates run/certificate.crt and run/privateKey.key
Declare pyz as default executable for *.pyz files.
Start the serveur:
./setup.py run -h
or
./pyz ./pyweb.pyz -h
or
pthon3 ./pyweb.pyz -h
You should get:
usage: pyweb.pyz [-h] [-nogui] [-port [PORT]] [-add ADD [ADD ...]]
[-m M [M ...]] [-testing] [-testfile [TESTFILE]] [-secured]
[-certfile [CERTFILE]] [-keyfile [KEYFILE]]
Optional app description
optional arguments:
-h, --help show this help message and exit
-nogui without gui
-port [PORT] port
-add ADD [ADD ...] directory
-m M [M ...] module for actions
-testing with tests
-testfile [TESTFILE] javascript test file
-secured secured
-certfile [CERTFILE] certificate path
-keyfile [KEYFILE] private key file
Replace -h
by your configuration parameters.
Default tests URL :
Two files recreated after each launch:
sys.stdin
is redirected to run/pyweb.errsys.stdout
is redirected to pyweb.log
Edit file lab.py as needed. This python script is dynamicly reloaded.
@core.http("GET", "/root/{id}/{action}.do")
def action_1 (headers, parameters, id: "path", action: "path"):
return answer(200, hs={}, body="Hello world")
@core.http("GET|POST", "/test/unique/{id}")
def action_test_unique(
headers,
params,
id: "path",
ptexte: "text [a-zA-Z]{10}",
htexte: "header",
pnum: "number .{10}"=1234567890,
pfile: "file"=None):
"""
Fonction de test
@param headers http headers
@param params all parameters dictionnary
@param id mandatotory path element
@param ptexte mandatory text parameter with exactly 10 letters
@param htexte parameter from header
@param pnum parameter with 10 carachters with default value 1234567890
@param pfile optionnal file
"""
return answer(200, body="<html>Hello %s</html>" % ptexte, mime="text/html")
Your Pyweb server actions:
- ./lab.py
- ./print.py
Tests directory:
- ./www/test.js (generated by staarting the server with testing option)
- ./www/testlib.*
Documentation:
- ./doc/*
Archive ./pyweb.pyz sources files:
- ./src/*.py
From work directory:
- ./work/certificate.crt (generated by
./setup.py ssl
) - ./work/privateKey.key (generated by
./setup.py ssl
) - ./work/pyweb.err
- ./work/pyweb.log
Others:
- ./README.md
- ./LICENSE
- ./setup.py