Skip to content

Sphinx

Sphinx ↗︎ is a documentation generator written in Python. In this guide, you will create a new Sphinx project and deploy it using Cloudflare Pages.

Prerequisites

Create a Sphinx project

  1. Create a new project directory, set up a Python virtual environment, and install Sphinx:
mkdir my-sphinx-project
cd my-sphinx-project
python3 -m venv .venv
source .venv/bin/activate
pip install sphinx
  1. Record your dependencies in a requirements.txt file so Cloudflare Pages automatically installs Sphinx during builds:
echo "sphinx" > requirements.txt
  1. Run sphinx-quickstart to scaffold your documentation site:
sphinx-quickstart

When prompted, answer the setup questions:

Separate source and build directories (y/n) [n]: y
Project name: <Your project name>
Author name(s): <Your author name>
Project release []: <Leave blank or provide a version>
Project language [en]: <Leave blank for en or provide a language code>
  1. Add a .gitignore file so your local virtual environment and build output are not committed to Git:
.gitignoretxt
.venv/
build/

This creates a project structure with requirements.txt, Makefile, and a source/ directory containing conf.py and index.rst. For more details on authoring documentation with Sphinx, refer to the Sphinx documentation ↗︎.

Before you continue

This guide assumes you already have a fundamental understanding of Git ↗︎. If you are new to Git, refer to the GitHub guide to Git ↗︎ on how to set up Git on your local machine.

If you clone with SSH, you must generate SSH keys ↗︎ on each computer you use to push or pull from GitHub.

Refer to the GitHub documentation ↗︎ and Git documentation ↗︎ for more information.

Create a GitHub repository

Create a new GitHub repository by visiting repo.new ↗︎. After creating a new repository, go to your newly created project directory to prepare and push your local application to GitHub by running the following commands in your terminal:

git init
git remote add origin https://github.com/<your-gh-username>/<repository-name>
git add .
git commit -m "Initial commit"
git branch -M main
git push -u origin main

Deploy with Cloudflare Pages

To deploy your site to Pages:

  1. In the Cloudflare dashboard, go to the Workers & Pages page.

    Go to Workers & Pages ↗
  2. Select Create application (if prompted).

  3. At the bottom of the page, select the link to continue to Cloudflare Pages (Get started or Continue to Pages).

  4. Select Import an existing Git repository.

  5. Select the new GitHub repository that you created and then select Begin setup.

  6. In the Set up builds and deployments section, provide the following information:

Configuration option Value
Production branch main
Build command make html
Build directory build/html

Cloudflare Pages detects requirements.txt and installs your Python dependencies before running make html. If you need a specific Python version rather than the build image default, set the PYTHON_VERSION environment variable as described in Override default versions.

After deploying your site, you will receive a unique subdomain for your project on *.pages.dev. Every time you commit new code to your Sphinx site, Cloudflare Pages automatically rebuilds your project and deploys it.

You will also get access to preview deployments on new pull requests, so you can preview how changes look to your site before deploying them to production.

Learn more

By completing this guide, you have deployed your Sphinx site to Cloudflare Pages. For new projects, refer to Cloudflare Workers framework guides, or refer to the Pages framework guides for other Pages setups.

Was this helpful?