Writing documentation#

The Bokeh documentation is an important resource for the entire Bokeh community. It helps guide new users, and it is the definitive reference for seasoned users and developers. That is why all contributions to Bokeh must contain adequate documentation. It is also why we have set standards to ensure that Bokeh’s documentation remains easily accessible and up to date.

Just like Bokeh itself, the documentation is a community effort. And just like Bokeh, the documentation is being adapted and improved all the time. In fact, helping with the documentation is one of the most valuable ways to contribute to Bokeh. It’s also a good way to get started and introduce yourself as a new contributor.

This section describes Bokeh’s documentation style guidelines for contributing to the documentation. This section also includes details on how to build and edit the documentation in your local development environment.

Where to get started#

An easy way to start contributing to Bokeh’s docs is to submit pull requests for any typos or other small errors you might find in Bokeh’s documentation. This is always appreciated!

In addition to quick fixes, check the list of open documentation issues on GitHub. This list contains several projects as a starting point.

Documentation style guidelines#

Bokeh’s documentation uses the Google developer documentation style guide.

If your contribution includes substantial edits or additions, please familiarize yourself with Google’s style guide. A simple way to get started is using Google’s free technical writing courses.

Note

You will find that many parts of Bokeh’s documentation do not yet follow these style guidelines. We are currently working on implementing these changes. However, we request that all documentation contributions follow the standards described in this document.

Principles of good style#

Follow these basic guidelines in all your writing for Bokeh:

  • Be aware of sentence length. Try to avoid sentences that require more than two commas. Consider breaking up longer sentences. You could also use bulleted or numbered lists instead.

  • Avoid jargon or uncommon words and phrases. Keep in mind that many users of Bokeh don’t use English as their primary language.

  • Use active voice instead of passive voice whenever possible.

  • Address the reader in the second person (‘you’). Avoid using the first person (‘we’) or the third person (‘the user’).

  • Use American English spelling and grammar (refer to Merriam-Webster for consistent spelling).

  • Use sentence case for headlines (capitalize words like in a regular sentence, but do not use any punctuation at the end).

  • Use serial commas, also known as Oxford Commas.

  • Write in a way that is inclusive and accessible.

  • Use a spell checker in your development environment.

Refer to the Google developer documentation style guide for more detailed information.

Commonly used terms#

These are some commonly used terms and phrases and their spellings used throughout the narrative documentation:

Term

Details

Bokeh, BokehJS

Always capitalize Bokeh and BokehJS

JavaScript

Capitalize both ‘J’ and ‘S’

Jupyter notebook

Capitalize Jupyter, but not notebook

pandas

Don’t capitalize pandas

Python

Always capitalize Python (the language)

For definitions and concepts used throughout Bokeh’s documentation, see the Glossary.

In general, see the word list of the Google developer documentation style guide for reference.

Setting up and building Bokeh’s documentation#

Bokeh uses Sphinx to generate the HTML files displayed at docs.bokeh.org. The documentation is written in reStructuredText (ReST).

HTML is the only output format supported by Bokeh’s documentation. Many pages use dynamic content and rely heavily on JavaScript. Bokeh’s documentation also uses several custom Sphinx extensions.

1. Prepare your environment#

To build the documentation, follow the instructions in Setting up a development environment and make sure you have activated the bkdev environment in your console:

conda activate bkdev

Unless you have just installed or updated your conda environment, you should make sure that all the packages are up to date. Run this command from the root level of your source checkout directory to update bkdev:

conda env update --name bkdev --file <environment file> --prune

using the environment file you originally used to create bkdev.

2. Set environment variable#

In order to build the documentation, you must set the environment variable GOOGLE_API_KEY. The documentation includes some plots with maps, and a valid Google API key is required to build those plots correctly. You have two options:

  • Follow the instructions on the Google developers website to generate a new API key.

  • Use a placeholder value like some_value instead of a valid API key. If you use a placeholder, some map plots in Bokeh’s documentation might not be rendered correctly, but the documentation should otherwise be built correctly. This will only affect your local environment and should have no effect on any changes you might commit to the Bokeh repository.

After activating your conda environment, use the following command to set the environment variable:

conda env config vars set GOOGLE_API_KEY=some_value

Next, you have to reactivate your environment:

conda deactivate
conda activate bkdev

Using conda env config vars set makes this environment variable part of your bkdev environment. Whenever you activate your bkdev environment, conda will now set this environment variable for you.

3. Build Bokeh’s documentation#

You can find all source files for Bokeh’s documentation in the docs/bokeh/ directory of the Bokeh source tree.

cd docs/bokeh/

Sphinx uses the standard Unix make command to control the build process. For Windows users, the sphinx directory includes the file make.bat. Use this Windows batch file instead of make, which is usually only available on Unix-based systems.

