API

class rst.Document(title)

Returns a Document object.

>>> import rst
>>> doc = rst.Document('Title of the report')
>>> print doc.get_rst()
===================
Title of the report
===================
add_child(node)

Adds a Node object to the Document. Returns True in case of success.

get_rst()

Returns the rst representation of the document in unicode format.

save(path)

Saves the document in the given path.

Parameters:path – Path to save the document.
class rst.Paragraph(text='')

Represents a paragraph

Parameters:text – Text to be present in the paragraph.

. doctest:

>>> import rst
>>> doc = rst.Document('Title of the report')
>>> para = rst.Paragraph('This is a paragraph. A long one.')
>>> doc.add_child(para)
True
>>> print doc.get_rst()
===================
Title of the report
===================

This is a paragraph. A long one.
class rst.Section(title, depth=1)

Represents a Section object.

Parameters:
  • depth – Depth of the section, default is 1
  • text – Title of the section
class rst.Orderedlist

Represents a Ordered List.

>>> import rst
>>> doc = rst.Document('Title of the report')
>>> blt = rst.Orderedlist()
>>> blt.add_item('Fedora')
>>> blt.add_item('Debian')
>>> doc.add_child(blt)
True
>>> print doc.get_rst()
===================
Title of the report
===================

    1. Fedora
    2. Debian
add_item(text)

Adds a new text block in the Bulletlist.

Parameters:text – text to be added in the list, remember it is ordered list.
class rst.Bulletlist

Represents a Bullet List.

>>> import rst
>>> doc = rst.Document('Title of the report')
>>> blt = rst.Bulletlist()
>>> blt.add_item('Fedora')
>>> blt.add_item('Debian')
>>> doc.add_child(blt)
True
>>> print doc.get_rst()
===================
Title of the report
===================

    * Fedora
    * Debian
add_item(text)

Adds a new text block in the Bulletlist.

Parameters:text – text to be added in the list.
class rst.Table(title='', header=None, width=None)

Represents a Table, (will be wriiten in csv-table style)

>>> import rst
>>> doc = rst.Document('Title of the report')
>>> tbl = rst.Table('My friends', ['Name', 'Major Project'])
>>> tbl.add_item(('Ramki', 'Python'))
>>> tbl.add_item(('Pradeepto', 'Kde'))
>>> tbl.add_item(('Nicubunu', 'Fedora'))
>>> doc.add_child(tbl)
True
>>> print doc.get_rst()
===================
Title of the report
===================

.. list-table:: My friends
    :header-rows: 1

    * -  Name
      -  Major Project
    * -  Ramki
      -  Python
    * -  Pradeepto
      -  Kde
    * -  Nicubunu
      -  Fedora
add_item(row)

Adds a new row to the table.

Parameters:row – list of items in the table.

rst is a python module to create reStructuredText documents through code.

Related Topics

This Page

Fork me on GitHub