A simple-to-use http and https server, simillar to flask, in python.
✅ To-do
HTTP and HTTPS server class
Request class
Document class
Python code execution in html
MIME type in Document class
Default headers per server
Per host handler
❓ How to use
fromhttpython.serversimportHTTP_ServerfromhttpythonimportRequestMethod# Define the port and hosthost, port="127.0.0.1", 80# Instanciate the server objectserver=HTTP_Server(host, port)
#For HTTPS servers, use HTTPS_Server(host, port, certificate_path, private_key_path)# Create an handler for requests@server.method(RequestMethod.GET, route="*", host="*") # Using the route and host parameters as '*' will use this handler as a fallback for the GET method.defGET_Handler(request):
# do stuffreturnRequest.response(
500, # Status code"Not Implemented", # Message
{"Server": "httpy/2.0", "Connection": "closed"}, # Headersb""# Body
)
@server.method(RequestMethod.GET, route="/api/", host="*")defAPI_Handler(request):
# do stuffreturnRequest.response(
500, # Status code"Not Implemented", # Message
{"Server": "httpy/2.0", "Connection": "closed"}, # Headersb'{"foo": "bar"}'# Body
)
# Run the serverserver.run()
The Tidelift Subscription provides access to a continuously curated stream of human-researched and maintainer-verified data on open source packages and their licenses, releases, vulnerabilities, and development practices.