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.
Reproduction repository for the MDX 2021 Hybrid Demucs model

Submission This is the submission for MDX 2021 Track A, for Track B go to the track_b branch. Submission Summary Submission ID: 151378 Submitter: defo

Alexandre Défossez 62 Dec 18, 2022
my own python useful functions

PythonToolKit Motivation This Repo should help save time for data scientists' daily work regarding the Time Series regression task by providing functi

Kai 2 Oct 01, 2022
In this project we will be using OpenCV to virtually drag a rectangle and drop it at a different location. It will be further used for Virtual Mouse.

Virtual Drag & Drog using OpenCV In this project we will be using OpenCV to virtually drag a rectangle and drop it at a different location. It will be

Hassan Shahzad 5 Sep 27, 2021
FCurve-Cleaner: Tries to clean your dense mocap graphs like an animator would

Tries to clean your dense mocap graphs like an animator would! So it will produce a usable artist friendly result while maintaining the original graph.

wiSHFul97 5 Aug 17, 2022
OnTime is a small python that you set a time and on that time, app will send you notification and also play an alarm.

OnTime Always be OnTime! What is OnTime? OnTime is a small python that you set a time and on that time, app will send you notification and also play a

AmirHossein Mohammadi 11 Jan 16, 2022
A similarity measurer on two programming assignments on Online Judge.

A similarity measurer on two programming assignments on Online Judge. Algorithm implementation details are at here. Install Recommend OS: Ubuntu 20.04

StardustDL 6 May 21, 2022
Projeto de análise de dados com SQL

Project-Analizyng-International-Debt-Statistics- Projeto de análise de dados com SQL - Plataforma Data Camp Descrição do Projeto : Não é que nós human

Lorrayne Silva 1 Feb 01, 2022
A simply dashboard to view commodities position data based on CFTC reports

commodities-dashboard A simply dashboard to view commodities position data based on CFTC reports This is a python project using Dash and plotly to con

71 Dec 19, 2022
API development made easy: a smart Python 3 API framework

appkernel - API development made easy What is Appkernel? A super-easy to use API framework, enabling API creation from zero to production within minut

156 Sep 28, 2022
Calculatrix is a project where I'll create plenty of calculators in a lot of differents languages

Calculatrix What is Calculatrix ? Calculatrix is a project where I'll create plenty of calculators in a lot of differents languages. I know this sound

1 Jun 14, 2022
Python library for Minitel communication through serial port

Python library for Minitel communication through serial port

Noël 3 Aug 14, 2022
Simple yet flexible natural sorting in Python.

natsort Simple yet flexible natural sorting in Python. Source Code: https://github.com/SethMMorton/natsort Downloads: https://pypi.org/project/natsort

Seth Morton 712 Dec 23, 2022
Blender addon that simplifies access to useful operators and adds missing functionality

Quick Menu is a Blender addon that simplifies common tasks Compatible with Blender 3.x.x Install through Edit - Preferences - Addons - Install... -

passivestar 94 Dec 27, 2022
Think DSP: Digital Signal Processing in Python, by Allen B. Downey.

ThinkDSP LaTeX source and Python code for Think DSP: Digital Signal Processing in Python, by Allen B. Downey. The premise of this book (and the other

Allen Downey 3.2k Jan 08, 2023
Fastest python library for making asynchronous group requests.

FGrequests: Fastest Asynchronous Group Requests Installation Install using pip: pip install fgrequests Documentation Pretty easy to use. import fgrequ

Farid Chowdhury 14 Nov 22, 2022
Tools for dos (denial-of-service) website / web server

DoS Attack Tools Tools for dos (denial-of-service) website / web server di buat olah NurvySec How to install on debian / ubuntu $ apt update $ apt ins

nurvy 1 Feb 10, 2022
Lightweight and Modern kernel for VK Bots

This is the kernel for creating VK Bots written in Python 3.9

Yrvijo 4 Nov 21, 2021
Amitkumar Mishra 2 Jan 14, 2022
pybicyclewheel calulates the required spoke length for bicycle wheels

pybicyclewheel pybicyclewheel calulates the required spoke length for bicycle wheels. (under construcion) - homepage further readings wikipedia bicyc

karl 0 Aug 24, 2022
TikTok Auto Claimer Made By Aim low!#9999 Leaked By bazooka#0001

Zues Auto Claimer Leaked By bazooka#0001 put proxies in prox.txt put ssid in sid.txt put all users you want to target in user.txt for the login just t

1 Jan 14, 2022