Static Site Generator



Stapy is a Static Site Generator. It works with Python on any operating system without additional packages.

Download 1.17.10

This documentation covers the version 1.17.10

A question? Contact us!


Requires Python 3.6 or newer on any operating system.



Download the last Stapy release and unzip the archive.



tar zxvf stapy-1.17.10.tar.gz




Start working on the website by running the HTTP server.



Then navigate to the URL in your browser.

Serve from custom host and port by adding an argument:


Note: This involves modifying the base URL in the file source/layout/common.json.

Tip: Create an alias to quickly start the server for your site:

alias stapy='python3 /absolute/path/to/'


Double-click on the file (Python is required, easily install from Microsoft Store if needed).

If the py files open with an editor, right-click and select: Open with... Python 3.X

Then navigate to the URL in your browser.

=^..^= Welcome to Stapy 1.17.9
Serving under


When the site is ready, build it for publishing.


python3 build


Double-click on the file.

If the py files open with an editor, right-click and select: Open with... Python 3.X

=^..^= Welcome to Stapy 1.17.9
Build in progress...
[prod] 56 pages generated in 0.1456 seconds
[devel] 56 pages generated in 0.1348 seconds


Static files are generated in the web directory. This directory contains all the necessary environment directories (devel, prod...).

For the production, add a prod directory in the web directory. It will contain all pages and files you need to deploy (html, css, js, images...).


All necessary resources like js, css or images are copied from the source/assets directory in all environment directories (e.g. web/prod).


For a page, the server search a json file in source/pages directory. The name of the json file is the same as the URL path. Examples:

URL Path Json file
/ index.html.json
/hello.html hello.html.json
/hello/world.html hello/world.html.json
/hello/world/ hello/world/index.html.json

Reserved routes

Route Result (json)
/_pages List all the pages
/_pages/data List all the pages with the data
/_environments List the environments
/_page/hello.html Get the data of the given path
/_content/content/hello.html Get the content of the given file
/_cache/clear Manually clear Json query data cache


The page json file contains all the data required to generate the page:

  "template": "template/default.html",
  "enabled": true,

  "content": "content/index.html",

  "meta_title": "Page meta title",
  "meta_description": "Page meta description",
  "title": "Page title"

Other keys are free and used in the template.

Set the environment variables with the environment suffix:

  "url.local": "",
  "": ""

The environment suffix must have the same name as your environment directory. For local server rendering, the suffix is always "local".

A variable can have a default value:

  "my_text": "All environments display this text",
  "": "Except the prod with this"


A file named html.json in the source/layout directory is used for the default html page configuration. It will be merged with the page's json file. This is useful for a global configuration.


  "title": "Default title",
  "template": "template/default.html"


  "title": "Home title",
  "content": "content/index.html"

layout/html.json + pages/index.html.json

  "title": "Home title",
  "template": "template/default.html",
  "content": "content/index.html"

You can add layout file for any file extensions you need:

A common.json config file is available for all pages (all extensions).

Finally, it is possible to add a layout file for the page subdirectories:

JSON Weight Required
layout/common.json 1 N
layout/html.json 2 N
layout/blog/common.json 3 N
layout/blog/html.json 4 N
layout/blog/2022/html.json 5 N
pages/blog/2022/my-first-post.html.json 6 Y

Json data with higher weight will override and extend lower weights.

Tip: Add _page/ before the path to fetch json merged data.


The template file is the skeleton of the page:

<!DOCTYPE html>
<html lang="fr">
        <meta charset="utf-8">
        <title>{{ meta_title }}</title>
        <meta name="description" content="{{ meta_description }}" />
        <link rel="stylesheet" href="{{ url }}css/style.css" />
            {% block.header %}
            {% content %}
            {% block.footer %}


Note: Escape the brace character to not parse an expression:

\{% block.keep.exp %\}

Child block

Call a child block template declared in page data with {% %} syntax.

  "": "template/block/post.html"
{% %}

Add arguments to the block:

{% firstname:"John" lastname:"Doe" %}

The arguments will be accessible in the "" template with a $ before the var:

Hello {{ $firstname }} {{ $lastname }}!

Use specific json data for the child content with a + separator (spaces are required):

{% + my-first-post.html %}

The json/my-first-post.html.json data will be accessible in the "" template with a $ before the var:

<a href="{{ url }}{{ $_path }}">{{ $post_title }}</a>

To loop json data with a query, use ~ as separator (spaces are required):

