---
title: End-To-End Walkthrough
description: A step-by-step guide to using fastship
order: 1
image: ../images/card.png
aliases:
- /tutorial.html
---
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

The written tutorial below shows you how to create a Python package from scratch using fastship.

Alternatively, you can watch this video tutorial recorded for `fastship`'s predecessor `nbdev`, where Jeremy Howard and Hamel Husain walk through the core notebook-driven workflow:

\<iframe width\="560" height\="315" src\="[https://www.youtube-nocookie.com/embed/l7zS8Ld4\_iA](https://www.youtube-nocookie.com/embed/l7zS8Ld4_iA)" frameborder\="0" allow\="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen style\="max-width: 100%; margin: auto" class\="rounded"\>\</iframe\>

## Installation

You'll need the following software to complete the tutorial (you only need to install these once per environment):

1. Python 3.10\+
2. `uv` (recommended) or `pip`
3. `fastship`
4. JupyterLab (when authoring notebooks; plain `.py`, Markdown, and `.qmd` projects need no Jupyter server)

Quarto is not required — `fastship` builds static documentation sites directly in Python.

### Install JupyterLab

Launch a terminal and install JupyterLab:

```sh
uv pip install jupyterlab
```

(or `pip install jupyterlab`). Then start JupyterLab:

```sh
jupyter lab
```

This opens JupyterLab in a new browser tab:

![](images/jupyter-welcome.png)

### Install fastship

The next step is to install fastship itself. JupyterLab comes with its own terminal, so we'll use that moving forward.

In the Launcher, scroll down to the "Other" section, then click "Terminal". If the Launcher isn't opened, you can open it by clicking "File" → "New Launcher".

A new tab should open with a blank terminal -- it might not look exactly the same, depending on how your shell is configured:

![](images/jupyter-blank-terminal.png)

Install `fastship` with `uv` (or `pip`):

```sh
uv pip install fastship
```

No separate Quarto or Conda installation is needed. Next, we'll create a `fastship` project.

## First steps

By the end of this section you'll have your own fastship repo with tests, continuous integration, PyPI packaging, and a documentation website.

### Create an empty GitHub repo

