Configuration file v2 (.readthedocs.yaml)ο
Read the Docs supports configuring your documentation builds with a configuration file.
This file is named .readthedocs.yaml
and should be placed in the top level of your Git repository.
The .readthedocs.yaml
file can contain a number of settings that are not accessible through the Read the Docs website.
Because the file is stored in Git, the configuration will apply to the exact version that is being built. This allows you to store different configurations for different versions of your documentation.
Below is an example YAML file which shows the most common configuration options:
1# Read the Docs configuration file for Sphinx projects
2# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3
4# Required
5version: 2
6
7# Set the OS, Python version and other tools you might need
8build:
9 os: ubuntu-22.04
10 tools:
11 python: "3.11"
12 # You can also specify other tool versions:
13 # nodejs: "20"
14 # rust: "1.70"
15 # golang: "1.20"
16
17# Build documentation in the "docs/" directory with Sphinx
18sphinx:
19 configuration: docs/conf.py
20 # You can configure Sphinx to use a different builder, for instance use the dirhtml builder for simpler URLs
21 # builder: "dirhtml"
22 # Fail on all warnings to avoid broken references
23 # fail_on_warning: true
24
25# Optionally build your docs in additional formats such as PDF and ePub
26# formats:
27# - pdf
28# - epub
29
30# Optional but recommended, declare the Python requirements required
31# to build your documentation
32# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
33# python:
34# install:
35# - requirements: docs/requirements.txt
1# Read the Docs configuration file for MkDocs projects
2# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3
4# Required
5version: 2
6
7# Set the version of Python and other tools you might need
8build:
9 os: ubuntu-22.04
10 tools:
11 python: "3.11"
12
13mkdocs:
14 configuration: mkdocs.yml
15
16# Optionally declare the Python requirements required to build your docs
17python:
18 install:
19 - requirements: docs/requirements.txt
See also
- Configuration file tutorial
Practical steps to add a configuration file to your documentation project.
Supported settingsο
Read the Docs validates every configuration file. Any configuration option that isnβt supported will make the build fail. This is to avoid typos and provide feedback on invalid configurations.
Warning
When using a v2 configuration file, the local settings from the web interface are ignored.
versionο
- Required:
true
Example:
version: 2
Warning
If you donβt provide the version, v1 will be used.
formatsο
Additional formats of the documentation to be built, apart from the default HTML.
- Type:
list
- Options:
htmlzip
,pdf
,epub
,all
- Default:
[]
Example:
version: 2
# Default
formats: []
version: 2
# Build PDF & ePub
formats:
- epub
- pdf
Note
You can use the all
keyword to indicate all formats.
version: 2
# Build all formats
formats: all
Warning
At the moment, only Sphinx supports additional formats.
pdf
, epub
, and htmlzip
output is not yet supported when using MkDocs.
With builds from pull requests, only HTML formats are generated. Other formats are resource intensive and will be built after merging.
pythonο
Configuration of the Python environment to be used.
version: 2
python:
install:
- requirements: docs/requirements.txt
- method: pip
path: .
extra_requirements:
- docs
- method: pip
path: another/package
system_packages: true
python.versionο
Warning
This option is now deprecated and replaced by build.tools.python. See python.version (legacy) for the description of this option.
python.installο
List of installation methods of packages and requirements. You can have several of the following methods.
- Type:
list
- Default:
[]
Requirements fileο
Install packages from a requirements file.
The path to the requirements file, relative to the root of the project.
- Key:
requirements
- Type:
path
- Required:
false
Example:
version: 2
python:
install:
- requirements: docs/requirements.txt
- requirements: requirements.txt
Warning
If you are using a Conda environment to
manage the build, this setting will not have any effect. Instead
add the extra requirements to the environment
file of Conda.
Packagesο
Install the project using pip install
(recommended) or python setup.py install
(deprecated).
The path to the package, relative to the root of the project.
- Key:
path
- Type:
path
- Required:
false
The installation method.
- Key:
method
- Options:
pip
,setuptools
(deprecated)- Default:
pip
Extra requirements section to install in addition to the package dependencies.
Warning
You need to install your project with pip
to use extra_requirements
.
- Key:
extra_requirements
- Type:
list
- Default:
[]
Example:
version: 2
python:
install:
- method: pip
path: .
extra_requirements:
- docs
With the previous settings, Read the Docs will execute the next commands:
pip install .[docs]
python.system_packagesο
Give the virtual environment access to the global site-packages directory.
- Type:
bool
- Default:
false
Warning
If you are using a Conda environment to manage the build, this setting will not have any effect, since the virtual environment creation is managed by Conda.
condaο
Configuration for Conda support.
version: 2
conda:
environment: environment.yml
conda.environmentο
The path to the Conda environment file, relative to the root of the project.
- Type:
path
- Required:
false
buildο
Configuration for the documentation build process. This allows you to specify the base Read the Docs image used to build the documentation, and control the versions of several tools: Python, Node.js, Rust, and Go.
version: 2
build:
os: ubuntu-22.04
tools:
python: "3.11"
nodejs: "18"
rust: "1.64"
golang: "1.19"
build.osο
The Docker image used for building the docs. Image names refer to the operating system Read the Docs uses to build them.
Note
Arbitrary Docker images are not supported.
- Type:
string
- Options:
ubuntu-20.04
,ubuntu-22.04
- Required:
true
build.toolsο
Version specifiers for each tool. It must contain at least one tool.
- Type:
dict
- Options:
python
,nodejs
,rust
,golang
- Required:
true
build.tools.pythonο
Python version to use. You can use several interpreters and versions, from CPython, Miniconda, and Mamba.
Note
If you use Miniconda3 or Mambaforge, you can select the Python version
using the environment.yml
file. See our How to use Conda as your Python environment guide
for more information.
- Type:
string
- Options:
2.7
3
(last stable CPython version)3.6
3.7
3.8
3.9
3.10
3.11
miniconda3-4.7
mambaforge-4.10
mambaforge-22.9
build.tools.nodejsο
Node.js version to use.
- Type:
string
- Options:
14
16
18
19
20
build.tools.rustο
Rust version to use.
- Type:
string
- Options:
1.55
1.61
1.64
1.70
build.tools.golangο
Go version to use.
- Type:
string
- Options:
1.17
1.18
1.19
1.20
build.apt_packagesο
List of APT packages to install. Our build servers run Ubuntu 18.04, with the default set of package repositories installed. We donβt currently support PPAβs or other custom repositories.
- Type:
list
- Default:
[]
version: 2
build:
apt_packages:
- libclang
- cmake
Note
When possible avoid installing Python packages using apt (python3-numpy
for example),
use pip or conda instead.
Warning
Currently, itβs not possible to use this option when using build.commands.
build.jobsο
Commands to be run before or after a Read the Docs pre-defined build jobs. This allows you to run custom commands at a particular moment in the build process. See Build process customization for more details.
version: 2
build:
os: ubuntu-22.04
tools:
python: "3.11"
jobs:
pre_create_environment:
- echo "Command run at 'pre_create_environment' step"
post_build:
- echo "Command run at 'post_build' step"
- echo `date`
Note
Each key under build.jobs
must be a list of strings.
build.os
and build.tools
are also required to use build.jobs
.
- Type:
dict
- Allowed keys:
post_checkout
,pre_system_dependencies
,post_system_dependencies
,pre_create_environment
,post_create_environment
,pre_install
,post_install
,pre_build
,post_build
- Required:
false
- Default:
{}
build.commandsο
Specify a list of commands that Read the Docs will run on the build process.
When build.commands
is used, none of the pre-defined build jobs will be executed.
(see Build process customization for more details).
This allows you to run custom commands and control the build process completely.
The _readthedocs/html
directory (relative to the checkoutβs path) will be uploaded and hosted by Read the Docs.
Warning
This feature is in a beta phase and could suffer incompatible changes or even removed completely in the near feature. It does not yet support some of the Read the Docsβ integrations like the flyout menu, search and ads. However, integrating all of them is part of the plan. Use it under your own responsibility.
version: 2
build:
os: ubuntu-22.04
tools:
python: "3.11"
commands:
- pip install pelican
- pelican --settings docs/pelicanconf.py --output _readthedocs/html/ docs/
Note
build.os
and build.tools
are also required when using build.commands
.
- Type:
list
- Required:
false
- Default:
[]
sphinxο
Configuration for Sphinx documentation (this is the default documentation type).
version: 2
sphinx:
builder: html
configuration: conf.py
fail_on_warning: true
Note
If you want to pin Sphinx to a specific version,
use a requirements.txt
or environment.yml
file
(see Requirements file and conda.environment).
If you are using a metadata file to describe code dependencies
like setup.py
, pyproject.toml
, or similar,
you can use the extra_requirements
option
(see Packages).
This also allows you to override the default pinning done by Read the Docs
if your project was created before October 2020.
sphinx.builderο
The builder type for the Sphinx documentation.
- Type:
string
- Options:
html
,dirhtml
,singlehtml
- Default:
html
Note
The htmldir
builder option was renamed to dirhtml
to use the same name as sphinx.
Configurations using the old name will continue working.
sphinx.configurationο
The path to the conf.py
file, relative to the root of the project.
- Type:
path
- Default:
null
If the value is null
,
Read the Docs will try to find a conf.py
file in your project.
sphinx.fail_on_warningο
Turn warnings into errors
(-W
and --keep-going
options).
This means the build fails if there is a warning and exits with exit status 1.
- Type:
bool
- Default:
false
mkdocsο
Configuration for MkDocs documentation.
version: 2
mkdocs:
configuration: mkdocs.yml
fail_on_warning: false
Note
If you want to pin MkDocs to a specific version,
use a requirements.txt
or environment.yml
file
(see Requirements file and conda.environment).
If you are using a metadata file to describe code dependencies
like setup.py
, pyproject.toml
, or similar,
you can use the extra_requirements
option
(see Packages).
This also allows you to override the default pinning done by Read the Docs
if your project was created before March 2021.
mkdocs.configurationο
The path to the mkdocs.yml
file, relative to the root of the project.
- Type:
path
- Default:
null
If the value is null
,
Read the Docs will try to find a mkdocs.yml
file in your project.
mkdocs.fail_on_warningο
Turn warnings into errors. This means that the build stops at the first warning and exits with exit status 1.
- Type:
bool
- Default:
false
submodulesο
VCS submodules configuration.
Note
Only Git is supported at the moment.
Warning
You canβt use include
and exclude
settings for submodules at the same time.
version: 2
submodules:
include:
- one
- two
recursive: true
submodules.includeο
List of submodules to be included.
- Type:
list
- Default:
[]
Note
You can use the all
keyword to include all submodules.
version: 2
submodules:
include: all
submodules.excludeο
List of submodules to be excluded.
- Type:
list
- Default:
[]
Note
You can use the all
keyword to exclude all submodules.
This is the same as include: []
.
version: 2
submodules:
exclude: all
submodules.recursiveο
Do a recursive clone of the submodules.
- Type:
bool
- Default:
false
Note
This is ignored if there arenβt submodules to clone.
searchο
Settings for more control over Server side search.
version: 2
search:
ranking:
api/v1/*: -1
api/v2/*: 4
ignore:
- 404.html
search.rankingο
Set a custom search rank over pages matching a pattern.
- Type:
map
of patterns to ranks- Default:
{}
Patterns are matched against the final html pages produced by the build
(you should try to match index.html
, not docs/index.rst
).
Patterns can include some special characters:
*
matches everything?
matches any single character[seq]
matches any character inseq
The rank can be an integer number between -10 and 10 (inclusive). Pages with a rank closer to -10 will appear further down the list of results, and pages with a rank closer to 10 will appear higher in the list of results. Note that 0 means normal rank, not no rank.
If you are looking to completely ignore a page, check search.ignore.
version: 2
search:
ranking:
# Match a single file
tutorial.html: 2
# Match all files under the api/v1 directory
api/v1/*: -5
# Match all files that end with tutorial.html
'*/tutorial.html': 3
Note
The final rank will be the last pattern to match the page.
Tip
Is better to decrease the rank of pages you want to deprecate, rather than increasing the rank of the other pages.
search.ignoreο
List of paths to ignore and exclude from the search index. Paths matched will not be included in search results.
- Type:
list
of patterns- Default:
['search.html', 'search/index.html', '404.html', '404/index.html']
Patterns are matched against the relative path of html files produced by the build
(you should try to match index.html
, not docs/index.rst
).
Patterns can include some special characters:
*
matches everything?
matches any single character[seq]
matches any character inseq
version: 2
search:
ignore:
# Ignore a single file in the root of the output directory
- 404.html
# Ignore all files under the search/ directory
- search/*
# Ignore all files named ref.html nested inside one or more sub-folders
- '*/ref.html'
version: 2
search:
ignore:
# Custom files to ignore
- file.html
- api/v1/*
# Defaults
- search.html
- search/index.html
- 404.html
- 404/index.html'
Note
Since Read the Docs fallbacks to the original search engine when no results are found, you may still see search results from ignored pages.
Schemaο
You can see the complete schema here. This schema is available at Schema Store, use it with your favorite editor for validation and autocompletion.
Legacy build
specificationο
The legacy build
specification used a different set of Docker images,
and only allowed you to specify the Python version.
It remains supported for backwards compatibility reasons.
Check out the build above
for an alternative method that is more flexible.
version: 2
build:
image: latest
apt_packages:
- libclang
- cmake
python:
version: "3.7"
The legacy build
specification also supports
the apt_packages
key described above.
Warning
When using the new specification,
the build.image
and python.version
options cannot be used.
Doing so will error the build.
build (legacy)ο
build.image (legacy)ο
The Docker image used for building the docs.
- Type:
string
- Options:
stable
,latest
- Default:
latest
Each image support different Python versions and has different packages installed, as defined here:
python.version (legacy)ο
The Python version (this depends on build.image (legacy)).
- Type:
string
- Default:
3
Note
Make sure to use quotes ("
) to make it a string.
We previously supported using numbers here,
but that approach is deprecated.
Warning
If you are using a Conda environment to manage the build, this setting will not have any effect, as the Python version is managed by Conda.
Migrating from v1ο
Changesο
The version setting is required. See version.
The default value of the formats setting has changed to
[]
and it doesnβt include the values from the web interface.The top setting
requirements_file
was moved topython.install
and we donβt try to find a requirements file if the option isnβt present. See Requirements file.The setting
conda.file
was renamed toconda.environment
. See conda.environment.The
build.image
setting has been replaced bybuild.os
. See build.os. Alternatively, you can use the legacybuild.image
that now has only two options:latest
(default) andstable
.The settings
python.setup_py_install
andpython.pip_install
were replaced bypython.install
. And now it accepts a path to the package. See Packages.The setting
python.use_system_site_packages
was renamed topython.system_packages
. See python.system_packages.The build will fail if there are invalid keys (strict mode).
Warning
Some values from the web interface are no longer respected, please see Migrating from the web interface if you have settings there.
New settingsο
Migrating from the web interfaceο
This should be pretty straightforward, just go to the Admin > Advanced settings, and find their respective setting in here.
Not all settings in the web interface are per version, but are per project. These settings arenβt supported via the configuration file.
Name
Repository URL
Repository type
Language
Programming language
Project homepage
Tags
Single version
Default branch
Default version
Show versions warning
Privacy level
Analytics code
Custom paths for .readthedocs.yamlο
In order to support monorepo layouts,
itβs possible to configure the path to where your .readthedocs.yaml
is found.
Using this configuration makes it possible to create several Read the Docs projects pointing at the same Git repository. This is recommended for monorepo layouts that host several documentation projects in the same repository.
See also
- How to use a .readthedocs.yaml file in a sub-folder
This guide explains how to use the configuration.
Previous version: v1ο
Version 1 is deprecated and using it is discouraged, view its reference here Configuration file v1 (Deprecated).