Wecome to the documentation of Sierra - Sierra is a Python library to write HTML and CSS in pure Python using the DOM API in a simple yet elegant manner. Take advantage of Python's powerful functionalities with ease. Loops, variables, functions, libraries - you name it, you have it. You can now develop your web application purely in Python, taking full advantage of its powerful functionalities with simple and elegant syntax. You can use this along with another templating engine, or use it standalone - even without a web framework, if you like. If you have any specific requests, open a discussion/issue on our GitHub page . Any contributions can also be made there.
Please read our LICENSE before moving forward.
Contents:
Let's get started
can be done as an easier way of installing. You can also clone the repository and work inside of src/sierra if you like.
To import the library, simply use:
Once imported, the first line of syntax is mandatory, and all development to be displayed on the webpage must come after this:
This creates an index.html
and a style.css
in the working directory.
You can add a header with head()
. Start the body of the web application with openBody()
. Add CSS with **kwargs
.
You may notice in styling with **kwargs
, that the styling argument font-family
and background-color
is entered in as font_family
and background-color
.
That is, underscores are used in **kwargs
in the place of hyphens.
This is because Python returns a SyntaxError
when hyphens are used in the key of **kwargs
.
Hence, use underscores in **kwargs
for hyphens in styling arguments.
Fonts can be added with addFont()
which takes only one argument, which is the link to the font.
Using CSS
There are three ways you can add CSS to tags. The first one is with .css()
, which takes in **kwargs
, and can only be used within the context managers of already existing syntax, like Tag()
and div()
.
Underscores are used in the key or **kwargs
instead of hyphens in styling attributes.
The second way is to use writeCSS()
. It takes in a dictionary of CSS attributes, and adds them to the tag mentioned as the first argument in writeCSS().
.
The third way is to use writeCSS_raw()
. Any text you specify in writeCSS_raw()
gets written into the CSS file.
Working with div, section and p tags
Division and section tags can be opened the same way as Tag()
, except the syntax is div(**kwargs)
and section(**kwargs)
respectively.
It can take in tag attributes through the **kwargs
method.
Prefix conflicting arguments with a double underscore and use a single underscore for hyphens.
While adding CSS for this is similar to the mechanism in Tag()
, it differs in the fact that the .css() here prioritizes tag attributes given.
The first priority being for __class
, the second being for id
, and if both don't exist, CSS is just added to the tag raw.
That is div
or section
. Entering in both __class
and id
results in CSS being added to the class, and enters it to id in the absence of __class
.
If you don't want to add CSS this way using .css()
, use writeCSS()
instead, where you can add CSS to any tag/attribute, simply use '#name_of_id'
or '.name_of_class'
as the first argument.
<p>
tags can be added with p()
.
The text to be added goes into the text
attribute, and tag attributes, as usual, can be added to attr
.
However, p()
is not a context manager-based approach, as shown above under the section tag, and closes upon argument exit.
Use writeCSS()
or writeCSS_raw()
to add css.
Adding images
Images can be added with image()
as context manager based approach, .show()
which takes no arguments is used to display the image and .css()
can be used to add CSS (no priorities, just adds to img
), or one of the other three methods to add it to a class or an id.
Working with tables (Pandas supported)
Adding a table could never have been easier with a context manager approach on Table()
, which takes no arguments and has objects create_table()
and get_table()
.
Sierra is compatible with Pandas, meaning just enter the path to the CSV file in arg dataframe
in getTable()
, and the table will display!
As mentioned, you can also add a table with create_table()
. Make sure the arg rows is a list of lists, even if there's only one row
Output:
foo
foo1
foo2
United States
Croatia
Austria
Czech
Denmark
Canada
Netherlands
Scotland
England
Bulleted lists (ordered and unordered)
Ordered and/or unordered lists can be added with bullets()
using with
.
Just enter a list into the argument points
, specify the type of the list (ordered or unordered), attributes if necessary, and you're good to go.
It doesn't have a .css()
function - use one of the three methods to add CSS to it.
Output:
- pt1
- pt2
- pt3
- pt4
- pt5
- pt6
Adding a description list
Description lists can be added with des_lists()
, which takes in argument des_list
and of course, attributes can be added with **kwargs
.
Just enter in a list of lists as the first argument, and it will show as a description list.
It is not a context manager-based approach.
Output:
- foo
- - foo1
- - foo2
- py
- py1
- - PEP
- - PEP8
Here,
[['foo'], ['- foo1', '- foo2']]
is the first description list, and [['py', 'py1'], ['- PEP', '- PEP8']]
is the
second. These two are separated by commas and are subsets of a list that contains them both. The attribute id='d_list'
was
added to the description list, and CSS was added to the id with writeCSS()
.
So get careful with the list arrangement!
Other functions
Python functions/variables or anything can be added onto the web application using Sierra with much ease. However keep in mind, that every
function/CSS/tag, or anything that is to be added to the HTML must come only after title()
.
Here's a list of other functions you can use with Sierra:
Here's an example:
Regular HTML escape sequences and glyphs and regular tags like <a>
can be used within the context manager or any functions that involve displaying on the web application, like
License