---
title: RenderScripts
description: Introduction to RenderScripts -- create web pages using python
order: 3
---
*RenderScripts* are regular Python scripts, except that:

- Rather than just having the extension `.py`, they have an extension like `.md.py` or `.qmd.py`
- They contain a module docstring containing YAML frontmatter (three hyphens on a line, YAML metadata, then three hyphens on a line).

These scripts are run when your site is rendered. Anything that they print to stdout becomes a new file in your site. The name of the file is the same as the name of the `.py` script, without the `.py` extension. For instance, the page you're reading right now is created by `renderscript.md.py`, which you'll [find here](https://github.com/AnswerDotAI/fastship/blob/main/ship/tutorials/renderscript.md.py).

Hot/live reloading even works with these .py scripts -- so as soon as you save the script, you'll see the new output in your web browser.

This approach can be particularly helpful for generating data-driven documents. For instance, consider this table, containing a list of the people with testimonials on fastship's home page:

|  | Name | Position |
|--- |--- |--- |
| <img src="../images/chris-lattner.png" alt="" width="60%" /> | Chris Lattner | Inventor of Swift and LLVM |
| <img src="../images/fernando-p%C3%A9rez.jpeg" alt="" width="60%" /> | Fernando Pérez | Creator of Jupyter |
| <img src="../images/david-berg.jpeg" alt="" width="60%" /> | David Berg | Software Engineer, Netflix |
| <img src="../images/erik-gaasedelen.jpeg" alt="" width="60%" /> | Erik Gaasedelen | Software Engineer, Lyft |
| <img src="../images/roxanna-pourzand.jpeg" alt="" width="60%" /> | Roxanna Pourzand | Product Manager, Transform |
| <img src="../images/hugo-bowne-anderson.jpeg" alt="" width="60%" /> | Hugo Bowne-Anderson | Head of Developer Relations, Outerbounds |

When creating a table like this, it can be tricky to ensure that markdown is correct and consistent for every row. It can be easier and more maintainable to programatically generate it. The table above is generated from the following python list:

```python
testimonials = [
    ('chris-lattner.png', 'Chris Lattner', 'Inventor of Swift and LLVM'),
    ('fernando-pérez.jpeg', 'Fernando Pérez', 'Creator of Jupyter'),
    ('david-berg.jpeg', 'David Berg', 'Software Engineer, Netflix'),
    ('erik-gaasedelen.jpeg', 'Erik Gaasedelen', 'Software Engineer, Lyft'),
    ('roxanna-pourzand.jpeg', 'Roxanna Pourzand', 'Product Manager, Transform'),
    ('hugo-bowne-anderson.jpeg', 'Hugo Bowne-Anderson', 'Head of Developer Relations, Outerbounds')
]
```

To produce the table from this python list, the following four lines of code are used:

```python
print(row(['', 'Name', 'Position']))
print(row(['---', '---', '---']))
for fname, name, position in testimonials:
    print(row([im(fname, 60), name, position]))
```

For richer HTML layouts and reusable components, use `fastcore.xml` tags (`Div`, `Img`, `P`, `to_xml`) directly — see [`_index.py`](https://github.com/AnswerDotAI/fastship/blob/main/ship/_index.py) and [`index.qmd`](https://github.com/AnswerDotAI/fastship/blob/main/ship/index.qmd) behind the [fastship home page](https://ship.fast.ai).

You can use RenderScripts to create any kind of file. For instance, the SVG below is created dynamically using [this script](https://github.com/AnswerDotAI/fastship/blob/main/ship/images/circles.svg.py):

<img src="../images/circles.svg" alt="" width="40%" />

Once you've run `ship-preview` or `ship-docs` you'll find your rendered output in `_docs/`. You can also run your script directly from the shell (e.g. `python renderscript.md.py`) to inspect the generated Markdown.