{% ~ SELECT ITEMS {start}-{end} WHERE {conditions} ORDER BY {key} {dir} %}


{% ~ SELECT ITEMS 1-10 WHERE "post" in tags AND published = 1 ORDER BY date desc %}

This query retrieves the pages 1 to 10, with post value in tags and published set to 1, sorted by date. The tags, published and date vars must be present in the json data of the pages:

  "date": "2022-01-01",
  "published": 1,
  "tags": ["post"]

The json data will be accessible in the "" template with a $ before the var.

Add an optional block separator with the delimiter parameter:

{% delimiter:"<br />" ~ SELECT ITEMS 1-10 WHERE "post" in tags AND published = 1 ORDER BY date desc %}


The value type must be the same as in the JSON data:

  "published": 1
  "published": "1"

Multiline expressions are allowed:

    delimiter:"<br />"
    ~ SELECT ITEMS 1-10 WHERE "post" in tags AND published = 1 ORDER BY date desc

A block called in the same block never throws an infinite loop error. The child block is ignored.

Reserved variables


Variable Description Example
_path Cleaned page path blog/
_full_path Full page path blog/index.html
_env Environment name prod


{{ url }}{{ _path }}
<!-- -->
{{ url }}{{ _full_path }}
<!-- -->
<script type="text/javascript" src="{{ url }}js/init.{{ _env }}.js"></script>
<!-- -->


A plugin allows you to add custom code when rendering the page.

Method Description Method argument 1 Method argument 2 (dict) Return
file_content_opened Update any file content (html, json, md, css, js...) File content (str or bytes) {path, mode, _stapy} str or bytes
page_data_merged Update the current page json data Page data (dict) {path, _stapy} dict
before_content_parsed Update the page template content before parsing Page content (str) {data, env, path, _stapy} str
after_content_parsed Update the page template content after parsing Page content (str) {data, env, path, _stapy} str
child_content_data Update child data before content generation Child data (dict) {key, env, path, data, _stapy} dict
child_content_query_result Update data result before content generation All child data (list) {key, env, path, data, _stapy} list
custom_http_response Send custom response on a request Response result (tuple or None) {path, request, _stapy} tuple or None
http_request_initialized Execute an action when HTTP request is initialized Current page path {_stapy} None
http_request_sent Execute an action when HTTP request was sent Current page path {_stapy} None
? A free named method called with {: :} syntax Page data (dict) {env, path, _stapy, ?} str

A plugin is a free named python script in the plugins directory, or a script named in a subdirectory:

The _stapy key in argument 2 contains StapyFileSystem, StapyJsonQuery, StapyParser, StapyGenerator and StapyPlugins objects.


To convert Markdown to HTML, add a file in the plugins directory with the following content:

import markdown

def file_content_opened(content: str, args: dict) -> str:
    if args['path'].endswith('.md'):
        return markdown.markdown(content)
    return content

pip3 install markdown

You can now use Markdown syntax in your page content:

Hello World!

[Back to home]({{ url }})

Custom method

In any template file, call a free named method with curly brace colon {: :} syntax.

Search for method in all plugins:

{: my_plugin_method :}

Execute method only in the specified plugin:

{: custom.my_plugin_method :}

The plugin name is the plugin file name without the .py extension or the plugin directory name.

custom.my_plugin_method means to display my_plugin_method result from the plugins/ or plugins/custom/ script.

# plugins/

def my_plugin_method(data: dict, args: dict) -> str:
    return '<strong>Hello World!</strong>'

Add arguments to the method:

{: custom.my_plugin_method firstname:"John" lastname:"Doe" :}
# plugins/

def my_plugin_method(data: dict, args: dict) -> str:
    return '<strong>Hello ' + args['firstname'] + ' ' + args['lastname'] + '</strong>'

Method arguments are optional when you don't need them:

# plugins/

def my_plugin_method() -> str:
    return '<strong>Hello World!</strong>'

Protected methods

All methods other than the custom plugin method should be prefixed by underscore. They can never be called in a template.

# plugins/

def custom_plugin_method(data: dict, args: dict) -> str:
    return _my_method(data)

def _my_method(data: dict) -> str:
    return '<strong>Hello World!</strong>!'

{: custom_plugin_method :} <!-- OK -->
{: _my_method :} <!-- Forbidden -->


All the files in your production environment (e.g. web/prod) must be exposed.

Bug Tracking

For any question or bug report, please add a ticket:

Bug Tracking


Themes for Stapy: