Skip to main content

Twig is a frontend and backend web framework utilizing the python socket module to serve http requests.

Project description

Twig 0.5.0

Twig is a backend web framework for python utilizing the socket module to handle http requests and serve responses.

To install use the following command:

py -m pip install TwigWeb

Changelog


0.5.0

  • Fixed dynamic router.

  • Implemented URL query parameters.

  • Implemented Headers class to separate parts of incoming request for the developer.


0.4.0

  • Added dynamic route parameters.

  • Improved route handling with Route class


0.3.0

  • Added static paths and folders functions.

  • Added element class.

  • Added component classes.


0.2.0

  • Added set_all_routes function

  • Fixed inconsistent request handling

  • Improved documentation


Example

This example does not show all of the functionality of Twig. There is documentation currently being worked on.

from src.TwigWeb.backend.routehandler.route import Route, RouteParameter, RouteParamType
from src.TwigWeb.backend import Server
from src.TwigWeb.backend.response import Response

app = Server("", debug=True, open_root=False)

@app.route("")
def index(headers):
    #this is the index of the app
    return Response("test", ContentType.html)

@app.route("form")
def form(headers):
    #this form redirects to page/2
    return Response("""<form action="/page/2">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>""")

@app.route("page/[num]")
def index(headers, num):
    # Headers.URL is a dictionary containing all url query parameters/variables.
    # num a dynamic route.
    return Response(f"num: {num} and {headers.URL}", ContentType.html)

@app.route("page")
def index(headers):
    return Response(f"page", ContentType.html)

app.run()

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

TwigWeb-0.5.1.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

TwigWeb-0.5.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file TwigWeb-0.5.1.tar.gz.

File metadata

  • Download URL: TwigWeb-0.5.1.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.9

File hashes

Hashes for TwigWeb-0.5.1.tar.gz
Algorithm Hash digest
SHA256 fc123275edc97bff95c5a33371f138f11960f09afcc50b4d01d9fd3d6a465d6b
MD5 2439c1ff72e94a49d60138821a6c8fae
BLAKE2b-256 6ad211366e281833461c47a012b8521bc4896420141faa4deacca85da4d89e78

See more details on using hashes here.

File details

Details for the file TwigWeb-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: TwigWeb-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.64.1 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.5 CPython/3.6.9

File hashes

Hashes for TwigWeb-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7a3ae59e775f259472219dbd6fe0f3e7ac6ae139fee26fb21d94a9cf49812d86
MD5 b3ce163c409b4e54a67266ea5e1ec3e8
BLAKE2b-256 2af8a29a35f78d1799b7c26563d5cf868d332249c941efde13e62e73c8475b21

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