End-To-End Walkthrough
A step-by-step guide to using fastship
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" 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):
- Python 3.10+
uv(recommended) orpipfastship- JupyterLab (when authoring notebooks; plain
.py, Markdown, and.qmdprojects need no Jupyter server)
Quarto is not required — fastship builds static documentation sites directly in Python.
Install JupyterLab
Launch a terminal and install JupyterLab:
uv pip install jupyterlab
(or pip install jupyterlab). Then start JupyterLab:
jupyter lab
This opens JupyterLab in a new browser tab:
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:
Install fastship with uv (or pip):
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 (see GitHub's 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):
You should then be redirected to your new repo:
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 (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 (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 buildanduv publish(and tag-triggered CI releases for native and npm projects). - Built-in static documentation sites with search, Markdown
.mdcopies, andllms.txt(no Quarto required). - GitHub Actions workflows (
ship-ciandship-docs) to verify notebooks, runship-test, and deploy docs to GitHub Pages.
Create your fastship project and enter its directory (substituting your own GitHub username):
ship-new fastship-hello-world --nb --gh-org <your-github-user>
cd fastship-hello-world
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:
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.
fastship uses GitHub Pages by default because its easily accessible. However, you can use any host you like. See these docs 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):
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:
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 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.pyexamples, andpytest)
- Your notebooks are cleaned of noisy metadata (
- Docs (
ship-docs) – Builds your site withfastship(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 you should see a new workflow run: "pages build and deployment". As the name suggests, this workflow deploys your website contents to GitHub Pages.
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):
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.
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:
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:
*.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, or use pre-commit hooks / ship-clean before committing.
See Git-Friendly Jupyter 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 diffon 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:
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:
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:
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.
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
#| 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 reference page):
- H1 heading (
# core) – the page title - Blockquote (
> Core functionality) – the page description
- H1 heading (
- The second is a code cell with
#| default_exp core, which sets the target Python module this notebook exports to (see Directives).
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.
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:
#| hide
#| eval: false
import fastship; fastship.ship_export()
What does this mean?
#| hideexcludes the cell from both the exported module and the published docs.#| eval: falsekeeps docs builds andship-testfrom running it automatically while letting you execute it manually in Jupyter.fastship.ship_export()exports your notebooks and refreshes tracked generated files.
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:
#| 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:
say_hello("Isaac")
'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 asserts:
assert say_hello("Hamel") == "Hello Hamel!"
…or functions from fastcore.test, which behave like assert but also display the actual and expected values if they differ:
from fastcore.test import *
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:
from IPython.display import display,SVG
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.pymodules from notebooks and refreshes_modidx.pyand generatedREADME.mdship-test: runs notebook lessons, literate.pyexamples, andpytestship-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:
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-driverandship-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.ipynbwith your own information - Pushed to GitHub.
Read on to learn about more advanced fastship functionality. Also see our explanations for deep-dives on specific topics, as well as our other tutorials.
Advanced functionality
Add a class
Create a class in 00_core.ipynb as follows:
#| 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
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:
show_doc(HelloSayer.say)
HelloSayer.say
def say():
Do the saying
And add some examples and/or tests:
o = HelloSayer("Alexis")
o.say()
'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:
"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:
[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.
Set up console scripts
Python packaging metadata in pyproject.toml can automatically create cross-platform console 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:
[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. Create an account on PyPI, generate an API token in Account settings, 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):
[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-pypibuilds distributions and uploads directly to PyPI without changing your version or git history.ship-releaseruns the full local release workflow: updatesCHANGELOG.mdfrom closed GitHub issues and PRs using three fixed labels (breaking→ Breaking Changes,enhancement→ New Features,bug→ Bug Fixes), refreshesllms*.txt, builds withuv build --clear, commits and pushes, creates the GitHub release, publishes viauv publish, and commits a[skip ci]version bump. (For Rust/maturin, Zig, and npm projects,ship-releasepushes an annotatedv<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: This lets you fold and unfold each section in your notebook, based on its markdown headings. You can also hit left to go to the start of a section, and right to go to the end
- TOC2: This adds a table of contents to your notebooks, which you can navigate either with the
Navigatemenu 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 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 and Executable .qmd Documents for details.