PyKozo is a Python library that allows for complete web development using Python scripts.
Project description
PyKozo
PyKozo is a Python library that allows for complete web development using Python scripts. Currently, it only includes the complete HTML module, but other modules will be added in the future.
Version 0.0.4
Documentation coming soon...
Getting started
Installation:
Run the following command in your command prompt / shell:
pip install -U PyKozo
Your first compilation
You need to instantiate pykozo.html() into a variable and preferably within a function.
from pykozo import html
def my_page():
page = html() # Instantiate the class
# Now, to create HTML with an h1, we'll do the following
page.h1('Hello World') # The first argument is the content inside the h1
# And now, to compile our HTML, we'll do
return page.compile()
# Now if we print the function...
print(my_page())
We'll get this:
<h1>Hello World</h1>
Attributes
You can add all kinds of attributes, such as style or class. Here's an example:
pykozo.html.p('Hi', style='color: #000080;', className='container')
# After the first attribute, you can pass parameters that go into the HTML
About self-closing tags
In HTML, there are tags that only close once, like <input>. In this case, for these tags, the first argument is no longer the content but starts as the first attribute. An example is:
pykozo.html.input(type="submit", value="Submit")
Components and sections
PyKozo recommends and even "forces" you to work with components and sections. How do you create a component? Here's how:
from pykozo import html
def my_button_component(text):
button = html()
button.button(text, type="button")
return button.compile()
def main_page():
page = html()
buttons = ""
for i in range(5):
button = my_button_component(f"Button {i}")
buttons += button
page.div(buttons)
return page.compile()
print(main_page())
and we will receive this:
<div><button type="button">Button 0</button><button type="button">Button 1</button><button type="button">Button 2</button><button type="button">Button 3</button><button type="button">Button 4</button></div>
And an example for a section:
from pykozo import html
def python_frameworks_list():
frameworks = ["Flask", "FastAPI", "Django", "etc"]
section = html()
for framework in frameworks:
section.li(framework)
return section.compile()
def main_page():
page = html()
page.ul(python_frameworks_list())
return page.compile()
print(main_page())
and it prints this:
<ul><li>Flask</li><li>FastAPI</li><li>Django</li><li>etc</li></ul>
Implementation with Flask
PyKozo can integrate with most Python frameworks, one of which is Flask. Here is a very basic example of how to implement it:
from pykozo import html
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
page = html()
page.h1("Hi everyone")
page.h2("My first Page with PyKozo and Flask")
page.img(src='https://source.unsplash.com/random', style="width:400px;")
return page.compile()
if __name__ == "__main__":
app.run()
You can add backend logic, and the code will also display a random image from an API.
CSS Support!
from pykozo import CSS
class Styles1(CSS):
@CSS.style(name="red-text", type="class")
def red_text():
color = "red"
font_size = "20px"
@CSS.style(name="blue-bg", type="id")
def blue_bg():
background_color = "blue"
padding = "10px"
@CSS.style(name="p", type="tag")
def paragraph_style():
line_height = "1.5"
text_align = "justify"
class Styles2(CSS):
@CSS.style(name="green-border", type="class")
def green_border():
border = "2px solid green"
margin = "5px"
@CSS.style(name="yellow-text", type="id")
def yellow_text():
color = "yellow"
font_weight = "bold"
print("Compiled Styles1 CSS:")
print(Styles1.compile())
print("Compiled Styles2 CSS:")
print(Styles2.compile())
We'll get this:
Compiled Styles1 CSS:
.red-text {
color: red;
font-size: 20px;
}
#blue-bg {
background-color: blue;
padding: 10px;
}
p {
line-height: 1.5;
text-align: justify;
}
Compiled Styles2 CSS:
.green-border {
border: 2px solid green;
margin: 5px;
}
#yellow-text {
color: yellow;
font-weight: bold;
}
Extra Functions
Add custom tags
If you want to add a tag that is not registered, you can use the following function:
pykozo.html.add_tag(_tag='tag name', _content='only if the tag is not a self closing tag', _closing_tag=True/False)
An example of usage would be for PyScript.
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pykozo-0.0.4.tar.gz.
File metadata
- Download URL: pykozo-0.0.4.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48d174bad395ad81f4e673d380ce014802b728847b9bc629968195b71d3eb113
|
|
| MD5 |
c56b30b9af045f34febeac2738c0b59e
|
|
| BLAKE2b-256 |
5c967e69e1c584c4a3f336b03345ea8a6d857419b60afba5036625f446a20b0f
|
File details
Details for the file pykozo-0.0.4-py3-none-any.whl.
File metadata
- Download URL: pykozo-0.0.4-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2eebfdb4668e8f54186cec555fcd0c4ac66d7717677b1aae791581d034dd42e
|
|
| MD5 |
39ecf9dd695ffd21d4bc8246b9b7de71
|
|
| BLAKE2b-256 |
0804141fa2d490fe1efaa5e55738288e88c54c7441101447780893ff2b3cc52e
|