Convert IPYNB to RST
Max file size 100mb.
IPYNB vs RST Format Comparison
| Aspect | IPYNB (Source Format) | RST (Target Format) |
|---|---|---|
| Format Overview |
IPYNB
Jupyter Notebook
Interactive computational document used in data science, machine learning, and scientific research. JSON-based format containing code cells, markdown cells, and their outputs. The standard environment for exploratory data analysis and reproducible research. Data Science Standard Interactive Computing |
RST
reStructuredText
Plain text markup language designed for technical documentation. Part of the Docutils project and the standard markup for Python documentation via Sphinx. Offers more features than Markdown including directives, roles, cross-references, and extensibility. Powers Read the Docs and most Python project documentation. Python Docs Standard Sphinx Ecosystem |
| Technical Specifications |
Structure: JSON document with notebook schema
Encoding: UTF-8 Format: JSON with cells, metadata, kernel info MIME Type: application/x-ipynb+json Extensions: .ipynb |
Structure: Plain text with underline-based headings
Encoding: UTF-8 Format: Docutils markup language MIME Type: text/x-rst Extensions: .rst, .rest |
| Syntax Examples |
IPYNB uses JSON cell structure: {
"cell_type": "code",
"source": ["import pandas as pd\n",
"df = pd.read_csv('data.csv')"],
"outputs": [{"output_type": "stream",
"text": [" col1 col2\n"]}]
}
|
RST uses underline-based headings and directives: Chapter Title
=============
Section Title
-------------
*italic text*, **bold text**
.. code-block:: python
print("Hello, world!")
.. note::
This is a note admonition.
|
| Content Support |
|
|
| Advantages |
|
|
| Disadvantages |
|
|
| Common Uses |
|
|
| Best For |
|
|
| Version History |
Introduced: 2014 (Project Jupyter)
Current Version: nbformat 4.5 Status: Active, widely adopted Evolution: From IPython Notebook to Jupyter ecosystem |
Introduced: 2001 by David Goodger
Current Version: Docutils 0.21 Status: Active, Python docs standard Evolution: Part of Docutils project, adopted by Sphinx |
| Software Support |
Jupyter: Notebook, Lab, Hub
IDEs: VS Code, PyCharm, DataSpell Cloud: Google Colab, AWS SageMaker, Azure ML Other: nbviewer, GitHub rendering |
Build: Sphinx, Docutils, rst2pdf
Hosting: Read the Docs, GitHub Pages Editors: VS Code (RST extension), PyCharm Converters: Pandoc, nbsphinx, nbconvert |
Why Convert IPYNB to RST?
Converting Jupyter Notebooks to reStructuredText (RST) is essential for integrating data science work into Python project documentation built with Sphinx. RST is the standard markup language for the Python ecosystem, powering documentation for projects like NumPy, pandas, scikit-learn, and thousands of other libraries hosted on Read the Docs.
When you convert a notebook to RST, code cells become .. code-block:: python directives with syntax highlighting, markdown text becomes properly structured RST with headings, lists, and emphasis, and the resulting file integrates seamlessly into a Sphinx documentation project. This allows your analysis tutorials, API usage examples, and research documentation to become part of your project's official docs.
RST offers capabilities beyond Markdown that are particularly valuable for technical documentation: cross-references between documents (:ref: and :doc: roles), automatic API documentation (autodoc directive), admonitions (.. note::, .. warning::), custom directives, and the toctree for organizing multi-page documentation. These features make RST the superior choice for comprehensive project documentation.
The Sphinx ecosystem also includes nbsphinx, an extension that can render IPYNB files directly in Sphinx builds. However, converting to RST gives you more control over the output formatting and allows you to edit the documentation without requiring Jupyter. The RST format is plain text, making it easy to review, edit, and version control.
Key Benefits of Converting IPYNB to RST:
- Sphinx Integration: Include notebooks in Sphinx documentation projects
- Read the Docs: Publish notebook content on Read the Docs
- Cross-References: Link to other docs, API references, and glossary terms
- Code Blocks: Syntax-highlighted code with .. code-block:: directive
- Directives: Use admonitions, figures, tables, and custom extensions
- Version Control: Plain text RST diffs cleanly in Git
- Multi-Output: Build HTML, PDF, EPUB from single RST source
Practical Examples
Example 1: Sphinx Documentation from Tutorial Notebook
Input IPYNB file (notebook.ipynb):
# Markdown Cell:
# Getting Started with MyLibrary
## Installation
Install via pip:
# Code Cell:
# pip install mylibrary
from mylibrary import DataProcessor
dp = DataProcessor(format='csv')
result = dp.process('data.csv')
print(f"Processed {result.row_count} rows")
print(f"Columns: {result.columns}")
# Output:
Processed 15000 rows
Columns: ['id', 'name', 'value', 'timestamp']
Output RST file (notebook.rst):
Getting Started with MyLibrary
==============================
Installation
------------
Install via pip:
.. code-block:: python
# pip install mylibrary
from mylibrary import DataProcessor
dp = DataProcessor(format='csv')
result = dp.process('data.csv')
print(f"Processed {result.row_count} rows")
print(f"Columns: {result.columns}")
Output::
Processed 15000 rows
Columns: ['id', 'name', 'value', 'timestamp']
Example 2: API Reference from Analysis Notebook
Input IPYNB file (analysis.ipynb):
# Markdown Cell:
# API Reference: Prediction Module
## predict() Method
Returns prediction results for input data.
# Code Cell:
from mylib.predict import PredictionEngine
engine = PredictionEngine(model='v2.1')
prediction = engine.predict(
features=[0.5, 1.2, -0.3, 0.8],
threshold=0.7
)
print(f"Label: {prediction.label}")
print(f"Confidence: {prediction.confidence:.3f}")
print(f"Latency: {prediction.latency_ms:.1f}ms")
# Output:
Label: positive
Confidence: 0.892
Latency: 12.4ms
Output RST file (analysis.rst):
API Reference: Prediction Module
=================================
predict() Method
----------------
Returns prediction results for input data.
.. code-block:: python
from mylib.predict import PredictionEngine
engine = PredictionEngine(model='v2.1')
prediction = engine.predict(
features=[0.5, 1.2, -0.3, 0.8],
threshold=0.7
)
print(f"Label: {prediction.label}")
print(f"Confidence: {prediction.confidence:.3f}")
print(f"Latency: {prediction.latency_ms:.1f}ms")
Output::
Label: positive
Confidence: 0.892
Latency: 12.4ms
.. note::
The ``predict()`` method requires a trained model.
Example 3: Tutorial with Step-by-Step Guide
Input IPYNB file (research.ipynb):
# Markdown Cell:
# Data Cleaning Tutorial
## Step 1: Load and Inspect Data
Start by loading the raw dataset and checking for issues.
# Code Cell:
import pandas as pd
df = pd.read_csv('raw_survey.csv')
print(f"Shape: {df.shape}")
print(f"Missing values:\n{df.isnull().sum()}")
# Output:
Shape: (5000, 8)
Missing values:
age 45
income 123
city 0
score 67
# Markdown Cell:
## Step 2: Handle Missing Values
We use median imputation for numerical columns.
Output RST file (research.rst):
Data Cleaning Tutorial
======================
Step 1: Load and Inspect Data
-----------------------------
Start by loading the raw dataset and checking for issues.
.. code-block:: python
import pandas as pd
df = pd.read_csv('raw_survey.csv')
print(f"Shape: {df.shape}")
print(f"Missing values:\n{df.isnull().sum()}")
Output::
Shape: (5000, 8)
Missing values:
age 45
income 123
city 0
score 67
Step 2: Handle Missing Values
------------------------------
We use median imputation for numerical columns.
Frequently Asked Questions (FAQ)
Q: How are code cells converted in RST?
A: Code cells become RST code-block directives: .. code-block:: python followed by the indented code. Sphinx renders these with syntax highlighting, line numbers, and optional emphasis on specific lines.
Q: Can I include the RST file in my Sphinx project?
A: Yes! Place the converted .rst file in your Sphinx source directory and add it to a toctree directive in your index.rst. Run sphinx-build and the notebook content will appear in your documentation alongside other pages.
Q: How does RST compare to Markdown for documentation?
A: RST is more powerful than Markdown for technical documentation. It supports directives, roles, cross-references, admonitions, and extensibility through Sphinx. Markdown is simpler to write but lacks these features. For Python project docs, RST is the established standard.
Q: Will images from the notebook be included?
A: Image outputs are saved as separate files and referenced using the .. image:: or .. figure:: directive in RST. The images need to be placed in your Sphinx project's static directory or a relative path for them to render correctly in the built documentation.
Q: What is the advantage over nbsphinx?
A: nbsphinx renders IPYNB files directly in Sphinx, which is convenient. Converting to RST gives you more control: you can edit the text, add RST-specific directives, cross-reference other documents, and maintain the content without needing Jupyter. RST is also lighter and easier to review in pull requests.
Q: Does RST support math equations?
A: Yes! RST and Sphinx support LaTeX math via the .. math:: directive for display equations and :math:`E=mc^2` role for inline math. Mathematical notation from notebooks translates directly to RST math syntax.
Q: Can I publish the RST on Read the Docs?
A: Absolutely! Read the Docs builds Sphinx documentation from RST source files. Connect your repository to Read the Docs, include the RST file in your Sphinx project, and your notebook content will be automatically built and published online.
Q: Is RST hard to learn?
A: RST has a steeper learning curve than Markdown due to its more complex syntax (underlined headings, directive blocks, roles). However, the converted file provides a good template to learn from. For basic edits, the syntax is intuitive: headings use underlines, bold is **bold**, and code blocks use indentation.