Skip to main content

Static documentation generator for Protobuf and gRPC

Project description

Sabledocs

CircleCI PyPi Python versions

A simple static documentation generator for Protobuf and gRPC contracts.

Demo: You can check out this demo showing the generated documentation for some of the Google Cloud SDK contracts.

How to use

Generate the proto descriptor

In order to build the documentation, you need to generate a binary descriptor from your Proto contracts using protoc. If you don't have it yet, the protoc CLI can be installed by downloading the release from the official protobuf repository.

For example in the folder where your proto files are located, you can execute the following command.

protoc *.proto -o descriptor.pb --include_source_info

(It's important to use the --include_source_info flag, otherwise the comments will not be included in the generated documentation.)

The generated descriptor.pb file will be the input needed to build the documentation site.

Build the documentation

Install the sabledocs package. It requires Python (version 3.11 or higher) to be installed.

pip install sabledocs

In the same folder where the generated descriptor.pb file is located, execute the command.

sabledocs

The documentation will be generated into a folder sabledocs_output, its main page can be opened with index.html.

Customization

For further customization, create a sabledocs.toml file in the folder where the Protobuf descriptor file is located and from which the sabledocs CLI is executed. You can customize the following options. Any omitted field will use its default value.

# Configures the main title of the documentation site.
# Default value: "Protobuf module documentation"
module-title = "My Awesome Module"

# Specifies the name of the Protobuf descriptor file.
# Default value: "descriptor.pb"
input-descriptor-file = "myawesomemodule.pb"

# Specifies the file which contains the content to display on the main page above the package list.
# Default value: ""
main-page-content-file = "intro.md"

# The output folder to which the documentation is generated.
# Default value: "sabledocs_output"
output-dir = "docs"

# Controls whether the the search functionality is enabled with a prebuilt Lunr index.
# Default value: true
enable-lunr-search = true

# Copyright message displayed in the footer.
# Default value: ""
footer-content = "© 2023 Jane Doe. All rights reserved."

# The following 3 fields configure the source control repository of the project.
# They are used to generate deeplinks for the members of the Proto model pointing to the original source
# code. By default these fields are not configured, and source code links are not included in the docs.
# The repository-type field supports two possible values, "github" and "bitbucket".
# The fields repository-url and repository-branch should be configured to point to the correct repository.
# repository-dir should be set only if the root of your Protobuf module is in a specific directory inside your repository.
repository-type = "github"
repository-url = "https://github.com/janedoe/myawesomeproject"
repository-branch = "main"
repository-dir = "proto"

# In each comment, ignore everything that comes after (until end of the comment) one of the keywords.
# Default value: []
ignore-comments-after = ["@exclude"]
# In each comment, ignore all lines that contain at least one keyword from the following list.
# Default value: []
ignore-comment-lines-containing = ["buf:lint"]

# Packages can be hidden from the generated documentation by adding them to the hidden-packages
# collection. In the templates, the field non_hidden_packages can be used to access the packages which are
# not listed in hidden-packages. (And the packages field returns all packages.)
# Default value: []
hidden-packages = ["google.protobuf"]

# By default, packages and members in a package are ordered alphabetically.
# By setting the member-ordering option to "preserve", the original order present in the Protobuf
# definitions will be preserved.
# When using the "preserve" option and having multiple proto input files, the order of the members will
# depend not just on the physical order in the Protobuf files, but also on the order in which the files
# were listed in the input when `protoc` was executed.
# Default value: ""
member-ordering = "preserve"

Main page content

Custom introduction content can be specified in a separate file, which can be displayed above the packages list on the main page of the documentation.
Then the name of the file has to be specified in the main-page-content-file configuration setting.

main-page-content-file = "intro.md"

See the example on the main page of the demo site.

Using with Docker

For convenient usage in CI builds and other scenarios where a Docker image is preferable, the image markvincze/sabledocs can be used, which has both the protoc CLI, and sabledocs preinstalled.

Markdown support

Markdown can be used both in the main content page, and also in the Protobuf comments.
Code blocks can be defined both with indentation, and with the ``` fence.

It's important that if we use fenced code blocks in the Protobuf comments, there must be no spaces between the foreslashes at the start of the line, and the backticks.
For example this code block will not work.

// These are the comments for SearchRequest
//
// ```
// namespace Test
// {
//     public class Foo {
//         public string Bar { get; set; }
//     }
// }
// ```
message SearchRequest {
  string query = 1;
  int32 page_number = 2;
  int32 results_per_page = 3;
}

The spaces between the foreslash and the backtick have to be removed, then the code blocks will correctly appear.

// These are the comments for SearchRequest
//
//```
//namespace Test
//{
//    public class Foo {
//        public string Bar { get; set; }
//    }
//}
//```
message SearchRequest {
  string query = 1;
  int32 page_number = 2;
  int32 results_per_page = 3;
}

For maintainers

Build the Python package:

python -m build

Publish with twine:

python -m twine upload --repository testpypi dist/*

Install from the local folder:

pip install .

Build the library and the sample documentation, from the sample folder:

# PowerShell
npm run css-build; pip install ..; sabledocs; .\output\index.html

# Bash
npm run css-build && pip install .. && sabledocs && .\output\index.html

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sabledocs-0.11.527.dev0.tar.gz (51.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sabledocs-0.11.527.dev0-py3-none-any.whl (52.3 kB view details)

Uploaded Python 3

File details

Details for the file sabledocs-0.11.527.dev0.tar.gz.

File metadata

  • Download URL: sabledocs-0.11.527.dev0.tar.gz
  • Upload date:
  • Size: 51.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for sabledocs-0.11.527.dev0.tar.gz
Algorithm Hash digest
SHA256 d94c21da776742421f17f4870aa856d6b849a3c9121c9d333ae8d62abed6507c
MD5 722cd28f662a84ba49b3905ecc8fbd29
BLAKE2b-256 0fdb842aa31dbbe651e1788a3be794920796c707f5e9056714e39212f28436d1

See more details on using hashes here.

File details

Details for the file sabledocs-0.11.527.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for sabledocs-0.11.527.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 278d295c8834669266a7e4b5d1081523683740365126cdd31c73c7be7418a1ca
MD5 55cf2adf5f29cc35d169feb3be53606e
BLAKE2b-256 2f65f6560313c170e35ee424e4337fdf73939396531b563f4effec46d1a28375

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page