A Python package for creating and manipulating reusable HTML components
Project description
PyDOM
Simple to learn, easy to use, fully-featured UI library for Python
PyDOM is a Python library that allows you to create web pages using a declarative syntax.
PyDOM provides a set of components that represent HTML elements and can be composed to create complex web pages.
Quick Start
This is a quick start guide to get you up and running with PyDOM. The guide will show you how to setup PyDOM and integrate it with FastAPI.
Installation
First, install the PyDOM package.
pip install pydom
Create Reusable Page
PyDOM provides a default page component that is the minimal structure for a web page.
The page can be customized by extending the default page component and overriding the head and the body methods.
More information about the default page component can be found here.
# app_page.py
from pydom import Link, Page
class AppPage(Page):
def head(self):
return (
*super().head(),
Script(
src="https://cdn.tailwindcss.com/",
)
)
Creating the FastAPI app
Lastly, create the FastAPI app and add an endpoint that will render the page when the user accesses the root route.
# main.py
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from pydom import render, Div, P
from app_page import AppPage
app = FastAPI()
@app.get("/", response_class=HTMLResponse)
async def read_root():
return render(
AppPage(
Div(classes="text-center p-4 rounded")(
Div(classes="text-4xl")(
"Hello, World!"
),
P(classes="text-lg text-gray-600")(
"Welcome to PyDOM"
),
)
)
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="localhost", port=8000)
That's it! Now you can run the app and access it at http://localhost:8000/.
It should display a page like this:
Documentation
The full documentation can be found at our documentation site.
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
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 pydom-0.4.2.tar.gz.
File metadata
- Download URL: pydom-0.4.2.tar.gz
- Upload date:
- Size: 48.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16a8cb23521cf74ede09b35e61f968b65313c16697d320f2018b123e494eb1ce
|
|
| MD5 |
b29c68d1a1f365a145e987b53948a6f7
|
|
| BLAKE2b-256 |
788097eb94f3558daf1fa8f17ea621115265c9a5e82610d4f17bca49694d21a5
|
File details
Details for the file pydom-0.4.2-py3-none-any.whl.
File metadata
- Download URL: pydom-0.4.2-py3-none-any.whl
- Upload date:
- Size: 146.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ab495bb98a6ad1f69aa8c4442ae94fe9b152cb9dd99783685810d917c5b917e
|
|
| MD5 |
8656c2a287b3fa396b92d9361053cd18
|
|
| BLAKE2b-256 |
fc08f8cd4775661fffeff7cef4c3ee1bd9099d3fa5b8ed4bbc0f02133920111c
|