Skip to main content

Simple package for fast writing local sites and desktop apps, with html, css and javascript

Project description

About Monolit

This technology allows for rapid development of monolithic applications with a server-side component. The core idea is that the server and client reside on the same device, eliminating the need for a physical server. This lowers the barrier to entry in web development. Consequently, any indie developer can create a full-fledged application with a server-side component without any initial investment or hosting rental costs.

How to install Monolit

The library can be installed using Python’s built-in package manager, pip. Simply type "pip install monolit_local_app" in your terminal, and all necessary packages will be automatically downloaded to your computer.

How to use Monolit

To run a Monolit application, you need to import Monolit (for example, import monolit_local_app as ml). Then, create a class in the main.py file. Specify the full path to the "www" folder (which must contain the "index.html" file, otherwise an error will occur). Within this class, you also need to create a method named "process_request" that accepts the request argument: ml.Request. When an HTTP request is received at "http://127.0.0.1:5000/process," this function will be called and return a response.

main.py:

import monolit_local_app as ml

class Main(ml.App):
    def __init__(self):
        self.www = f"{ml.dirname(__file__)}\\www"

    def process_request(self, request: ml.Request):
        ml.info(request)

        return ml.jsonify(
            {
                "msg": "All is ok!"
            }
        )

if __name__ == "__main__":
    ml.host(Main)

However, this code does not constitute the application itself. This script merely hosts the application at the address "http://127.0.0.1:5000/www/index.html", but it does not launch it. To launch it, you must manually open your browser and enter "http://127.0.0.1:5000/www/index.html" in the address bar. Since this would be highly inconvenient for the user, it’s better to call main.py from the command line using another Python script.

app.py:

import os
import webbrowser
webbrowser.open("http:\\127.0.0.1:5000\www\index.html")
os.system("python main.py")

If you suddenly find that a website is attempting to request unexpected files and this is causing errors, use the main class method, process_path. This function accepts the path to each requested file and should return the path to the file you want to return to the unexpected path. However, if everything is working fine, it's best not to use it, as you risk breaking the data exchange mechanism.

main.py:

    ...
        self.www = f"{ml.dirname(__file__)}\\www"

    def process_path(self, path: str):
        if path == "favicon.ico":
            return ml.sum_paths(self.www, "img/favicon.ico")
        if path == "devtools.json":
            return ml.sum_paths(self.www, "chache/history/data.json")

        # Or a more laconic version

        try:
            return {
                "favicon.ico": ml.sum_paths(self.www, "img/favicon.ico"),
                "devtools.json": ml.sum_paths(self.www, "chache/history/data.json")
            }[path]
        except KeyError:
            return None

    def process_request(self, request: ml.Request):
        ml.info(request)
    ...

Project details


Download files

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

Source Distribution

monolit_local_app-1.0.5.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file monolit_local_app-1.0.5.tar.gz.

File metadata

  • Download URL: monolit_local_app-1.0.5.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for monolit_local_app-1.0.5.tar.gz
Algorithm Hash digest
SHA256 bef23f8647c6adcc4566ddc39679781b30d9f4b40b4e2bd7e157e0d58f628d63
MD5 6094697cc9399b8b8ddcb015d69076f7
BLAKE2b-256 48092ccf1d93af5ae20a1595aa1ad9d91f8429b9d4e4a9b2b73bd1c91a9250a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page