---
title: Configuration and version bumping
description: Project detection, unified TOML configuration, version bumping, and package
  metadata helpers for `fastship`.
order: 1
---
Configure `fastship` in either `ship.toml` at the project root or `[tool.fastship]` inside `pyproject.toml` (never both; optional when defaults suffice). Packaging metadata (`name`, `version`, `description`, [`authors`](core.md#authors), `urls`, `entry-points`) is read directly from native manifests (`pyproject.toml`, `Cargo.toml`, `package.json`) and git remotes without duplication.

Use `ship-bump` from the command line or [`ship_bump`](config.md#ship_bump) in Python to increment semantic versions (`X.Y.Z`) or `.postN` suffixes in `Cargo.toml`, `package.json`, static `[project].version`, or `pkg/__init__.py`, syncing any `version-files` in the same step.

```bash
ship-bump                  # bump patch (or .postN when present)
ship-bump --part 1         # bump minor and drop any .postN suffix
ship-bump --part 2 --unbump
```

## snake\_keys

```python
def snake_keys(
    o
):
```

*Return `o` with every `-` in dict keys replaced by `_`, recursively.*

## parse\_ship\_cfg

```python
def parse_ship_cfg(
    text:str, # TOML configuration text
    root:str | pathlib._local.Path='.', # Base directory for resolving relative `output`
    path:str | pathlib._local.Path='ship.toml', # Path shown in error messages
)->dict: # Snake-case settings dict with resolved `output` when set
```

*Parse `ship.toml` TOML `text` into snake-case settings with an absolute `output` path; empty text gives `{}`.*

## read\_ship\_cfg

```python
def read_ship_cfg(
    root:str | pathlib._local.Path, # Project or site root directory
    data:dict=None, # Optional parsed `pyproject.toml` dict (read from `root/pyproject.toml` when None)
)->tuple[dict, pathlib._local.Path | None]: # `(settings_dict, config_file_path)`
```

*Read fastship settings from `root/ship.toml` or `[tool.fastship]` in `root/pyproject.toml`, erroring if both exist.*

## ship\_cfg

```python
def ship_cfg(
    data:dict, # Parsed `pyproject.toml` dict
    root:str | pathlib._local.Path=None, # Optional project root to also check `ship.toml` with mutual-exclusion validation
)->dict: # Normalized snake-case fastship settings dict
```

*Return normalized fastship settings from `root/ship.toml` or `[tool.fastship]` in `data`.*

## Configuration

Unified project configuration and orthogonal version resolution for Python, hybrid, Rust/maturin, crate, npm, and standalone site projects.

### ShipConfig

```python
def ShipConfig(
    root:pathlib._local.Path, # Project root directory
    pyproject:pathlib._local.Path | None, # Resolved path to `pyproject.toml`, or `None` for non-Python projects
    data:dict, # Parsed `pyproject.toml` dictionary (or `{}`)
    branch:str, # Release git branch
    changelog_file:pathlib._local.Path, # Path to `CHANGELOG.md` (or configured `changelog-file`)
    version_files:list[pathlib._local.Path], # Extra files from `version-files` updated on bump
    pkg:str | None, # Package import directory name, or `None` for GitHub-only, non-Python, or site projects
    pkg_path:pathlib._local.Path | None, # Path to the package directory, or `None` when absent
    init_file:pathlib._local.Path | None, # Path to `pkg/__init__.py`, or `None` when absent
    wheel_only:bool, # Whether `wheel-only` skips sdist builds
    ship:dict=<factory>, # Normalized snake-case `ship.toml` / `[tool.fastship]` settings
    ship_file:pathlib._local.Path | None=None, # Resolved `ship.toml` or `pyproject.toml` providing fastship config
    ship_path:pathlib._local.Path | None=None, # Resolved content directory (`root/ship` by default, or configured `ship-path`)
    output:pathlib._local.Path | None=None, # Resolved site build output directory (defaults to `root/_docs`)
    lib_name:str='', # Distribution or project name
    title:str='', # Display title
    description:str='', # Short project description
    keywords:list[str]=<factory>, # Project keywords
    min_python:str='3.11', # Minimum Python version string
    author:str | None=None, # Primary author name from package metadata
    author_email:str | None=None, # Primary author email from package metadata
    git_url:str='', # Repository URL (without trailing `/`)
    doc_url:str='', # Published documentation URL
    user:str='', # Repository owner/org
    repo:str='', # Repository name
    doc_host:str='', # Documentation scheme + host (e.g. `https://ship.fast.ai`)
    doc_baseurl:str='/', # Documentation URL path prefix (e.g. `/` or `/fastship`)
)->None:
```

*Unified configuration for Python, notebook, hybrid, Rust/maturin, crate, Zig, npm, GitHub-only, and standalone site projects.*

#### ShipConfig.config\_path

```python
def config_path()->pathlib._local.Path:
```

#### ShipConfig.config\_file

```python
def config_file()->pathlib._local.Path:
```

#### ShipConfig.lib\_path

```python
def lib_path()->pathlib._local.Path:
```

#### ShipConfig.version

```python
def version()->str:
```

*Current version read fresh from the authoritative manifest (`Cargo.toml`, `package.json`, `[project].version`, or `__version__`).*

#### ShipConfig.gh\_only

```python
def gh_only()->bool:
```

*Return `True` when this project has no Python package and releases on GitHub only.*

#### ShipConfig.d

```python
def d()->dict:
```

#### ShipConfig.get

```python
def get(
    k:str, default=None
):
```

#### ShipConfig.path

```python
def path(
    k:str, default=None
)->pathlib._local.Path | None:
```

### get\_config

```python
def get_config(
    start:str | pathlib._local.Path | None=None, # Starting file or directory (defaults to current working directory)
)->fastship.config.ShipConfig:
```

*Load unified [`ShipConfig`](config.md#shipconfig) from the nearest project or site marker (`pyproject.toml`, `package.json`, `Cargo.toml`, `ship.toml`).*

Reads fastship settings from either `ship.toml` or `[tool.fastship]` (erroring if both exist), infers packaging facts from native manifests and git remotes, and refuses uv workspace roots (`CliError`). Outside any project, returns a default [`ShipConfig`](config.md#shipconfig) rooted at `start`.

## Version bumping

### version\_source

```python
def version_source(
    cfg:fastship.config.ShipConfig
)->tuple[str, collections.abc.Callable]:
```

*Resolve `(current_version, writer)` for `cfg` from Cargo TOML, `package.json`, static `[project].version`, or `__version__`.*

### bump\_cfg

```python
def bump_cfg(
    cfg:fastship.config.ShipConfig, # Already-loaded project configuration
    part:int=None, # Semver part from the left (`0` major, `1` minor, `2` patch); defaults to `.postN` when present, else patch (`2`)
    unbump:bool=False, # Decrement instead of incrementing
    version_src:tuple[str, collections.abc.Callable]=None, # Optional pre-resolved `(old, write)` from `version_source(cfg)`
)->str: # The new version string
```

*Bump the authoritative version file for `cfg` and sync configured `version-files`.*

### ship\_bump

```python
def ship_bump(
    part:int=None, # Semver part from the left (`0` major, `1` minor, `2` patch); defaults to `.postN` when present, else patch (`2`)
    unbump:bool=False, # Decrement instead of incrementing
):
```

*Bump the authoritative project version in place and sync configured `version-files`.*

### version\_copies

```python
def version_copies(
    old:str, version_files:list[pathlib._local.Path]
)->dict[pathlib._local.Path, str]:
```

*Read synchronized `version_files` and raise `ValueError` unless `old` appears exactly once in each before any write.*

### write\_npm\_version

```python
def write_npm_version(
    pkg_json:pathlib._local.Path, version:str
):
```

*Rewrite the top-level `version` field in `pkg_json`, preserving existing indentation.*

## Project detection

### find\_project

```python
def find_project(
    start:pathlib._local.Path | None=None
)->tuple[typing.Literal['py', 'npm', 'crate', 'site'], pathlib._local.Path]:
```

*Find the nearest project or site marker walking up from `start`.*

Checks `pyproject.toml` (`"py"`), `package.json` (`"npm"`), `Cargo.toml` (`"crate"`), and `ship.toml` (`"site"`). When multiple markers live in the same directory, priority follows that order.

### project\_type

```python
def project_type(
    root:pathlib._local.Path, data:dict
)->Literal['rust', 'zig', 'python']:
```

*Classify a `pyproject.toml` project as `'rust'`, `'zig'`, or `'python'`.*

### ship\_src\_dir

```python
def ship_src_dir(
    root:str | pathlib._local.Path, # Project or site root directory
    ship:dict=None, # Optional already-loaded normalized fastship config dict
    data:dict=None, # Optional parsed `pyproject.toml` dict
)->pathlib._local.Path: # Resolved content directory (`root/ship` by default, or configured `ship-path`)
```

*Resolve the project's content directory: configured `ship-path`, else `root/ship`.*

### find\_pkg\_path

```python
def find_pkg_path(
    root:str | pathlib._local.Path, # Project root directory
    data:dict=None, # Optional parsed `pyproject.toml` dict
    ship:dict=None, # Optional normalized fastship config dict
)->pathlib._local.Path:
```

*Locate the Python package directory under `root`, honoring `lib-path` before falling back to [`fastcore.project.find_pkg_path`](https://fastcore.fast.ai/project.html#find_pkg_path).*

### gh\_only

```python
def gh_only(
    root:pathlib._local.Path, data:dict, ship:dict=None
)->bool:
```

*Return `True` when a project defines a static `[project].version` and has no Python package to build.*

### is\_maturin\_project

```python
def is_maturin_project(
    data:dict
)->bool:
```

*Return `True` when `pyproject.toml` `data` configures a maturin/PyO3 build.*

## Git, URL, and TOML helpers

### branch

```python
def branch(
    ship:dict=None, path:pathlib._local.Path=None
)->str:
```

*Resolve the target git branch: configured [`branch`](config.md#branch), else current git branch, else `'main'`.*

### parse\_repo

```python
def parse_repo(
    repo:str=None, # Explicit `"OWNER/REPO"` slug, bare repo name, or `None`
    path:pathlib._local.Path=None, # Directory to inspect git `remote.origin.url` in
)->tuple[str | None, str | None]: # `(owner, repo_name)`, with `None` elements if unresolved
```

*Parse an `'OWNER/REPO'` string, falling back to the git `origin` remote in `path`.*

```python
assert parse_repo("AnswerDotAI/fastship") == ("AnswerDotAI", "fastship")
```

### repo\_slug

```python
def repo_slug(
    root:str | pathlib._local.Path, data:dict=None
)->tuple[str | None, str | None]:
```

*Infer `(owner, repo)` from `[project.urls]` GitHub links, falling back to git `origin` remote.*

### repo\_branch

```python
def repo_branch(
    root:str | pathlib._local.Path, data:dict=None, ship:dict=None
)->str:
```

*Return the project's configured or active git branch.*

### repo\_blob\_base

```python
def repo_blob_base(
    root:str | pathlib._local.Path, data:dict=None, ship:dict=None
)->str:
```

*Return the GitHub blob base URL (`https://github.com/owner/repo/blob/branch/`), or `''` when unresolved.*

### git\_cmd

```python
def git_cmd(
    cmd:str, # Git arguments string, split with `shlex.split` (e.g. `"branch --show-current"`)
    default:str='', # Value returned when git fails or outputs only whitespace
    path:pathlib._local.Path=None, # Working directory for git (defaults to current working directory)
)->str: # Stripped stdout, or `default`
```

*Run `git <cmd>` in `path` and return stripped stdout, falling back to `default` on failure or empty output.*

### gh\_url

```python
def gh_url(
    org:str, proj:str
)->str:
```

*Build the GitHub repository URL `https://github.com/{org}/{proj}`.*

### pages\_url

```python
def pages_url(
    org:str, proj:str
)->str:
```

*Build the GitHub Pages URL `https://{org}.github.io/{proj}/`.*

### docs\_base\_url

```python
def docs_base_url(
    root:str | pathlib._local.Path, # Project root directory
    data:dict=None, # Optional parsed `pyproject.toml` mapping
    ship:dict=None, # Optional normalized fastship settings dict
)->str: # Published docs base URL ending with `/`, or `""` when unknown
```

*Return the published docs base URL from `site-url`, `[project.urls].Documentation`, or inferred GitHub Pages URL.*

### modidx\_settings

```python
def modidx_settings(
    root:str | pathlib._local.Path, data:dict=None, pkg_path:pathlib._local.Path=None, ship:dict=None
)->dict:
```

*Build the `settings` dict stored inside `pkg/_modidx.py`.*

### project\_defaults

```python
def project_defaults(
    root:str | pathlib._local.Path, # Project root containing `pyproject.toml` or `ship.toml`
    data:dict=None, # Optional parsed `pyproject.toml` mapping
    ship:dict=None, # Optional normalized fastship settings dict
)->dict: # Default site settings (snake-case) derived from native project metadata
```

*Derive default site settings (`title`, `description`, `site_url`, `tools`) from native manifests and git remote.*

### toml\_set

```python
def toml_set(
    p:pathlib._local.Path, # Path to the TOML file to update in place
    section:str, # Dotted table name (e.g. `"tool.fastship"` or `"project.urls"`)
    items:dict, # Key/value pairs to write into `[section]`
    replace:bool=True, # Overwrite keys that already exist (matched case-insensitively)
):
```

*Write `items` into dotted `[section]` of TOML file `p`, preserving comments and formatting.*

## Notebook and package helpers

### page\_nm

```python
def page_nm(
    rel:str | pathlib._local.Path
)->str:
```

*Output name of `rel`: its stem without any leading numeric prefix.*

### create\_output

```python
def create_output(
    txt, mime:str
)->list[dict]:
```

*Build a notebook `execute_result` cell output containing `txt` of MIME type `text/{mime}`.*

### show\_src

```python
def show_src(
    src:str, lang:str='python'
):
```

*Return an IPython Markdown display object fencing `src` in `lang`.*

### nbpath2html

```python
def nbpath2html(
    p:str | pathlib._local.Path
)->pathlib._local.Path:
```

*Convert notebook path `p` to its HTML doc path, stripping any numeric prefix.*

```python
assert nbpath2html(Path("foo/bar/012abc_my.notebook.ipynb")) == Path("foo/bar/my.notebook.html")
```

### nbpath2docurl

```python
def nbpath2docurl(
    nb_path:str | pathlib._local.Path
)->str:
```

*Hosted Markdown docs URL (`.md`) for notebook `nb_path`, or `''` if no `doc_host`.*

### is\_export\_call

```python
def is_export_call(
    src:str
)->bool:
```

*Return `True` when code cell source `src` contains a manual `nbdev_export()` or [`ship_export()`](export.md#ship_export) call.*

### update\_init\_mdoc

```python
def update_init_mdoc(
    path:str | pathlib._local.Path=None, desc:str=None
):
```

*Write an explicitly exported index-notebook intro to `path/__init__.py` without clobbering hand-written docstrings.*

### import\_obj

```python
def import_obj(
    s:str
):
```

*Import and return the object named by a `'module:attr'` or `'module.attr'` string.*

### write\_cells

```python
def write_cells(
    cells, hdr:str, file, solo_nb:bool=False
):
```

*Write exported code `cells` to `file` with cell-origin header `hdr`.*
