Metadata-Version: 2.5
Name: palestine
Version: 0.2.1
Summary: A full spec DOM implementation for server-side rendering in Python
Project-URL: Homepage, https://github.com/u84u/palestine
Project-URL: Documentation, https://github.com/u84u/palestine#readme
Project-URL: Repository, https://github.com/u84u/palestine
Project-URL: Issues, https://github.com/u84u/palestine/issues
Author: u84u
License: MIT
Keywords: dom,html,rendering,server-side,ssr,template
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.14
Provides-Extra: all
Requires-Dist: django>=6.1; extra == 'all'
Requires-Dist: fastapi>=0.141; extra == 'all'
Requires-Dist: flask>=3.1; extra == 'all'
Requires-Dist: jinja2>=3.1; extra == 'all'
Requires-Dist: weasyprint>=70.0; extra == 'all'
Provides-Extra: django
Requires-Dist: django>=6.1; extra == 'django'
Provides-Extra: fastapi
Requires-Dist: fastapi>=0.141; extra == 'fastapi'
Requires-Dist: jinja2>=3.1; extra == 'fastapi'
Provides-Extra: flask
Requires-Dist: flask>=3.1; extra == 'flask'
Provides-Extra: pdf
Requires-Dist: weasyprint>=70.0; extra == 'pdf'
Description-Content-Type: text/markdown

# Palestine

A full spec DOM implementation for server-side rendering in Python.

## Installation

```bash
pip install palestine
```

## Quick Start

```python
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`, and `Document`
- **HTML Parsing** - Parse HTML strings into DOM trees with `parse_html` and `parse_fragment`
- **Rendering** - Render elements to HTML with `render_element`, `render_node`, and `minify`

### Template Engine

- **Templates** - Create reusable templates with `Template` supporting 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

```python
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

```python
# 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

```python
from fastapi import FastAPI
from palestine.integrations.fastapi import PalestineMiddleware

app = FastAPI()
app.add_middleware(PalestineMiddleware)
```

## Static Site Generation

```python
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
