Skip to main content

Web Framework with Pythonic Javascript Syntax

Project description

Jyserver Web Framework with Pythonic Javascript Syntax

Jyserver is a framework for simplifying the creation of font ends for apps and kiosks by providing real-time access to the browser's DOM and Javascript from the server using Python syntax. It also provides access to the Python code from the browser's Javascript.

The difference between this framework and others (such as Django, Flask, etc.) is that jyserver uses Python dynamic syntax evaluation so that you can write Python code that will dynamically be converted to JS and executed on the browser. On the browser end, it uses JS's dynamic Proxy object to rewrite JS code for execution by the server. All of this is done transparently without any additional libraries or code. See example below.

This module uses threads and queues to ensure responsiveness.

Browser           Server
Javascript  --->  execute as python server code
JS & DOM    <---  execute statements
            <---  query and change values

Example:

from jserver import Client, Server
class App(Client):
    def __init__(self):
        # For simplicity, this is the web page we are rendering. 
        # The module will add the relevant JS code to 
        # make it all work. You can also use an html file.
        self.html = """
            <p id="time">TIME</p>
            <button id="reset" 
                onclick="server.reset()">Reset</button>
        """

    # Called by onclick
    def reset(self):
        # reset counter so elapsed time is 0
        self.start0 = time.time()
        # executed on client
        self.js.dom.time.innerHTML = "{:.1f}".format(0)

    # If there is a "main" function, it gets executed. Program
    # ends when the function ends. If there is no main, then
    # server runs forever.
    def main(self):
        # start counter so elapsed time is 0
        self.start0 = time.time()
        while True:
            # get current elapsed time, rounded to 0.1 seconds
            t = "{:.1f}".format(time.time() - self.start0)
            # update the DOM on the client
            self.js.dom.time.innerHTML = t
            time.sleep(0.1)

httpd = Server(App)
print("serving at port", httpd.port)
httpd.start()

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

jyserver-0.0.1.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

jyserver-0.0.1-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file jyserver-0.0.1.tar.gz.

File metadata

  • Download URL: jyserver-0.0.1.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for jyserver-0.0.1.tar.gz
Algorithm Hash digest
SHA256 10198bf38bcba703065d8d6385cdbf289b1d7131d634dcef1f8a7eb8ee39b072
MD5 d392b226f04a9e2b5f47dc81f9f87b43
BLAKE2b-256 f281b874f57b0b987d72b5469bc41cc1d7cb4c5de7a1ed9c268141e02a8c1aaf

See more details on using hashes here.

File details

Details for the file jyserver-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: jyserver-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for jyserver-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 be278b421e37f1ed7b7382ad508b9faf365defca9d20bcdb2bf013a8ffc67c5e
MD5 a884769f98fb0feb90f2484ce1fb0bf2
BLAKE2b-256 00812e45150adc3cbe4f75a9285e012b28c030ab134ffd976a652ef9535b0697

See more details on using hashes here.

Supported by

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