An html wrapper for python

Overview

MessySoup

What is it?

MessySoup is a python wrapper for html elements. While still a ways away, the main goal is to be able to build a wesbite straight from python, both front and backend. MessySoup is similiar to other frontend frameworks and libraries in that it allows you to build reusable blocks of code instead of having to define them in each webpage.

What are the limitations?

Interactivity

Currently, you still have to write all interactivity in javascript or WASM (web assembly). However, I am keeping a sharp eye on the pyodide development. There are a number of issues open on their github page aiming to streamline some of the import methodology which look promising.

One of the reasons pyodide hasn't been integrated with this project is that the process to get custom packages loaded in the virtual document is non-intuitive for most python devs as you first need to build a python wheel before installing it with mircopip and being able to use it. That build could be added to this project, but we'll wait and see what direction the pyodide team goes in first.

Events

Due to the sheer number of events available, it doesn't make sense to add each event as an arguement for every element. For now, all events will need to be handled in JS or using the pyodide js bindings.

File Format

Once you write your elements to disk in a file, you will notice the file is not formatted properly. This is intentional. To fix in VS Code, simply right click on the file and click format document

How do I use it?

To get started, use pip install messysoup. This library is mostly funciton based, where each html tag has it's own funciton. In cases where an html tag or attribute name clashes with a built in function or reserved word, such as open and dir, an underscore is added to the end of the python equivalent. Thus, open become open_ and dir becomes dir_.

Each python tag has three main types of attibutes:

  1. The content (with the exeptoin of self closing tags such as br).
  2. Tag specific attributes, such as href for a.
  3. Global attributes (with the exception of some tags such as br).

The below example uses two common tags, a paragraph and a hyperlink. One makes use the global tags, and one makes use non-global tags.

from messysoup.messysoup import p

content = ("Lorem ipsum dolor sit amet, consectetur adipiscing elit. "
        "Aliquam sapien ligula, finibus sed ullamcorper vitae, dignissim ac turpis. " 
        "Nulla et consequat felis, vel aliquet libero. Fusce dolor nibh, sodales ut egestas eget, semper at sem. " 
        "Pellentesque sit amet massa tincidunt, consectetur purus id, molestie arcu. " 
        "Fusce in odio quis enim pulvinar condimentum. " 
        "Praesent dictum scelerisque ornare. " 
        "Morbi eget nisi ac lacus ullamcorper pharetra ut a ligula. " 
        "Aliquam porttitor commodo magna, in malesuada elit sagittis ac.")

my_paragraph = p(content=content, id='lorem-ipsum')


my_link = a("The text of the hyperlink", href="https://www.github.com")

In order to create a document out of it, add it to the MessySoup class.

from messysoup.messysoup import MessySoup, p


document = MessySoup("filename")

my_paragraph = p("Contents of the paragraph")

document.add(my_paragraph)

document.write_file()

Creating Tables

There is also a built in way to create html tables from python datastructures. Currently supported structures:

  • list of list
  • list of dictionaries
  • dictionary
  • pandas df.

To do so, simply pass your structure to create_table(). Currenlty all tables will be returned with headers and footers. If a footer is not passed in separately, the last index will be used. If headers are not passed in seperately, the following will be used:

  • Pandas df: The columns headers.
  • Dictionary: The keys.
  • List of lists: Index 0 of the parent list.

This will create a basic html table where all tags will be lacking attributes. To add attributes to the tags, use any combination of the below functions; they return a modified copy of the original table. add_all_table_attributes() will add the specified attributes to all tags, whereas all the others will add them to the specific tag.

  • add_all_table_attributes()
  • add_table_attributes()
  • add_trow_attributes()
  • add_tcell_attributes()
  • add_theader_attributes()
  • add_th_attributes()
  • add_tbody_attributes()
  • add_tfooter_attributes()

Global arguments

The majority of attributes allow global arguments. The below is a quick reference for each arguement. For tag specific items, see the MDN docs.

  • accesskey: A shortcut key to activate of focus on the element.
  • class: Specify the classname for an element.
  • contenteditable: Determines whether the content of the element is editable.
  • data_key: Will be appended to the data- tag. Used to store custom data private to the page or application.
  • data_value: The value of the data- tag.
  • dir_: Specifies the direction of the text.
  • draggable: Specifies whether or not an element is draggable.
  • hidden: Specifies whether or not an element is relevant.
  • id: Unique id for the element.
  • lang: Language of the element.
  • spellcheck: Specifies whether or not spelling and grammer should be checked.
  • style: Add inline CSS.
  • tabindex: Tabbing order of the element.
  • title: Extra info about the element.
  • translate: Whether or not the element should be translated.
Utils to quickly evaluate many 🤗 models on the GLUE tasks

