Freezes a Flask application into a set of static files.
npx @tessl/cli install tessl/pypi-frozen-flask@1.0.0Frozen-Flask transforms Flask web applications into static websites by generating static HTML files from all accessible URLs. It provides a comprehensive freezing system with configurable URL generators, automatic static file handling, and support for custom routing patterns.
pip install Frozen-Flaskfrom flask_frozen import FreezerComplete import for all public functionality:
from flask_frozen import Freezer, walk_directory, relative_url_forfrom flask import Flask
from flask_frozen import Freezer
# Create Flask app
app = Flask(__name__)
@app.route('/')
def index():
return '<h1>Hello World!</h1>'
@app.route('/page/<name>/')
def page(name):
return f'<h1>Page: {name}</h1>'
# Initialize freezer
freezer = Freezer(app)
# Register URL generator for dynamic routes
@freezer.register_generator
def page_urls():
yield 'page', {'name': 'about'}
yield 'page', {'name': 'contact'}
# Freeze the application to static files
if __name__ == '__main__':
freezer.freeze() # Generates static files in 'build/' directoryFrozen-Flask operates through a flexible URL generation system that discovers and processes all URLs in a Flask application:
The library automatically handles static files, applies URL generators for dynamic routes, and provides hooks for custom URL generation patterns, making it suitable for converting any Flask application into a deployable static website.
Primary functionality for converting Flask applications to static sites, including the main Freezer class, build process control, and URL discovery mechanisms.
class Freezer:
def __init__(self, app=None, with_static_files=True,
with_no_argument_rules=True, log_url_for=True): ...
def init_app(self, app): ...
def freeze(self): ...
def freeze_yield(self): ...
def all_urls(self): ...Advanced URL generation system for handling dynamic routes, custom URL patterns, and endpoint discovery.
def register_generator(self, function): ...
def static_files_urls(self): ...
def no_argument_rules_urls(self): ...Comprehensive configuration system for controlling build behavior, file handling, error processing, and output customization.
# Configuration options set automatically on app.config
FREEZER_DESTINATION: str
FREEZER_BASE_URL: str
FREEZER_RELATIVE_URLS: bool
FREEZER_REMOVE_EXTRA_FILES: boolHelper functions for directory operations, relative URL generation, and file system utilities.
def walk_directory(root, ignore=()): ...
def relative_url_for(endpoint, **values): ...Frozen-Flask provides a comprehensive warning system for common issues:
class FrozenFlaskWarning(Warning): ...
class MissingURLGeneratorWarning(FrozenFlaskWarning): ...
class MimetypeMismatchWarning(FrozenFlaskWarning): ...
class NotFoundWarning(FrozenFlaskWarning): ...
class RedirectWarning(FrozenFlaskWarning): ...These warnings help identify missing URL generators, MIME type conflicts, 404 responses, and redirect handling issues during the build process.