Skip to main content

A lightweight webserver implementation [inspired by flask]

Project description

ksalf

PyPI

A lightweight experimental HTTP handler inspired by flask.
! This is just a experimental (fun) project, please don't use it in production !

Implemtation

Ksalf is a lightweight handler for the python (base) http server .
It provides new feature like URL parsing and HTML responses, to the python in-build http server.
Ksalf currently only supports GET requests.
The project was inspired by the flask python project.

Installtion

pip install ksalf

Example

from http.server import HTTPServer
from ksalf import HTTPHandler

class Handler(HTTPHandler):

    @HTTPHandler.route("/health")
    def GET(self):
        self.respond(b'healthy')

if __name__ == "__main__":
    PORT = 8080
    httpd = HTTPServer(('0.0.0.0', PORT), Handler)
    print("Server running on http://localhost:" + str(PORT))
    httpd.serve_forever()

This example would serve a simple web app on your localhost:8080.
You can register a route with @HTTPHandler.route("/<your_route>").
GET requests always get processed by the def GET(self): implementation.
curl

curl localhost:8080/health

Response

healthy

Future Development

  • Implement tests
  • Support other request methods than just GET
  • Advanced URL parsing
  • Enhance HTML Responses

Project details


Download files

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

Files for ksalf, version 0.0.2
Filename, size File type Python version Upload date Hashes
Filename, size ksalf-0.0.2-py3-none-any.whl (4.1 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size ksalf-0.0.2.tar.gz (3.0 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page