Skip to main content

Generate static web pages from WSGI apps

Project description


Static web page generator created by the Czech Python community.

What this does

Freezeyt is a static webpage freezer. It takes a Python web application and turns it into a set of files that can be served by a simple server like GitHub Pages or Python's http.server.

Freezeyt is compatible with all Python web frameworks that use the common Web Server Gatweay Interface (WSGI)


Freezeyt requires Python 3.6 or above.

It is highly recommended to create and activate a separate virtual environment for this project. You can use venv, virtualenv, Conda, containers or any other kind of virtual environment.

The tool can be installed using:

$ python -m pip install .


To use freezeyt, you need a Python web application. You can use the example Flask app.

Your WSGI application should be named app. Both the application and Freezeyt must be importable (installed) in your environment.

Run freezeyt with the name of your application and the output directory. For example:

$ python -m freezeyt my_app _build

Freezeyt may overwrite the build directory (here, _build), removing all existing files from it.

For more options, see Configuration below.

Python API

Freezeyt also has a Python API, the freeze function that takes an application to freeze and a configuration dict:

from freezeyt import freeze
freeze(app, config)

The config should be a dict as if read from a YAML configuration file (see Configuration below).

From asynchronous code running in an asyncio event loop, you can call freeze_async instead of freeze.


While common options can be given on the command line, you can have full control over the freezing process with a YAML configuration file or a variable with the configuration. You can specify a config file using the -c/--config option, for example:

$ python -m freezeyt my_app _build -c freezeyt.yaml

The configuration variable should be a dictionary. To pass the config variable, use the -C/--import-config option, for example:

$ python -m freezeyt my_app _build -C my_app:freezeyt_config

Here is an example configuration file:

output: ./_build/   # The website will be saved to this directory
    # Let freezeyt know about URLs that are not linked from elsewhere
    # Include additional files in the output:
    # Static files
        copy_from: static/
    # Web host configuration
    ".nojekyll": ''
        copy_from: google-verification.html
    # If a redirect page (HTTP status 3xx) is found, warn but don't fail
    "3xx": warn

The following options are configurable:

Module Name

The module that contains the application must be given on the command line. In it, Freezyt looks for the variable app. A different variable can be specified using :.








To outupt the frozen website to a directory, specify the directory name:

output: ./_build/

Or use the full form – using the dir saver:

    type: dir
    dir: ./_build/

If output is not specified in the configuration file, you must specify the oputput directory on the command line. Specifying it both on the command line and in the config file is an error.

If there is any existing content in the output directory, freezeyt will either remove it (if the content looks like a previously frozen website) or raise an error. Best practice is to remove the output directory before freezing.

Output to dict

For testing, freezeyt can output to a dictionary rather than save files to the disk. This can be configured with:

    type: dict