Utils to quickly evaluate many 🤗 models on the GLUE tasks

Przemyslaw K. Joniak 1 Dec 22, 2021
Addon to give a keybind to automatically enable contact shadows on all lights in a scene

3-2-1 Contact(Shadow) An easy way to let you enable contact shadows on all your lights, because Blender doesn't enable it by default, and doesn't give

TDV Alinsa 3 Feb 02, 2022
A small site to list shared directories

Nebula Server Directories This site can be used to list folder and subdirectories in your server : Python It's required to have Python 3.8 or more ins

Adrien J. 1 Dec 28, 2021
Convert Photoshop curves (acv) to xmp presets for Lightroom

acv2xmp Convert Photoshop curves (acv) to Lightroom preset (xmp) acv2xmp.py Basic command prompt that relies on standard library only and can be used

5 Feb 06, 2022
Windows Task Manager with special features, written in Python.

Killer That damn Chrome ⬇ Download here · 👋 Join our discord Tired of trying to kill processes with the default Windows Task Manager? Selecting one b

Nathan Araújo 49 Jan 03, 2023
WhyNotWin11 - Detection Script to help identify why your PC isn't Windows 11 Release Ready

WhyNotWin11 - Detection Script to help identify why your PC isn't Windows 11 Release Ready

Robert C. Maehl 5.9k Dec 31, 2022
pydock - Docker-based environment manager for Python

pydock - Docker-based environment manager for Python ⚠️ pydock is still in beta mode, and very unstable. It is not recommended for anything serious. p

Alejandro Piad 16 Sep 18, 2021
A modern python module including many useful features that make discord bot programming extremely easy.

discord-super-utils Documentation Secondary Documentation A modern python module including many useful features that make discord bot programming extr

106 Dec 19, 2022
Pyhexdmp - Python hex dump module

Pyhexdmp - Python hex dump module

25 Oct 23, 2022
This python code will get requests from SET (The Stock Exchange of Thailand) a previously-close stock price and return it in Thai Baht currency using beautiful soup 4 HTML scrapper.

This python code will get requests from SET (The Stock Exchange of Thailand) a previously-close stock price and return it in Thai Baht currency using beautiful soup 4 HTML scrapper.

Andre 1 Oct 24, 2022
A tool to nowcast quarterly data with monthly indicators: US consumption example

MIDAS_Nowcaster A tool to nowcast quarterly data with monthly indicators: US consumption example Pulls data directly from FRED from a list of codes -

Gene Kindberg-Hanlon 3 Oct 06, 2022
Goddard A collection of small, simple strategies for Freqtrade

Goddard A collection of small, simple strategies for Freqtrade. Simply add the strategy you choose in your strategies folder and run. ⚠️ General Crypt

Shane Jones 118 Dec 14, 2022
Why write code when you can import it directly from GitHub Copilot?

Copilot Importer Why write code when you can import it directly from GitHub Copilot? What is Copilot Importer? The copilot python module will dynamica

Mythic 41 Jan 04, 2023
This repository contains a lot of short scripting programs implemented both in Python (Flask) and TypeScript (NodeJS).

fast-scripts This repository contains a lot of short scripting programs implemented both in Python (Flask) and TypeScript (NodeJS). In python These wi

Nahum Maurice 3 Dec 10, 2022
Demo Python project using Conda and Poetry

Conda Poetry This is a demonstration of how Conda and Poetry can be used in a Python project for dev dependency management and production deployment.

Ryan Allen 2 Apr 26, 2022
Personal Chat Assistance

Python-Programming Personal Chat Assistance {% import "bootstrap/wtf.html" as wtf %} titleEVT/title script src="https://code.jquery.com/jquery-3.

PRASH_SMVIT 2 Nov 14, 2021
Completed task 1 and task 2 at LetsGrowMore as a data science intern.

LetsGrowMore-Internship Completed task 1 and task 2 at LetsGrowMore as a data science intern. Task 1- Task 2- Creating a Decision Tree classifier and

Sanjyot Panure 1 Jan 16, 2022
Easy, clean, reliable Python 2/3 compatibility

Overview: Easy, clean, reliable Python 2/3 compatibility python-future is the missing compatibility layer between Python 2 and Python 3. It allows you

Python Charmers 1.2k Jan 08, 2023
A multi purpose password managing and generating tool called Kyper.

Kyper A multi purpose password managing and generating tool called Kyper. Setup The setup for Kyper is fairly simple only involving the command python

Jan Dorian Poczekaj 1 Feb 05, 2022
A refresher for PowerBI Desktop documents

PowerBI_Refresher-NPP Informació Per executar el programa s'ha de tenir instalat el python versio 3 o mes. Requeriments a requirements.txt. El fitxer

Nil Pujol 1 May 02, 2022