Skip to main content

Create flexible websites with markdown content and FastHTML layouts - no design constraints

Project description

Pyxie

Create flexible websites with markdown content and FastHTML layouts - no design constraints.

Overview

Pyxie is a Python package that combines the simplicity of Markdown with the power of FastHTML to create modern, dynamic websites. Write your content in Markdown for maximum readability and maintainability, while leveraging component-based layouts for dynamic features. The result is content that's both beautiful to look at and semantically structured - making it ideal for both human readers and AI/LLM processing.

Features

  • Markdown-First: Write content in plain markdown with optional FastHTML components
  • Flexible Layouts: Define custom layouts with slots for different content sections
  • Content Management: Query and filter content using metadata
  • FastHTML Integration: Create dynamic components with Python

Quick Start

  1. Install Pyxie:
pip install pyx2
  1. Create a basic app (main.py):
from pathlib import Path
from fasthtml.common import *
from datetime import datetime
from pyxie import Pyxie

# Setup paths
BASE_DIR = Path(__file__).parent
CONTENT_DIR = BASE_DIR / "content"
POSTS_DIR = CONTENT_DIR / "posts"

# Initialize Pyxie
pyxie = Pyxie(
    POSTS_DIR,                             # Content directory    
    cache_dir=BASE_DIR / ".cache",         # Enable caching for better performance
    default_layout="default",              # Layout to use if not specified in metadata
    layout_paths=[BASE_DIR / "layouts"],   # Where to look for layouts    
)

# Create FastHTML app with Pyxie middleware
app, rt = fast_app(
    htmlkw=dict(lang="en"),
    middleware=(pyxie.serve_md(),)  # Serve markdown files at their slug paths
)

Key configuration options:

  • First argument is the content directory path
  • default_metadata: Default values for new posts (optional)
  • cache_dir: Enable caching for better performance (optional)
  • default_layout: Layout to use if not specified in metadata (defaults to "default")
  • layout_paths: Where to look for layouts (defaults to checking layouts, templates, static)
  • auto_discover_layouts: Whether to automatically find layouts (defaults to True)
  1. Create your content structure:
my-site/
├── content/
│   └── posts/          # Your markdown content
├── layouts/            # Your layout files
│   └── default.py      # Default layout
├── main.py            # App initialization
└── .cache/            # Generated cache files

Writing Content

Create markdown files with frontmatter metadata:

---
title: "My First Post"
date: 2024-03-19
layout: default
status: published
---

<featured_image>
![My Image](path/to/image.jpg)
</featured_image>

<content>
# Hello World

Regular markdown content here...

<fasthtml>
def Greeting():
    return H1("Welcome to my site!", cls="text-3xl font-bold")

show(Greeting())
</fasthtml>

More markdown content...
</content>

Creating Layouts

Layouts define the structure of your pages and what content sections (slots) are available:

@layout("default")  # Register as the "default" layout
def default_post_layout(metadata):
    """Basic blog post layout."""
    return Div(
        # Header with title
        H1(metadata.get('title', 'Untitled'), cls="text-3xl font-bold"),
        
        # Featured image slot - optional
        Div(None, data_slot="featured_image"),
        
        # Main content slot - required
        Div(None, data_slot="content", cls="prose"),
        
        # Optional conclusion slot
        Div(None, data_slot="conclusion"),
        
        cls="max-w-3xl mx-auto px-4 py-8"
    )

Key concepts:

  • Use @layout(name) to register a layout
  • data_slot="name" defines where content sections appear
  • data_pyxie_show="name" shows that element only when the named slot is filled
  • data_pyxie_show="!name" shows that element only when the named slot is empty
  • Access metadata from the markdown frontmatter

Querying Content

Pyxie provides a powerful API for querying content:

# Get recent published posts
recent_posts = pyxie.get_items(
    status="published",      # Filter by metadata
    order_by=["-date"],     # Sort by date descending
    per_page=5              # Limit results
).items

# Get posts by category
tech_posts = pyxie.get_items(
    category="tech",
    status="published"
).items

# Complex queries
featured_posts = pyxie.get_items(
    status="published",
    is_featured=True,
    order_by=["-date", "title"]  # Sort by date then title
).items

Query features:

  • Filter by any metadata field
  • Sort by multiple fields (prefix with - for descending)
  • Pagination support with per_page and page
  • Returns an object with items and pagination info

Learn More

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Acknowledgements

This project is built on top of FastHTML, a powerful web framework for creating HTML applications with python code. FastHTML provides the core functionality for handling layouts and components in Pyxie. We're grateful to the FastHTML team and community for creating such an excellent foundation to build upon.

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

pyx2-0.1.2.tar.gz (197.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyx2-0.1.2-py3-none-any.whl (50.1 kB view details)

Uploaded Python 3

File details

Details for the file pyx2-0.1.2.tar.gz.

File metadata

  • Download URL: pyx2-0.1.2.tar.gz
  • Upload date:
  • Size: 197.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyx2-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4889a7f016e5adce18e976eb7ea0a73818a4d123d53652cd9846bce38fa4d723
MD5 20a2eb029720872129040094f6f9dc40
BLAKE2b-256 c0eb73ab90917338ab3de6d32c9cd84a9532eb1cea35c585ae8d8b67220540ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyx2-0.1.2.tar.gz:

Publisher: publish.yml on banditburai/pyxie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyx2-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: pyx2-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 50.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyx2-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1b929cec2d88fef51df659a7507d4133bff893543ed99fd2e9117caaea06461a
MD5 1377c4d2bb134f86974a567de3d45fc1
BLAKE2b-256 709bd177eb2f83ba294cf4af8498c80641142d42bc0eac955f7da4e043e42de8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyx2-0.1.2-py3-none-any.whl:

Publisher: publish.yml on banditburai/pyxie

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page