In this case, the freeze() function returns a dictionary of filenames and their contents. For example, a site with /, /second_page/ and /images/smile.png will be represented as:

    'index.html': b'<html>...',
    'second_page': {
        'index.html': b'<html>...',
    'images': {
        'smile.png': b'\x89PNG\r\n\x1a\n\x00...',

This is not useful in the CLI, as the return value is lost.


The URL where the application will be deployed can be specified with:

prefix: http://localhost:8000/



Freezeyt will freeze all pages starting with prefix that it finds.

The prefix can also be specified on thecommand line with e.g.: --prefix=http://localhost:8000/. The CLI argument has priority over the config file.

Extra pages

URLs of pages that are not reachable by following links from the homepage can specified as “extra” pages in the configuration:

    - /extra/
    - /extra2.html

Freezeyt will freeze these pages in addition to those it finds by following links.

Extra pages may also be given on the command line, e.g. --extra-page /extra/ --extra-page /extra2.html. The lists from CLI and the config file are merged together.

You can also specify extra pages using a Python generator, specified using a module name and function name as follows:

    - generator: my_app:generate_extra_pages

The generate_extra_pages function should take the application as argument and return an iterable of URLs.

When using the Python API, a generator for extra pages can be specified directly as a Python object, for example:

config = {
   'extra_pages': [{'generator': my_generator_function}],
another_config = {
   'extra_pages': [my_generator_function],

Extra files

Extra files to be included in the output can be specified, along with their content.

This is useful for configuration of your static server. (For pages that are part of your website, we recommend adding them to your application rather than as extra files.)

For example, the following config will add 3 files to the output:

      ".nojekyll": ''
      config/xyz: abc

You can also specify extra files using Base64 encoding or a file path, like so:

        base64: "YWJjZAASNA=="
        copy_from: included/config2.dat

It's possible to recursively copy an entire directory using copy_from, as in:

        copy_from: static/

Extra files cannot be specified on the CLI.

Clean up

If an error occurs during the "freeze" process, Freezeyt will delete the incomplete output directory. This prevents, for example, uploading incomplete results to a web hosting by mistake.

If you want to keep the incomplete directory (for example, to help debugging), you can use the --no-cleanup switch or the cleanup key in the configuration file:

cleanup: False

The command line switch has priority over the configuration. Use --no-cleanup to override cleanup: False from the config.

Comparison of MIME type and file type

Freezeyt checks whether the file extensions in its output correspond to the MIME types served by the app. If there's a mismatch, freezeyt fails, because this means a server wouldn't be able to serve the page correctly.

Default MIME type

It is possible to specify the MIME type used for files without an extension. For example, if your server of static pages defaults to plain text files, use:


If the default MIME type isn't explicitly configured in YAML configuration, then the freezeyt uses value application/octet-stream.

The default mimetype cannot be specified on the CLI.

Recognizing file types from extensions

There is possibility to modify the way how to determine file type from file extension. You can setup your own get_mimetype function.

Freezeyt will register your own function, if you specify it in configuration YAML file as:


If the get_mimetype is not defined in configuration file, then freezeyt calls the python function mimetypes.guess_type and uses the mimetype (the first element) it returns.

get_mimetype can be defined as:

  • strings in the form "module:function", which name the function to call,
  • Python functions (if configuring freezeyt from Python, e.g. as a dict, rather than YAML).

The get_mimetype:

  • gets one argument - the filepath as str

  • returns file MIME types as a list of MIME types (e.g. ["text/html"] or ["audio/wav", "audio/wave"]).

If get_mimetype returns None, freezeyt will use the configured default_mimetype (see Default MIME type above).

The get_mimetype function cannot be specified on the CLI.

Using a mime-db database

There is an option to use the MIME type database from the jshttp project, or a database with the same structure. (This is the database used by GitHub Pages). The database will be used to get file MIME type from file suffix.

To use this database, add the path to the JSON file to freezeyt configuration:


This is equivalent to setting get_mimetype to a function that maps extensions to filetypes according to the database.

The mime_db file cannot be specified on the CLI.

Progress bar and logging

The CLI option --progress controls what freezeyt outputs as it handles pages:

  • --progress=log: Output a message about each frozen page to stdout.
  • --progress=bar: Draw a status bar in the terminal. Messages about each frozen page are also printed to stdout.
  • --progress=none: Don't do any of this.

The default is bar if stdout is a terminal, and log otherwise.

It is possible to configure this in the config file using the plugins freezeyt.progressbar:ProgressBarPlugin and freezeyt.progressbar:LogPlugin. See below on how to enable plugins.

Configuration version

To ensure that your configuration will work unchanged in newer versions of freezeyt, you should add the current version number, 1, to your configuration like this:

version: 1

This is not mandatory. If the version is not given, the configuration may not work in future versions of freezeyt.

The version parameter is not accepted on the command line.


It is possible to extend freezeyt with plugins, either ones that ship with freezeyt or external ones.

Plugins are added using configuration like:

    - freezeyt.progressbar:ProgressBar
    - mymodule:my_plugin

Custom plugins

A plugin is a function that freezeyt will call before starting to freeze pages.

It is passed a FreezeInfo object as argument (see the start hook below). Usually, the plugin will call freeze_info.add_hook to register additional functions.


It is possible to register hooks, functions that are called when specific events happen in the freezing process.

For example, if mymodule defines functions start and page_frozen, you can make freezeyt call them using this configuration:

        - mymodule:start
        - mymodule:page_frozen

When using the Python API, a function can be used instead of a name like mymodule:start.


The function will be called when the freezing process starts, before any other hooks.

It is passed a FreezeInfo object as argument. The object has the following attributes:

  • add_url(url, reason=None): Add the URL to the set of pages to be frozen. If that URL was frozen already, or is outside the prefix, does nothing. If you add a reason string, it will be used in error messages as the reason why the added URL is being handled.
  • add_hook(hook_name, callable): Register an additional hook function.
  • total_task_count: The number of pages freezeyt currently “knows about” – ones that are already frozen plus ones that are scheduled to be frozen.
  • done_task_count: The number of pages that are done (either successfully frozen, or failed).
  • failed_task_count: The number of pages that failed to freeze.


The function will be called whenever a page is processed successfully. It is passed a TaskInfo object as argument. The object has the following attributes:

  • get_a_url(): returns a URL of the page, including prefix. Note that a page may be reachable via several URLs; this function returns an arbitrary one.
  • path: the relative path the content is saved to.
  • freeze_info: a FreezeInfo object. See the start hook for details.
  • exception: for failed tasks, the exception raised; None otherwise.
  • reasons: A list of strings explaining why the given page was visited. (Note that as the freezing progresses, new reasons may be added to existing tasks.)


The function will be called whenever a page is not saved due to an exception. It is passed a TaskInfo object as argument (see the page_frozen hook).

Status handling

The status_handlers option defines the way to handle HTTP statuses. For example, the default reaction to a 404 NOT FOUND status is to quit with an error, but you can customize freezeyt to ignore the default error.

    '404': ignore

freezeyt includes a few pre-defined handlers:

  • 'warn': will save the content and send warn message to stdout
  • 'save': freezeyt will save the body of the page. This is the default for status 200 OK.
  • 'follow': freezeyt will save content from the redirected location (this requires a Location header, which is usually added for redirects – 3xx statuses). Redirects to external pages are not supported.
  • 'ignore': freezeyt will not save any content for the page
  • 'error': fail; the page will not be saved and freeze() will raise an exception.

The user can also define a custom handler as:

  • a string in the form 'my_module:custom_handler', which names a handler function to call,
  • a Python function (if configuring freezeyt from Python rather than from YAML).

The handler function takes one argument, task (TaskInfo): information about the freezing task. See the TaskInfo hook for a description. A custom handler should call one of the pre-defined handlers (e.g. freezeyt.status_handlers.follow) and return the return value from it.

Freezeyt's default functions, like follow, can be imported from freezeyt.status_handlers and used from the custom handlers.

For example, status_handlers would be specified as:

    '202': warn
    '301': follow
    '404': ignore
    '418': my_module:custom_handler
    '429': ignore
    '5xx': error

Note that the status code must be a string, so it needs to be quoted in the YAML file.

A range of statuses can be specified as a number (1-5) followed by lowercase xx. (Other "wildcards" like 50x are not supported.)

Status handlers cannot be specified in the CLI.

URL finding

freezeyt discovers new links in the application by URL finders. URL finders are functions whose goal is to find url of specific MIME type. freezeyt offers different configuration options to use URL finders:

  • use predefined URL finders for text/html or text/css (default),
  • define your own URL finder as your function,
  • turn off some of finders (section below)

Example of configuration:

    text/html: get_html_links
    text/css: get_css_links

Keys in the url_finders dict are MIME types;

Values are URL finders, which can be defined as:

  • strings in the form "module:function", which name the finder function to call,
  • strings like get_html_links, which name a function from the freezeyt.url_finders module, or
  • Python functions (if configuring freezeyt from Python rather than YAML).

An URL finder gets these arguments:

  • page content BinaryIO,
  • the absolute URL of the page, as a string,
  • the HTTP headers, as a list of tuples (WSGI).

The function should return an iterator of all URLs (as strings) found in the page's contents, as they would appear in href or src attributes. Specifically:

  • The URLs can be relative.
  • External URLs (i.e. those not beginning with prefix) should be included.

Finder functions may be asynchronous:

  • The function can be defined with async def (i.e. return a coroutine). If it is, freezeyt will use the result after await.
  • The function may be an asynchronous generator (defined with async def and use yield). If so, freezeyt will use async iteration to handle it.

The freezeyt.url_finders module includes the default finders get_html_links and get_css_links, and their asynchronous variants get_html_links_async and get_css_links_async.

URL finders cannot be specified in the CLI.

Default get_html_links

The default URL finder for HTML pages looks in src and href attributes of all tags in the document. It currently does not handle other links, such as embedded CSS, but it may be improved in the future.

Default get_css_links

The default URL finder for CSS uses the css_parser library to find all links in a stylesheet.

Disabling default URL finders

If a finder is not explictly specified in the configuration file, freezeyt will use the default for certain MIME type. For example, if you specify text/html: my_custom_finder only, freezeyt will use the default finder for text/css.

You can disable this behaviour:

use_default_url_finders: false

Path generation

It is possible to customize the filenames that URLs are saved under using the url_to_path configuration key, for example:

url_to_path: my_module:url_to_path

The value can be:

  • a strings in the form "module:function", which names the function to call (the function can be omitted along with the colon, and defaults to url_to_path), or
  • a Python function (if configuring freezeyt from Python rather than YAML).

The function receives the path of the URL to save, relative to the prefix, and should return a path to the saved file, relative to the build directory.

The default function, available as freezeyt.url_to_path, adds index.html if the URL path ends with /.

url_to_path cannot be specified in the CLI.

Examples of CLI usage

$ python -m freezeyt my_app _build/
$ python -m freezeyt my_app _build/ --prefix
$ python -m freezeyt my_app _build/ -c config.yaml
$ python -m freezeyt my_app _build/ --prefix --extra-page /extra1/ --extra-page /extra2/
$ python -m freezeyt my_app _build/ --prefix --extra-page /extra1/ --extra-page /extra2/ --config path/to/config.yaml


Are you interested in this project? Awesome! Anyone who wants to be part of this project and who's willing to help us is very welcome. Just started with Python? Good news! We're trying to target mainly the beginner Pythonistas who are seeking opportunities to contribute to (ideally open source) projects and who would like to be part of an open source community which could give them a head start in their (hopefully open source :)) programming careers.

Soo, what if you already have some solid Python-fu? First, there's always something new to learn, and second, we'd appreciate if you could guide the “rookies” and pass on some of the knowledge onto them.

Contributions, issues and feature requests are welcome. Feel free to check out the issues page if you'd like to contribute.

How to contribute

  1. Clone this repository to your local computer:
$ git clone
  1. Then fork this repo to your GitHub account
  2. Add your forked repo as a new remote to your local computer:
$ git remote add <remote_label><username>/freezeyt
  1. Create a new branch at your local computer
$ git branch <branch_name>
  1. Switch to your new branch
$ git switch <branch_name>
  1. Update the code
  2. Push the changes to your forked repo on GitHub
$ git push <remote_label> <branch_name>
  1. Finally, make a pull request from your GitHub account to origin

Installing for development

freezeyt can be installed from the current directory:

$ python -m pip install -e .

It also has several groups of extra dependecies:

  • blog for the project blog
  • dev for development and running tests
  • typecheck for mypy type checks

Each group can be installed separately:

$ python -m pip install -e ."[typecheck]"

or you can install more groups at once:

$ python -m pip install -e ."[blog, dev, typecheck]"

Using an in-development copy of freezeyt

  • Set PYTHONPATH to the directory with freezeyt, for example:

    • Unix: export PYTHONPATH="/home/name/freezeyt"
    • Windows: set PYTHONPATH=C:\Users\Name\freezeyt
  • Install the web application you want to freeze. Either:

    • install the application using pip, if possible, or
    • install the application's dependencies and cd to the app's directory.
  • Run freezeyt, for example:

    • python -m freezeyt demo_app_url_for _build --prefix http://freezeyt.test/foo/


For testing the project it's necessary to install additional requirements:

$ python -m pip install .[dev]

To run tests in your current environment, use pytest:

$ python -m pytest

To run tests with multiple Python versions (if you have them installed), install tox using python -m pip install tox and run it:

$ tox

Environ variables for tests

Some test scenarios compare freezeyt's results with expected output. When the files with expected output don't exist yet, they can be created by setting the environment variable TEST_CREATE_EXPECTED_OUTPUT to 1:





If you set the variable to any different value or leave it unset then the files will not be recreated (tests will fail if the files are not up to date).

When output changes, you need to first delete the expected output, regenerate it by running tests with TEST_CREATE_EXPECTED_OUTPUT=1, and check that the difference is correct.

Tools and technologies used

How to watch progress

Unfortunately our progress of development can be watched only in Czech language.

Watch the progress:

Other communication channels and info can be found here:

Freezeyt Blog

We keep a blog about the development of Freezeyt. It is available here.

Be warned: some of it is in the Czech language.

Blog development

The blog was tested on Python version 3.8.

The blog is a Flask application. To run it, install additional dependecies with python -m pip install .[blog]. Then, set the environment variable FLASK_APP to the path of the blog app. Also set FLASK_ENV to "development" for easier debugging. Then, run the Flask server.

  1. On Microsoft Windows:
> python -m pip install .[blog]
> set FLASK_APP=freezeyt_blog/
> set FLASK_ENV=development
> flask run
  1. On UNIX:
$ python -m pip install .[blog]
$ export FLASK_APP=freezeyt_blog/
$ export FLASK_ENV=development
$ flask run

The URL where your blog is running will be printed on the terminal.

Once you're satisfied with how the blog looks, you can freeze it with:

$ python -m freezeyt freezeyt_blog/build

Adding new articles to freezeyt blog

Articles are writen in the Markdown language.

Article - save to directory ../freezeyt/freezeyt_blog/articles

Images to articles - save to directory ../freezeyt/freezeyt_blog/static/images

If te files are saved elsewhere, the blog will not work correctly.


Why did the project start?

The Czech Python community uses a lot of static web pages that are generated from a web application for community purposes. For example, organizing and announcing workshops, courses, or meetups.

The community has been so far relying on Frozen Flask and elsa in order to generate the static web content. The new freezer ought to be used with any arbitrary Python Web application framework (Flask, Django, Tornado, etc.). So the community won't be limited by one web app technology for generating static pages anymore.


See GitHub history for all contributors.


This project is licensed under the MIT License. May it serve you well.

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

freezeyt-1.0.tar.gz (35.1 kB view hashes)

Uploaded source

Built Distribution

freezeyt-1.0-py3-none-any.whl (29.4 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page