Skip to main content

Build Status PyPI

sphinx-section-include

Include selected sections of reStructuredText documents in Sphinx projects. The extension copies parsed nodes, retaining nested headings, code blocks, source locations, and references. It also provides a typed Python API for extensions that select and transform sections themselves.

Installation

$ pip install sphinx-section-include

Enable the extension in conf.py:

"""Enable section inclusion in this Sphinx project."""

extensions = ["sphinx_section_include"]

Including a section

.. include-section:: manual.rst
   :section: Getting started / Configuration
   :include-heading:
   :exclude-sections: Advanced configuration

:section: is required. It accepts an exact heading, a slash-separated heading path, or an RST label prefixed by #. Literal heading matches take precedence, so headings containing slashes remain selectable. Missing or ambiguous selections fail with a build diagnostic.

:include-heading: includes the selected section’s heading. Without it, only the section’s contents and nested sections are included. :exclude-sections: accepts one descendant selector per line.

Paths are relative to the including document. A leading / selects a path relative to the Sphinx source directory. Sources must be existing .rst files within that directory. Self-inclusion and circular section includes are rejected.

Source documents are parsed with registered directives, substitutions, rst_prolog, and rst_epilog. Dependencies from nested includes are tracked for incremental builds. Internal anchors are namespaced so the same section can appear more than once. Links outside the excerpt retain their source document, and local image paths retain their source directory. Standard Sphinx reference resolution and builder URI conventions apply.

Python API

find_sections(document=..., selector=...) returns all matching sections. select_section(document=..., selector=...) requires exactly one match and raises ValueError otherwise.

copy_section(section=..., include_heading=True, exclude_sections=()) returns independent copied nodes without modifying the source tree. Exclusions are resolved section nodes and must be descendants of the selection. This function preserves document structure and does not apply rendering policy.

For Sphinx directive authors, read_document(directive=..., source=..., docname=None) parses an RST source and records its dependencies. The default parsing context is the source document. A docname override supports extensions whose embedded content uses the caller’s context. Temporary context is restored after parsing. resolve_source(directive=..., source=...) validates and resolves the path. Both helpers require an active Sphinx build, which supplies the source directory and directive context.

This library was extracted from sphinx-hackerrank. HackerRank layouts, language filtering, and HTML export remain in that extension.

Development

See CONTRIBUTING.rst for local checks and release steps. The sample project exercises section inclusion without HackerRank dependencies.

License

MIT. See LICENSE.

Metadata

Release files for sphinx-section-include 2026.11.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinx-section-include 2026.11.1.1
File Size Uploaded Provenance Actions
sphinx_section_include-2026.11.1.1.tar.gz 29.6 kB With provenance Details for sphinx_section_include-2026.11.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sphinx-section-include 2026.11.1.1
File Interpreter ABI Platform Actions
sphinx_section_include-2026.11.1.1-py3-none-any.whl Python 3 none any Details for sphinx_section_include-2026.11.1.1-py3-none-any.whl

Total release size: 39.4 kB

Release files / sphinx_section_include-2026.11.1.1.tar.gz

Download URL sphinx_section_include-2026.11.1.1.tar.gz
Size 29.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ebef7e04766d075751b8d45038a027f1e2a07982779031129c6370a32c0b883c
BLAKE2b-256 checksum
How to use checksums
c68347290ef65e1033f09374d0675cf116652375e49acd405472d53a944603f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Release files / sphinx_section_include-2026.11.1.1-py3-none-any.whl

Download URL sphinx_section_include-2026.11.1.1-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6eb1f54b5ff9a709a82f116f9446006ecdfe8dc06ee4995fdd9ec4388de2ecec
BLAKE2b-256 checksum
How to use checksums
e4541f3dc0568b5ab27ded1176cc7c98ba34523e8b334e7e1a87aeb9d41d3348
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Security for sphinx-section-include 2026.11.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sphinx_section_include-2026.11.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page