Skip to main content

a Web Framework made by Xp-op

Project description

icon version stars contributors Fork Issues

A Python Web Framework Built With Socket

High Performance • Light Weight • Not really

stats

About

Pjono is a framework for creating web server, api, and any other thing that it can do.

The reason I used Socket is that I really like Socket and it much easier to used.

Making the server receiving and sending data is easy but parsing Http Request and creating Http Response are quite a bit tricky since I don't have people that can help me. I also try to add new feature for building User Interface and I had to use Third Party Library(bs4) for parsing html code. This project made me understand how HTTP actually work. Really glad that I can finish this.

Features

  • Components

    Building User Interface with Components.py module.

    Example:

    from Pjono import HtComponents, HTML
    
    HtComponents(f"""
    <div class="container-1">
        <h1>(2+2)/5={(2+2)/5}</h1>
        <h1>2*4-(9%2)={2*4-(9%2)}</h1>
        <h1>1 is 1={1 == 1}</h1>
        <h1>"Hello" is a string={isinstance("Hello", str)}</h1>
        <h1>{", ".join(str(i) for i in range(1,11))}</h1>
    </div>
    """).render(HTML("index.html"), id="root")
    

    You can also append object to specific element:

    from Pjono import HtComponents, Component
    
    Parent = HtComponents("<div id='root'></div>")
    
    Parent.append(lambda c: "id" in c.attr and c.attr["id"] == "root", Component("h1","Hello, World!"))
    #<div id="root">
    #   <h1>Hello, World!</h1>
    #</div>
    

    Converting string or dict into Component object:

    from Pjono import Component
    
    comp = Component.StrToComponent("<h2 class='title'>Inside the hole of hell</h2>")
    # Component("h2", "Inside the hole of hell", True, **{"class":"title"})
    
    comp = Component.DictToComponent({
        "Name": "div",
        "Data": "This is div class",
        "EndTag": True,
        "Attrs":{
            "id":"Container"
        }
    })
    # Component("div", "This is div class", True, id="Container")
    
  • Signal and Event

    With this feature, you can execute any Python function on client side but you still need JS to make it work.

    How it Work? It simple.

    scenario

    client will send a request to the server with JS and the server will get the event name and message by headers. Server will get the function that supposed to handle the request and execute it.

    from Pjono import PjonoApp, ClientEvent, HTML
    
    # Creating PjonoApp and ClientEvent object
    app = PjonoApp("Example Server")
    client = ClientEvent(app)
    
    # Add new event
    @client.addEvent("upper")
    def upper(msg):
        return msg.upper()
    
    # Register new location
    @app.register("/")
    def index(request):
        signal, event = client.getEvent(request) # process the request
        if signal and event == "upper": # if the request is an event
            return signal # msg.upper()
        return HTML("index.html") # if not then send the index.html content
    

    and the JS part:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>index</title>
        <script src="/Pjono/signal.js"></script>
    </head>
    <body>
        <div id="root">
            <input name="msg" type="text" id="inp-1"><br><br>
            <button onclick="upper()">Upper</button>
        </div>
        <script>
        const Signal = new PjSignal();
        function upper(){
            Signal.fireEvent("upper", document.getElementById("inp-1").value, function(response, status){
                var ele = document.createElement("h2");
                ele.textContent = response;
                document.getElementById("root").appendChild(ele);
            });
        }
        </script>
    </body>
    

Features that may be added

  • WebSocket

    want to make chat app like Discord?

  • Components.py Improvement

    More HtComponents features such as extend, insert, delete and more.

  • File upload support

    This one is kinda hard to do but I'll try to make it

Usage

for more information, read the documentation.

from Pjono import PjonoApp

app = PjonoApp("My Server")

@app.register("/")
def index(request):
    return "<h1>Hello, World</h1>"

app.launch()

License

Distributed under the MIT License. See LICENSE for more information.

Contributing

Contributions can help make this project much better. All contributions are greatly appreciated.

  1. Fork the project

  2. Create your Feature Branch

    git checkout -b feature/EpicFeature

  3. Commit your changes

    git commit -m 'cool feature that can...'

  4. Push to the Branch

    git push origin feature/EpicFeature

  5. Open a Pull 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

Pjono-0.0.4.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

Pjono-0.0.4-py3-none-any.whl (177.0 kB view details)

Uploaded Python 3

File details

Details for the file Pjono-0.0.4.tar.gz.

File metadata

  • Download URL: Pjono-0.0.4.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.0

File hashes

Hashes for Pjono-0.0.4.tar.gz
Algorithm Hash digest
SHA256 38dee21c270d6d06a1bcf5c900176f8c4efa8a9f8b52990b2e31fb4a24318c47
MD5 eaae9c237bef5ac58b44d68667433ec8
BLAKE2b-256 6d0cb7a801cb52324945457117893c1676cb52c3e855d2e1258a934391fc2880

See more details on using hashes here.

File details

Details for the file Pjono-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: Pjono-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 177.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.3.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.0

File hashes

Hashes for Pjono-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3b5baec03f05af952363fee424c697539bd5398a00cdf0c09a940e1d3805948c
MD5 b2bdb7fa657ce983329f7653916115cc
BLAKE2b-256 fd3bc21c83e42e255076240d0bb2c387b0328cae4b7e9f02a11ccdc230c7b9d3

See more details on using hashes here.

Supported by

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