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.
You might also like...
Xbps-install wrapper written in Python that doesn't care about case sensitiveness and package versions
Xbps-install wrapper written in Python that doesn't care about case sensitiveness and package versions

xbi Xbps-install wrapper written in Python that doesn't care about case sensitiveness and package versions. Description This Python script can be easi

🤖🧭Creates google-like navigation menu using python-telegram-bot wrapper

python telegram bot menu pagination Makes a google style pagination line for a list of items. In other words it builds a menu for navigation if you ha

An async API wrapper for Dress To Impress written in Python.

dti.py An async API wrapper for Dress To Impress written in Python. Some notes: For the time being, there are no front-facing docs for this beyond doc

A Python wrapper API for operating and working with the Neo4j Graph Data Science (GDS) library

gdsclient NOTE: This is a work in progress and many GDS features are known to be missing or not working properly. This repo hosts the sources for gdsc

A simple wrapper for joy library
A simple wrapper for joy library

Joy CodeGround A simple wrapper for joy library to render joy sketches in browser using vs code, (or in other words, for those who are allergic to Jup

Installer, package manager, build wrapper and version manager for Piccolo

Piccl Installer, package manager, build wrapper and version manager for Piccolo

Wrapper around anjlab's Android In-app Billing Version 3 to be used in Kivy apps

IABwrapper Wrapper around anjlab's Android In-app Billing Version 3 to be used in Kivy apps Install pip install iabwrapper Important ( Add these into

Custom SLURM wrapper scripts to make finding job histories and system resource usage more easily accessible

SLURM Wrappers Executables job-history A simple wrapper for grabbing data for completed and running jobs. nodes-busy Developed for the HPC systems at

A wrapper script to make working with ADB (Android Debug Bridge) easier

Python-ADB-Wrapper A wrapper script to make working with ADB (Android Debug Bridge) easier This project was just a simple test to see if I could wrap

Owner
null
apysc is the Python frontend library to create html and js file, that has ActionScript 3 (as3)-like interface.

apysc apysc is the Python frontend library to create HTML and js files, that has ActionScript 3 (as3)-like interface. Notes: Currently developing and

simonritchie 17 Dec 14, 2022
Grimoire is a Python library for creating interactive fiction as hyperlinked html.

Grimoire Grimoire is a Python library for creating interactive fiction as hyperlinked html. Installation pip install grimoire-if Usage Check out the

Scott Russell 5 Oct 11, 2022
Visualize Data From Stray Scanner https://keke.dev/blog/2021/03/10/Stray-Scanner.html

StrayVisualizer A set of scripts to work with data collected using Stray Scanner. Usage Installing Dependencies Install dependencies with pip -r requi

Kenneth Blomqvist 45 Dec 30, 2022
Fetch data from an excel file and create HTML file

excel-to-html Problem Statement! - Fetch data from excel file and create html file Excel.xlsx file contain the information.in multiple rows that is ne

Vivek Kashyap 1 Oct 25, 2021
We'll be using HTML, CSS and JavaScript for the frontend

We'll be using HTML, CSS and JavaScript for the frontend. Nothing to install in specific. Open your text-editor and start coding a beautiful front-end.

Mugada sai tilak 1 Dec 15, 2021
Convert text with ANSI color codes to HTML or to LaTeX.

Convert text with ANSI color codes to HTML or to LaTeX.

PyContribs 326 Dec 28, 2022
Bootstraparse is a personal project started with a specific goal in mind: creating static html pages for direct display from a markdown-like file

Bootstraparse is a personal project started with a specific goal in mind: creating static html pages for direct display from a markdown-like file

null 1 Jun 15, 2022
A Python wrapper around Bacting

pybacting Python wrapper around bacting. Usage Based on the example from the bacting page, you can do: from pybacting import cdk print(cdk.fromSMILES

Charles Tapley Hoyt 5 Jan 3, 2022
Python wrapper to different clients to determine how a particular term is used.

Python wrapper to different clients to determine how a particular term is used.

Chris Mungall 3 Oct 24, 2022
A Python wrapper for Matrix Synapse admin API

Synapse-admin-api-python A Python wrapper for Matrix Synapse admin API. Versioning This library now supports up to Synapse 1.45.0, any Admin API intro

Knugi 9 Sep 28, 2022