CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-frozen-flask

Freezes a Flask application into a set of static files.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

core-freezing.mddocs/

Core Freezing Operations

Primary functionality for converting Flask applications to static sites. The Freezer class orchestrates URL discovery, file generation, and build management with support for incremental builds and comprehensive error handling.

Capabilities

Freezer Class

Main class for converting Flask applications to static websites. Manages the entire freezing process including URL discovery, file generation, and build output.

class Freezer:
    def __init__(self, app=None, with_static_files=True, 
                 with_no_argument_rules=True, log_url_for=True):
        """
        Initialize Flask app freezer.
        
        Parameters:
        - app: Flask application instance (optional, can use init_app later)
        - with_static_files: Whether to automatically generate URLs for static files
        - with_no_argument_rules: Whether to automatically generate URLs for no-argument rules
        - log_url_for: Whether to log url_for calls for URL generation
        """

Application Initialization

Methods for connecting the freezer to Flask applications.

def init_app(self, app):
    """
    Register a Flask app after Freezer initialization.
    
    Parameters:
    - app: Flask application instance
    """

Freezing Operations

Core methods for executing the static site generation process.

def freeze(self):
    """
    Clean destination and build all URLs from generators.
    
    Returns:
    set: Set of URLs that were frozen
    """

def freeze_yield(self):
    """
    Like freeze() but yields Page namedtuples while processing.
    
    Yields:
    Page: namedtuple with 'url' and 'path' fields for progress tracking
    """

def all_urls(self):
    """
    Run all generators and yield URLs relative to app root.
    
    Returns:
    generator: URLs from all registered generators (testing utility)
    
    Note: Does not generate pages, so url_for logged URLs not included
    """

Build Properties

Properties for accessing build configuration and output locations.

@property
def root(self):
    """
    Absolute path to the directory Frozen-Flask writes to.
    
    Returns:
    Path: Resolved FREEZER_DESTINATION configuration path
    """

File Path Operations

Methods for converting between URL paths and file system paths.

def urlpath_to_filepath(self, path):
    """
    Convert URL path like /admin/ to file path like admin/index.html.
    
    Parameters:
    - path: URL path string
    
    Returns:
    str: Relative file path for the URL
    """

Development Server

Methods for serving frozen content during development and testing.

def serve(self, **options):
    """
    Run HTTP server on the build result.
    
    Parameters:
    - **options: Passed to Flask.run()
    """

def run(self, **options):
    """
    Call freeze() then serve() for build-and-serve workflow.
    
    Parameters:
    - **options: Passed to Flask.run()
    """

def make_static_app(self):
    """
    Return Flask application serving the build destination.
    
    Returns:
    Flask: Application configured to serve static files
    """

Data Types

Page Namedtuple

Data structure returned by freeze_yield() for tracking build progress.

Page = namedtuple('Page', 'url path')

Fields:

  • url: The URL that was frozen
  • path: Path to generated file (relative to build root)

Usage Examples

Basic Freezing

from flask import Flask
from flask_frozen import Freezer

app = Flask(__name__)
freezer = Freezer(app)

# Freeze application
urls = freezer.freeze()
print(f"Generated {len(urls)} pages")

Progress Tracking

import click

# Track freezing progress with click
with click.progressbar(
    freezer.freeze_yield(),
    item_show_func=lambda p: p.url if p else 'Done!') as pages:
    for page in pages:
        # Processing happens automatically
        pass

Deferred Initialization

# Create freezer without app
freezer = Freezer()

# Initialize later
app = Flask(__name__)
freezer.init_app(app)

# Now can freeze
freezer.freeze()

Build and Serve

# Freeze and immediately serve for testing
freezer.run(debug=True, host='0.0.0.0', port=8000)

Install with Tessl CLI

npx tessl i tessl/pypi-frozen-flask

docs

configuration.md

core-freezing.md

index.md

url-generation.md

utilities.md

tile.json