Create an empty GitHub repo at [github.com/new](https://github.com/new) (see GitHub's [*Create a repo*](https://docs.github.com/en/get-started/quickstart/create-a-repo) guide if needed). Leave README, `.gitignore`, and license unchecked so the repository starts empty.

Before you click "Create Repository", it should look similar to this (with your own repository name and description):

<img src="images/github-create-new-repo.png" alt="" fig-align="center" width="600px" />

You should then be redirected to your new repo:

![](images/github-repo-empty.png)

> [!TIP]
> Try GitHub's powerful CLI
>
> GitHub's web interface is a great way to get started. As you grow more experienced, you might want to explore [the GitHub CLI](https://github.com/cli/cli) (command line interface). We often prefer to use command line tools for repetitive tasks where we're likely to make mistakes. Having those tasks written as small scripts in your terminal means that you can repeat them with little effort.

### Create your project with fastship

From the terminal you opened [earlier](#install-fastship) (or any terminal), scaffold your new project with `ship-new`.

`ship-new NAME --nb` creates a new directory with `pyproject.toml`, starter notebooks in `ship/`, a Python package, and GitHub Actions workflows. Omit `--nb` for plain `.py` modules, or pass `--kind maturin|crate|zig|site` for Rust, Zig, or standalone websites. The starter sets up:

- Local Python releases with `uv build` and `uv publish` (and tag-triggered CI releases for native and npm projects).
- Built-in static documentation sites with search, Markdown `.md` copies, and `llms.txt` (no Quarto required).
- GitHub Actions workflows (`ship-ci` and `ship-docs`) to verify notebooks, run `ship-test`, and deploy docs to GitHub Pages.

Create your `fastship` project and enter its directory (substituting your own GitHub username):

```sh
ship-new fastship-hello-world --nb --gh-org <your-github-user>
cd fastship-hello-world
```

> [!NOTE]
> `ship-new` derives the Python package name from the project name (replacing `-` with `_`). Pass `--package <pkg>` to use a different import name, and `--description "..."` to set the package description.

Double-check your `pyproject.toml` file, then initialize git, commit, and push to the empty GitHub repository you created:

```sh
git init
git add .
git commit -m 'Initial commit'
git remote add origin https://github.com/<your-github-user>/fastship-hello-world.git
git push -u origin main
```

### Enable GitHub Pages

fastship hosts your docs on GitHub Pages---an excellent (and free!) way to host websites.

> [!NOTE]
> fastship uses GitHub Pages by default because its easily accessible. However, you can use any host you like.  See [these docs](../explanations/docs.md#deploying-your-docs-on-other-platforms) for more information.

Enable workflow-based GitHub Pages by running `ship-pages` from your project root (this configures GitHub Pages via the GitHub API and sets your repository homepage and documentation URL):

```sh
ship-pages
```

Alternatively, open your repository's **Settings** -\> **Pages** in GitHub and set **Source** to **GitHub Actions**.

Now it's time to see all of the goodies fastship gives you!

### Check out your workflows

Open GitHub Actions by clicking the "Actions" tab near the top of your repo page. You should see two workflow runs:

![](images/github-actions-initial.png)

If you opened this page shortly after pushing your initial commit, the runs may not have a green check (✅) because they're still "In progress" or "Queued". That's no problem, they shouldn't take much more than a minute to complete.

If you see a red cross (❌), that means something failed. Click on the cross, then click "Details", and you'll be able to see what failed. If you can't figure out what's wrong, search [the forum](https://forums.fast.ai/c/nbdev/48) in case someone else resolved the same issue, otherwise create a new post describing your issue in as much detail as you can, and we'll try our best to help you. Remember that including a link to an actual repo and/or GitHub Action is the best way for us to quickly identify what's wrong.

What do these workflows do?

- **CI (`ship-ci`)** -- Runs on every push and pull request to verify that:
  
  - Your notebooks are cleaned of noisy metadata (`ship-clean`)
  - Your exported modules and tracked generated files are in sync (`ship-export`)
  - All tests pass (`ship-test`, covering notebook lessons, literate `.py` examples, and `pytest`)
- **Docs (`ship-docs`)** -- Builds your site with `fastship` (`ship-docs`) and deploys it to GitHub Pages via GitHub Actions.

We provide these basic workflows out-of-the-box, however, you can edit their corresponding YAML files in the `.github/workflows/` folder to your liking.

### Check out your docs

When you [enable GitHub Pages](#enable-github-pages) you should see a new workflow run: "pages build and deployment". As the name suggests, this workflow deploys your website contents to GitHub Pages.

![](images/github-actions-pages.png)

Wait for the workflow run to complete, then open your website. By default it is available at `https://{user}.github.io/{repo}`. The example screenshot below shows the starter site for `nbdev-hello-world` (from `fastship`'s predecessor `nbdev`):

![](images/nbdev-hello-world-site-initial.png)

### Recap

You now have a base fastship repo with continuous integration and hosted documentation! Here's a recap of the steps you took:

- Created a GitHub repo and enabled GitHub Actions Pages (`ship-pages`)
- Scaffolded your project with `ship-new fastship-hello-world --nb`
- Committed and pushed to GitHub.

## Make your first edit

In this section, you'll make your first edit to the repo you created in [*First steps*](#first-steps).

### Configure Git for notebook diffs and merges

Configure Git to use `fastship`'s diff and merge drivers so notebook diffs stay readable and merge conflicts remain valid JSON. To enable them globally across all repositories:

```sh
git config --global merge.jupyternotebook.name "resolve conflicts with ship-fix"
git config --global merge.jupyternotebook.driver "ship-merge %O %A %B %P"
git config --global diff.jupyternotebook.command ship-diff-driver
```

Then select `*.ipynb` in your global attributes file (`~/.config/git/attributes`) or a committed repository `.gitattributes`:

```text
*.ipynb merge=jupyternotebook
*.ipynb diff=jupyternotebook
```

Using the Git drivers requires no Jupyter configuration. If you also want Jupyter Notebook or JupyterLab to clean metadata automatically on save, see [Opt-in Jupyter pre-save cleaning](git_friendly_jupyter.md#opt-in-jupyter-pre-save-cleaning), or use [pre-commit hooks](pre_commit.md) / `ship-clean` before committing.

See [Git-Friendly Jupyter](git_friendly_jupyter.md) for local per-repo setup, matching ordinary text files with `ship-diff-driver`, and cleaning options. In short:

- Fix broken notebooks from git merge conflicts so they can be opened and resolved directly in Jupyter (`ship-merge` / `ship-fix`).
- Show clean cell-level diffs when running `git diff` on notebooks and word-level diffs on plain text (`ship-diff-driver` / `ship-diff`).
- Strip noisy notebook metadata on demand or on save (`ship-clean`).

`fastship`'s Git diff and merge drivers work on *any* git repository, even if it does not use the rest of `fastship`.

### Build your library

You can now export your package and tracked generated files (`_modidx.py` and generated `README.md`) from your notebooks by running:

```sh
ship-export
```

This writes the Python modules declared by your notebooks into your package directory.

### Install your package

You might have noticed that `ship-new fastship-hello-world --nb` created a Python package in your repo named `fastship_hello_world` (replacing `-` with `_` to make a valid Python import name).

Next, install your package in editable mode:

```sh
uv pip install -e '.[dev]'
```

(or `pip install -e '.[dev]'`):

- `-e` -- editable install, so changes to your package take effect immediately without reinstalling.
- `.` -- the current directory.
- `[dev]` -- installs development dependencies used for testing and docs.

### Preview your docs

fastship builds static documentation sites directly in Python for fast feedback loops. `ship-preview` renders your docs locally and rebuilds automatically whenever you edit notebooks, Markdown, `.qmd`, or Python modules.

Start the preview by entering this into your terminal:

```sh
ship-preview
```

Once the initial build finishes, it opens your browser and displays:

```
http://localhost:8000 - refresh your browser after rebuilding
```

Click the link to open the preview in a new browser tab. It should look exactly like your online docs.

> [!TIP]
> We often find it useful to keep a preview window open on the side while we're editing our notebooks in Jupyter.

### Edit 00\_core.ipynb

Now open `ship/00_core.ipynb` (created by `ship-new fastship-hello-world --nb`) in Jupyter. Numeric prefixes like `00_` are optional, and control the reading order of your sidebar and docs.

#### Add your own frontmatter

You'll see something that looks a bit like this:

**core**

> Core functionality

```python
#| default_exp core
```

Let's explain what these special cells mean:

- The first is a Markdown cell with fastship's Markdown *frontmatter* syntax that defines notebook metadata for your documentation site (see the [frontmatter](../api/frontmatter.md) reference page):
  
  - H1 heading (`# core`) -- the page title
  - Blockquote (`> Core functionality`) -- the page description
- The second is a code cell with `#| default_exp core`, which sets the target Python module this notebook exports to (see [Directives](../explanations/directives.md)).

Next, rename the notebook, replace the title and description, and change the default export module for your own project.

Once you're done, save the notebook. The live preview started in the previous section should update with your latest changes.

Rerun all cells in your notebook to ensure that they work, and to export the updated modules.

> [!TIP]
> We find the "restart kernel and run all cells" Jupyter command (the ⏩ button) so invaluable that we bind it to a keyboard shortcut. A common criticism of notebooks is that out-of-order execution leads to irreproducible notebooks. In our experience, making "restart and rerun" a habit solves this problem.

You can also export directly from inside Jupyter using the final cell of the starter notebook:

```python
#| hide
#| eval: false
import fastship; fastship.ship_export()
```

What does this mean?

- `#| hide` excludes the cell from both the exported module and the published docs.
- `#| eval: false` keeps docs builds and `ship-test` from running it automatically while letting you execute it manually in Jupyter.
- `fastship.ship_export()` exports your notebooks and refreshes tracked generated files.

> [!WARNING]
> Remember to delete any unused modules that aren't exported by a notebook or otherwise needed by your package. This is likely to happen if you change the default export of a notebook -- fastship doesn't remove the old module. This is intended, since fastship is designed to work with hybrid packages that use .py modules (with no corresponding notebook) as well as those exported from notebooks.

#### Add your own function

Add a new code cell below the `#| default_exp` cell with a function. For example:

```python
#| export
def say_hello(to):
    "Say hello to somebody"
    return f'Hello {to}!'
```

Notice how it includes `#| export` at the top -- this is a directive (like `#| default_exp`) that tells fastship to include the cell in your exported module and in your documentation.

The documentation should look like this:

---

### say\_hello

> ```
>  say_hello (to)
> ```

Say hello to somebody

#### Add your own examples, tests, and docs

One of the superpowers of notebook-driven development is that you can very easily add examples, tests, and documentation right below your code.

Include regular code cells, and they'll appear (with output) in your docs, for example:

```python
say_hello("Isaac")
```

```output
'Hello Isaac!'
```

This is a test too! When you run `ship-test` it will execute this cell (and all other test cells) and fail if they raise any exceptions.

For tests, it's preferred to use more explicit `assert`s:

```python
assert say_hello("Hamel") == "Hello Hamel!"
```

...or functions from [`fastcore.test`](https://fastcore.fast.ai/test.html), which behave like `assert` but also display the actual and expected values if they differ:

```python
from fastcore.test import *
```

```python
test_eq(say_hello("Hamel"), "Hello Hamel!")
```

Another superpower of notebook-driven development is that your examples can include plots, images, and even JavaScript widgets. For example, here's an SVG circle:

```python
from IPython.display import display,SVG
```

```python
display(SVG('<svg height="100" xmlns="http://www.w3.org/2000/svg"><circle cx="50" cy="50" r="40"/></svg>'))
```

### Prepare your changes

Before committing your changes to GitHub we recommend running `ship-prepare` in the terminal, which runs:

- `ship-export`: exports `.py` modules from notebooks and refreshes `_modidx.py` and generated `README.md`
- `ship-test`: runs notebook lessons, literate `.py` examples, and `pytest`
- `ship-clean`: strips noisy notebook metadata for clean git diffs

### Edit index.ipynb

Now you're ready to personalize your documentation home page and `README.md` file; these are both generated automatically from index.ipynb. Open Jupyter, then click on `ship/index.ipynb` to open it.

We recommend including a longer description about what your package does, how to install it, and how to use it (with a few examples which import and use your package). Remember, examples can be code cells with real outputs rather than plain markdown text -- they'll double as tests too!

### Push to Github

You can now commit and push your changes to GitHub. As we mentioned before, always remember to run `ship-prepare` before you commit to ensure your modules are exported and your tests pass. You can use `git status` to check which files have been generated or changed. Then:

```sh
git add .
git commit -m 'Add `say_hello`; update index' # Update this text with your own message
git push
```

This will kick-off your GitHub Actions. Wait a minute or two for those to complete, then check your updated repo and documentation.

### Recap

Congratulations, you've used all of the basics needed to build projects with fastship! Here's a recap of the steps you took:

- Configured Git notebook diff and merge drivers (`ship-diff-driver` and `ship-merge`)
- Installed your package with `uv pip install -e '.[dev]'`
- Previewed your docs with `ship-preview`
- Added your own frontmatter, function, tests, and docs to `ship/00_core.ipynb`
- Prepared your changes with `ship-prepare`
- Updated `ship/index.ipynb` with your own information
- Pushed to GitHub.

Read on to learn about more advanced fastship functionality. Also see our [explanations](../explanations/index.md) for deep-dives on specific topics, as well as our other [tutorials](index.md).

## Advanced functionality

### Add a class

Create a class in `00_core.ipynb` as follows:

```python
#| export
class HelloSayer:
    "Say hello to `to` using `say_hello`"
    def __init__(self, to): self.to = to
        
    def say(self):
        "Do the saying"
        return say_hello(self.to)
```

This will automatically appear in the docs like this:

### HelloSayer

```python
def HelloSayer(
    to
):
```

*Say hello to `to` using `say_hello`*

#### Document with show\_doc

However, methods aren't automatically documented. To add method docs, use [`show_doc`](../api/showdoc.md#show_doc):

```python
show_doc(HelloSayer.say)
```

### HelloSayer.say

```python
def say():
```

*Do the saying*

And add some examples and/or tests:

```python
o = HelloSayer("Alexis")
o.say()
```

```output
'Hello Alexis!'
```

### Add links with backticks

Notice above there is a link from our new class documentation to our function. That's because we used backticks in the docstring:

```python
    "Say hello to `to` using `say_hello`"
```

These are automatically converted to hyperlinks wherever possible. For instance, here are hyperlinks to `HelloSayer` and `say_hello` created using backticks.

### Set up autoreload

Since you'll be often updating your modules from one notebook, and using them in another, it's helpful if your notebook automatically reads in the new modules as soon as the Python file changes. To make this happen, just add these lines to the top of your notebook:

```
%load_ext autoreload
%autoreload 2
```

### Set up prerequisites

If your module requires other modules as dependencies, you can add those prerequisites to `[project].dependencies` in your `pyproject.toml`.

For example if your module requires the `fastcore` module of at least version 1.0.5, the `torchvision` module of at most version 0.7 and any version of `matplotlib`:

```toml
[project]
dependencies = [
    "fastcore>=1.0.5",
    "torchvision<0.7",
    "matplotlib",
]
```

You can also add optional dependencies using `[project.optional-dependencies]`. For more information about the format of dependencies, see the [pyproject.toml specification](https://packaging.python.org/en/latest/specifications/pyproject-toml/).

### Set up console scripts

Python packaging metadata in `pyproject.toml` can automatically create [cross-platform console scripts](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#creating-executable-scripts). Add a `[project.scripts]` section with one line per command. For instance, here is the line that creates fastship's own `ship-export` command:

```toml
[project.scripts]
ship-export = "fastship.export:ship_export"
```

### Release to PyPI

To let users install your package with `uv pip install your-project` or `pip install your-project`, publish it to [PyPI](https://pypi.org/). Create an account on PyPI, generate an API token in [Account settings](https://pypi.org/manage/account/), and provide it either via `UV_PUBLISH_TOKEN` or a `[pypi]` section in `~/.pypirc` (used only when uploading to PyPI without uv credentials — never sent when `UV_PUBLISH_URL` or `UV_PUBLISH_INDEX` selects an alternate index):

```ini
[pypi]
username = __token__
password = your_pypi_token
```

`fastship` builds and uploads pure-Python packages locally using `uv build --clear` and `uv publish` (no separate `build` or `twine` install needed):

- `ship-pypi` builds distributions and uploads directly to PyPI without changing your version or git history.
- `ship-release` runs the full local release workflow: updates `CHANGELOG.md` from closed GitHub issues and PRs using three fixed labels (`breaking` → **Breaking Changes**, `enhancement` → **New Features**, `bug` → **Bug Fixes**), refreshes `llms*.txt`, builds with `uv build --clear`, commits and pushes, creates the GitHub release, publishes via `uv publish`, and commits a `[skip ci]` version bump. (For Rust/maturin, Zig, and npm projects, `ship-release` pushes an annotated `v<version>` tag for GitHub Actions CI and bumps to the next dev version.)

### Install collapsible headings and toc2

There are two jupyter notebook extensions that I highly recommend when working with projects like this. They are:

- [Collapsible headings](https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/collapsible_headings/readme.html): This lets you fold and unfold each section in your notebook, based on its markdown headings. You can also hit <kbd>left</kbd> to go to the start of a section, and <kbd>right</kbd> to go to the end
- [TOC2](https://jupyter-contrib-nbextensions.readthedocs.io/en/latest/nbextensions/toc2/README.html): This adds a table of contents to your notebooks, which you can navigate either with the `Navigate` menu item it adds to your notebooks, or the TOC sidebar it adds. These can be modified and/or hidden using its settings.

### Math equation support

fastship renders LaTeX math equations natively. Standard LaTeX delimiters (`\(...\)` and `\[...\]`) work by default, and setting `math = "dollars"` in `ship.toml` or `[tool.fastship]` enables `$...$` and `$$...$$`:

Using `$$`, e.g.:

```
\sum_{i=1}^{k+1}i
```

Which is rendered as:

> \\sum\_{i\=1}\^{k\+1}i

Using `$`, e.g.:

```
This version is displayed inline: \sum_{i=1}^{k+1}i . You can include text before and after.
```

Which is rendered as:

> This version is displayed inline: \\sum\_{i\=1}\^{k\+1}i . You can include text before and after.

### Look at fastship "source" for more ideas

Don't forget that fastship itself is written with fastship! It's a good place to see hybrid notebook and `.py` authoring in practice — browse the [ship folder](https://github.com/AnswerDotAI/fastship/tree/main/ship) on GitHub.

### Rich Markdown and site features

fastship renders Markdown and notebooks directly with `mdhtml` and Pagefind — no Quarto installation required. Out of the box you can use callouts (`::: {.callout-note}`), collapsible details blocks (`::: {.details}`), Mermaid diagrams, footnotes, tables, format-conditional blocks (`{{#html}}` / `{{#md}}`), executable `.qmd` blocks, and custom CSS or JavaScript. See [Docs Website](../explanations/docs.md) and [Executable `.qmd` Documents](qmd_intro.md) for details.
