Web HTML maker in Python - a light web application framework
Project description
WhakerPy - a Web HTML maker in Python
Overview
Whakerpy is a simple library useful to create dynamic HTML content; it's a light web application framework.
Create and manipulate HTML from the power of Python:
- Easy to learn. Consistent, simple syntax.
- Flexible and easy usage.
- Create HTML pages dynamically
- Can save as static files, and/or
- Run locally with its httpd server and response "bakery" system.
Author
Copyright (C) 2023 - Brigitte Bigi - develop@sppas.org Laboratoire Parole et Langage, Aix-en-Provence, France
License
This is the implementation of the WhakerPy
library, under the terms of
the GNU General Public License version 3.
Install WhakerPy
From its repo:
Download the repository and unpack it, or clone with git
.
WhakerPy package includes the following folders and files:
- "whakerpy": the source code package
- "doc": the documentation of whakerpy in HTML
- "sample":
- "etc": etcetera!
From its wheel package:
Download the wheel file (WhakerPy-xxx.whl) and install it in your python environment with:
> python -m pip install dist/<WhakerPy-xxx.whl>
From pypi.org:
> python -m pip install WhakerPy
Quick Start
Open a Python interpreter and type or paste the following:
>>> from whakerpy.htmlmaker import *
>>> htree = HTMLTree("index")
>>> node = HTMLNode(htree.body_main.identifier, None, "h1", value="this is a title")
>>> htree.body_main.append_child(node)
Render and print the HTML
>>> print(htree.serialize())
<!DOCTYPE html>
<html>
<head> </head>
<body>
<main>
<h1>
this is a title
</h1>
</main>
</body>
</html>
Add some styling and others
>>> htree.head.title("WhakerPy")
>>> htree.head.meta({"charset": "utf-8"})
>>> htree.head.link(rel="icon", href="/static/favicon.ico")
>>> htree.head.link(rel="stylesheet", href="nice.css", link_type="text/css")
Add page copyright in the footer
>>> copyreg = HTMLNode(htree.body_footer.identifier, "copyright", "p",
>>> attributes={"class": "copyright", "role": "none"},
>>> value="Copyright © 2023 My Self")
>>> htree.body_footer.append_child(copyreg)
Let's view the result in your favorite web browser
>>> import webbrowser
>>> file_whakerpy = htree.serialize_to_file('file.html')
>>> webbrowser.open_new_tab(file_whakerpy)
Create a web application frontend with dynamic HTML content
For a quick start, see the file sample.py
. It shows a very simple
solution to create a server that can handle dynamic content. This content
is created from a custom BaseResponseRecipe()
object, available in the
file samples/response.py
. The response is the interface between a
local back-end python application and the web front-end.
For a more complex example of an already in-used web frontend, see: https://sourceforge.net/p/sppas/code/ci/master/tree/sppas/ui/swapp/app_setup/setupmaker.py.
Projects using WhakerPy
WhakerPy
was initially developed within SPPAS https://sppas.org; it was
extracted from its original software by its author to lead its own life as
standalone package. The "setup" of SPPAS is entirely based on whakerpy API,
and it's website too.
Other projects:
- pages of the website https://auto-cuedspeech.org are created by whakerpy.
- contact the author if your project is using whakerpy
The developer's corner
Create a wheel
WhakerPy is no system dependent. Information to build its wheel are stored
into the file pyproject.toml
.
The universal wheel is created with: python -m build
Make the doc
The API documentation is available in the doc
folder. Click the file index.html
to browse throw the documented classes of WhakerPy.
To re-generate the doc, install the required external program:
python -m pip install -r doc/requirements.txt
Then, launch the doc generator: cd doc; python makedoc.py
Analyze WhakerPy code
Unittests coverage can be analyzed with pytest and coverage. Install them
with the command: python -m pip install -r tests/requirements.txt
Then, perform the following steps:
coverage run -m pytest
coverage report
to see a summary report into the terminal, or use this command to get the result in XML format:coverage xml; mv coverage.xml tests
The whakerpy package can be analyzed with SonarQube by following these steps:
- Download and install Docker
- Download and install SonarQube:
docker pull sonarqube:latest
- Start the SonarQube server by running:
docker run --stop-timeout 3600 -d --name sonarqube -p 9000:9000 sonarqube:latest
Log in to http://localhost:9000. Both login and password are "admin".
Add the python plugin and restart server. - Click "Add project" with name "WhakerPy", and provide it a token
- Copy/Paste the token into the file whakerpy/sonar-project.properties
- Download sonar-scanner client:
brew install sonar-scanner
(or something else, it obviously depends on your OS) - Launch:
sonar-scanner
- See results in the opened URL, and don't forget it's an automatic code analyzer, not an intelligent one.
Contribute
If you plan to contribute to the code, please send an e-mail to the author.
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
Built Distribution
File details
Details for the file WhakerPy-0.2.tar.gz
.
File metadata
- Download URL: WhakerPy-0.2.tar.gz
- Upload date:
- Size: 74.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12905d27a8f5d65ae36548aaa2d198acda0f774956e6577e20a8a8cb09b63040 |
|
MD5 | 2b17f3df70b3d3b4dc7b31bcfe44e68a |
|
BLAKE2b-256 | b699f97462252ac2024616f1f645aa58b2ca74fc6f0a9845fbaabbde642454a7 |
File details
Details for the file WhakerPy-0.2-py3-none-any.whl
.
File metadata
- Download URL: WhakerPy-0.2-py3-none-any.whl
- Upload date:
- Size: 68.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f896311a48821860b6568d3e26a8dec36c1b7f1ea23960249ef5e000e00b33f9 |
|
MD5 | 18ce86a522c1c0edabf31be7a6b47af5 |
|
BLAKE2b-256 | 1109fc0ca93404b6f9cfc479a75f0d73462d2191b265821653d906e5616dee0e |