Palestine
A full spec DOM implementation for server-side rendering in Python.
Installation
pip install palestine
Quick Start
from palestine import Document, Button, Div, Text
doc = Document()
body = doc.create_element('body')
doc.append_child(body)
btn = Button(type="submit", class_="primary")
btn.append_child(Text("Click me"))
body.append_child(btn)
print(doc)
# <!DOCTYPE html>
# <html><body><button type="submit" class="primary">Click me</button></body></html>
Features
Core DOM
- Nodes & Elements - Full DOM tree implementation with
Node,Element,Text,Comment, andDocument - HTML Parsing - Parse HTML strings into DOM trees with
parse_htmlandparse_fragment - Rendering - Render elements to HTML with
render_element,render_node, andminify
Template Engine
- Templates - Create reusable templates with
Templatesupporting variables, conditionals, loops, and more
Styling
- CSS-in-Python - Styled elements with
Styles,styled,Box,Flex,Grid
Forms & Validation
- Form Builder - Declarative form construction with
FormBuilder - Validation - Schema validation with
Validator,Required,Email,URL,Pattern, and more - Serialization - JSON and form data serialization with
to_json,form_data,to_query_string
Framework Integrations
- Flask - Extension for Flask with
PalestineExtension - Django - Middleware and template tags for Django
- FastAPI - Middleware and helpers for FastAPI
Content Generation
- Markdown - Convert Markdown to HTML with
markdown_to_html - Feeds - RSS and Atom feed generation with
RSSFeed,AtomFeed - Sitemaps - XML sitemap generation with
Sitemap,SitemapIndex - Structured Data - Schema.org markup with
Schema - Open Graph & Twitter Cards - Social meta tags with
OpenGraph,TwitterCard
SEO & PWA
- SEO - Generate sitemaps, robots.txt, and structured data with
SEO - PWA - Service worker generation with
PWA,generate_service_worker
Security
- CSRF Protection - Token generation and validation
- HTML Sanitization - Safe HTML rendering with
sanitize_html,escape_html - Password Hashing - Secure password storage with
hash_password,verify_password - Rate Limiting - Request throttling with
RateLimiter - CSP Headers - Content Security Policy generation
Data Management
- ORM - Database models with
Model,Field,QuerySet - Authentication - User auth with
Auth,login_user,logout_user,@login_required - State Management - Application state with
Store,Action,create_store - Caching - LRU cache and memoization with
Cache,memoize,LRUCache
Media & Documents
- Charts - Data visualization with
Chart,BarChart,LineChart,PieChart - PDF Generation - Convert HTML to PDF with
PDF,html_to_pdf - Email - Email composition with
Email,EmailTemplate - File Uploads - Handle file uploads with
FileUpload,UploadedFile
SSR Utilities
- Static Site Generator - Generate static sites with
StaticSiteGenerator - Streaming SSR - Stream HTML responses with
StreamingRenderer - WSGI/ASGI - Integration with
HTMLResponse,html_response,ahtml - Middleware - Request/response middleware with
MiddlewareStack
Developer Tools
- Testing - Test utilities with
TestCase,TestClient,TestResponse - Assertions - DOM assertions with
ElementAssert,DocumentAssert - Mock Server - API mocking with
MockServer,MockResponse - Debugging - Debug tools with
inspect,tree,stats,validate_html - Benchmarks - Performance testing with
Benchmark,benchmark_render - Pretty Print - Formatted HTML output with
pretty_print - Export - Data export to CSV, TSV, JSON, XML with
to_csv,to_json - Analytics - Analytics integration with
GoogleAnalytics,PlausibleAnalytics - Internationalization - i18n support with
I18n,create_i18n
Framework Examples
Flask
from flask import Flask
from palestine.integrations.flask import PalestineExtension
app = Flask(__name__)
palestine = PalestineExtension(app)
@app.route("/")
def home():
doc = Document()
# ... build your page
return palestine.render_response(doc)
Django
# settings.py
MIDDLEWARE = [
...
'palestine.integrations.django.PalestineMiddleware',
]
# views.py
from palestine.integrations.django import render_element
def home(request):
doc = Document()
# ... build your page
return render_element(request, doc)
FastAPI
from fastapi import FastAPI
from palestine.integrations.fastapi import PalestineMiddleware
app = FastAPI()
app.add_middleware(PalestineMiddleware)
Static Site Generation
from palestine import StaticSiteGenerator
ssg = StaticSiteGenerator(output_dir="dist")
ssg.add_route("/", "index.html", {"title": "Home"})
ssg.add_route("/about.html", "about.html", {"title": "About"})
ssg.generate()
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
palestine-0.2.1.tar.gz
(92.2 kB
view details)
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
palestine-0.2.1-py3-none-any.whl
(117.5 kB
view details)
File details
Details for the file palestine-0.2.1.tar.gz.
File metadata
- Download URL: palestine-0.2.1.tar.gz
- Upload date:
- Size: 92.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5856142985ecf42f5784407b05b613a672a057da773e8be0d3736e8c0ad6dd2a
|
|
| MD5 |
3e3eff8e18d3371a7063ce1785e67b34
|
|
| BLAKE2b-256 |
0468b1f24b93b7a152309937cbc6b94724348b235be721ca4e3d25ae469080f1
|
File details
Details for the file palestine-0.2.1-py3-none-any.whl.
File metadata
- Download URL: palestine-0.2.1-py3-none-any.whl
- Upload date:
- Size: 117.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2dafa2cf8869dce5f44bfc0037651a19bc81ff553a3b4eac40c06013de7154d
|
|
| MD5 |
d6942deb67d9465145b78c6ebffc78fa
|
|
| BLAKE2b-256 |
502b838683b709495777ce39db7ffa4c4923c9b9d51064af06619105d25e3ccf
|