When building Bokeh’s documentation, the most common options for make are:

  • clean: remove all previously built documentation output. All output files are generated from scratch on the next build.

  • html: build any HTML output that hasn’t been built yet or needs to be rebuilt to include changes to the documentation source files.

  • serve: start a minimal web server and open a web browser to display the docs. Starting a server is necessary because large portions of the documentation require JavaScript files in the background.

To build the docs, run the following command:

make html
.\make.bat html
make.bat html

After building the docs, run the following command to start a server and display the docs in a web browser:

make serve
.\make.bat serve
make.bat serve

Linux/macOS only: You can combine multiple targets in one command (not supported by make.bat). For example:

make clean html serve

Note

Documents that you build yourself in your local environment load the most recent version of BokehJS from Bokeh’s Content Delivery Network (CDN) by default. If you would like to use your local version of BokehJS instead, set the environment variable BOKEH_DOCS_CDN to local before calling make:

BOKEH_DOCS_CDN=local make clean html serve
$Env:BOKEH_DOCS_CDN = "local"
.\make.bat html
.\make.bat serve
set BOKEH_DOCS_CDN=local
make.bat html
make.bat serve

To speed up the build of your local documentation, you have the option to use an experimental Sphinx feature that distributes the build process over several CPUs and cores. This only works on Linux and macOS (not on Windows). On macOS, this feature only works on Python 3.7. To use this experimental feature, add the option SPHINXOPTS="-j auto" to your build command:

make clean html serve SPHINXOPTS="-j auto"

To learn more about options for the Sphinx build process, see sphinx-build in the Sphinx documentation.

Writing Bokeh’s documentation#

The documentation available at docs.bokeh.org mainly consists of those two elements:

Narrative documentation

This part of the documentation consists of tutorial-like descriptions and instructions for Bokeh. This includes the user guide and contributor guide.

Docstrings and Model help text within the Python source code of Bokeh

This part of the documentation consists of detailed explanations of all Bokeh modules and their properties. These texts are available from the Python interpreter and within most Python development environments. Sphinx also uses those texts to generate the reference guide section of Bokeh’s documentation.

In the file docs/bokeh/source/rst_epilog.txt, you can find many common substitutions used across the narrative documentation as well as docstrings and model help texts. This file is loaded as the epilog.rst environment variable for Bokeh’s Sphinx configuration.

Writing for Bokeh’s narrative documentation#

Bokeh’s narrative documentation consists of these four elements:

  • First steps: first steps guides and installation instructions

  • User guide: descriptions and instructions for using Bokeh

  • Gallery: interactive examples with source code

  • Contributor guide: instructions for contributing to Bokeh

Sphinx generates each of those elements from reStructuredText (.rst) files. To edit any of those elements, open the corresponding ReST source file in the docs/bokeh/source/docs folder of the Bokeh source tree.

For information on how to format text using reStructuredText, see the reStructuredText primer on the Sphinx website or the official reStructuredText website.

For information on writing style, see Bokeh’s documentation style guidelines and the Google developer documentation style guide.

Contributing to Bokeh’s source code documentation#

All functions and methods in Bokeh use docstrings. In addition, Bokeh uses its own system to provide detailed information on individual properties.

Writing docstrings#

To automatically process Python docstrings, Bokeh uses an extension for Sphinx called Napoleon with Napoleon’s Google style. For Napoleon to work correctly, all docstrings you write need to follow the rules in the Google Python Style Guide.

Docstrings generally include these three elements:

  • A short description of what the function does, starting with a verb. For example: “Create and return a new Foo.”

  • Args: list all parameters, if any.

  • Returns: describe the return values of the function, even if the function returns None.

For example:

def foo_function(name, level):
    ''' Creates and returns a new Foo.

    Args:
        name (str) :
            A name for the Foo

        level (int) :
            A level for the Foo to be configured for

    Returns:
        Foo
    '''

Writing models and properties help#

Bokeh’s models use a custom system to provide documentation about individual properties directly in the source code. You can add this kind of text to any property type by including a help argument.

Any string passed as a help argument can be formatted using reStructuredText (ReST).

For example:

class DataRange(Range):
    ''' A base class for all data range types.

    '''

    names = List(String, help="""
    A list of names to query for. If set, only renderers that
    have a matching value for their ``name`` attribute will be used
    for autoranging.
    """)

    renderers = List(Instance(Renderer), help="""
    An explicit list of renderers to autorange against. If unset,
    defaults to all renderers on a plot.
    """)

Note

Release Notes are generally handled by the Bokeh core team as part of Bokeh’s release management. Each release should add a new file under docs/bokeh/source/docs/releases that briefly describes the changes in the release, including any migration notes. The filename should be <version>.rst, for example docs/bokeh/source/docs/releases/0.12.7.rst.The Sphinx build will automatically add this content to the list of all releases.