Skip to main content

kali

Simple, reliable, single-threaded HTTP service in Python. Aimed at serving web application to localhost as alternative to desktop application development.

Quick Start!

There are tutorial demonstrations in the examples folder at the Git repository. Mainly, you should read that source code (start with the intro) because it will show you how this all fits together. You can run the demos from the Windows command line by, for example, demo intro. (If you're on Linux/Mac/Unix, then feel free to contribute a suitable shell script.)

Why This, Then?

I wanted to expose a SINGLE-THREADED WEB APPLICATION over HTTP to LOCALHOST ONLY. Web application, because it's a comfortable style of working with data entry and navigation. Single threaded, to support working well with SQLite, which doesn't play well with multi-threading, and Windows, which is not particularly suited to a forking-model server.

Web browsers lately all expect to open multiple connections and might not send the first request on the first connection. The Python Standard Library offers class "HttpServer", but as currently coded, it only works properly when you're using a forking or threading mix-in. In sequential-service mode, the standard library deadlocks (at least until the end user refreshes the browser a few times).

The essential problem is solved by setting a brief time-out on the first packet from the client. If that time-out expires, the connection is closed and the server accepts the next caller, which will generally have the request data from the browser. The server also only speaks HTTP/1.0 on purpose: it guarantees all requests are served in a timely manner. There is zero packet latency on localhost, so there's not a real performance drain here.

Features! Benefits!

So long as I'm re-inventing the wheel, I might as well do it with the end in sight. Therefore:

  1. The server is a higher-order function called serve_http: you pass in a handler function. In fact, any callable-object will do. The handler call must accept a Request object and return a Response object (or just a content body). There are some convenience methods for creating redirections, serving plain text, etc.

  2. This means routing requests to different response methods is a separate problem. A simple solution is provided in the box, called class Router. It reads the path component of the Request URI to decide which of many sub-functions to call, and which bits of the path correspond to parameters, etc. Several ways are provided to register functionality, ranging from absolute flexibility to complete convenience.

  3. The framework takes (some) pains to avoid excessive copying, drawing inspiration from the iolist facility in the Erlang ecosystem. Rather than building up a big string, supply a list of them, or a funny-shaped nest of them, etc. The rules are somewhat loose.

  4. There's a simple HTML templating facility included: it will do the job without being accidentally quadratic (much) by participating in the above-described iolist game. You can have templates inline or saved in separate files: allowance is made for both styles of working. As feature sets go, it covers the most important bits (substitution, HTML escapes, loops, template extension) but leaves the really creative stuff for your Python code to work out.

  5. There's also a forms-handling library supplied. It offers components that make it extra easy to handle the most common kinds of work flows.

  6. It's really annoying forgetting to commit-or-rollback a transaction in a handler. Changes may appear fine locally (until they vanish) but nobody else sees anything except a locked database. Checking for this a simple matter by wrapping the root handler (application router) and taking corrective measures. (Roll back the transaction and return an error response maybe.)

Metadata

Release files for kali 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kali 0.0.8
File Size Uploaded Provenance Actions
kali-0.0.8.tar.gz 23.3 kB Without provenance Details for kali-0.0.8.tar.gz

Release files / kali-0.0.8.tar.gz

Download URL kali-0.0.8.tar.gz
Size 23.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2c873723c6c8b2419ca1516aa2155b5dcc0958b841fd6c9c4d9403d072ae95e3
BLAKE2b-256 checksum
How to use checksums
db19417311731693725f2747cf50328d7e6107a2d78eb7c096e5b37d899f356f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.9.0

Security for kali 0.0.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page