Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Construct RestructuredText markup and directives from Python Code.

Project description

Documentation Status!--None.svg?style=social

Welcome to rstobj Documentation

rstobj is a library that construct Restructured Text markup or directives from Python Code. rstobj is based on jinja2.

The idea behind rstobj:

RestructuredText is super powerful, way more powerful than markdown. But have you ever think of customize YOUR OWN markup or directive and do some magic?

Sphinx Doc is the ultimate doc build tool. With rstobj, you can easily create your own markup / directive, and hide complex workflow behind a single markup / directive, then use it when you need it. Here’s some ideas:

  1. Use .. include-all-image:: to automatically scan image file under a directory, create .. image:: directive and organize everything in a table.
  2. Separate comment and value of the config file, automatically create an document for a config file.

I have a Blog Post to share how to create a sphinx doc extension in 50 lines and customize your own directive (Sorry, its written in Chinese).


import rstobj # or from rstobj import *

header = rstobj.markup.Header(title="Section1", header_level=1, auto_label=True)
rst_header = header.render()

ltable = rstobj.directives.ListTable(
    data=[["id", "name"], [1, "Alice"], [2, "Bob"]],
rst = ltable.render()


.. _section1:


.. list-table:: Users
    :header-rows: 1
    :stub-columns: 0

    * - id
      - name
    * - 1
      - Alice
    * - 2
      - Bob

I recommend to use this in your jinja2 template, content of outut.rst:

{{ header.render() }}
{{ ltable.render() }}

And use rstobj with sphinx-jinja library in sphinx doc project.

Supported directives:

  • .. image::
  • .. list-table::
  • .. contents::
  • .. code-block::
  • .. include::

Supported markup:

  • Header:

    .. _ref-label:
  • URL: `Text <Target>`_

  • Reference: :ref:`Text <Target>`

If you need more features, please submit an issue to


rstobj is released on PyPI, so all you need is:

$ pip install rstobj

To upgrade to latest version:

$ pip install --upgrade rstobj

Project details

Download files

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

Files for rstobj, version 0.0.7
Filename, size File type Python version Upload date Hashes
Filename, size rstobj-0.0.7-py2.py3-none-any.whl (88.1 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size rstobj-0.0.7.tar.gz (39.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page