Skip to main content

docs2md

Automatically parse python docstrings and convert them to markdown!

Installing

pip install and you're good to go!

https://pypi.org/project/docs2md/

Instructions

Simply run the docs2md.py from the command line to interact with the ol' main function.

Note: Program uses f-strings, as such python 3.6 or above is required.

Assuming you'll have a folder structure like so:

.
├── foo.py
├── blahbla
│   ├── __init__.py
│   └── blahblah.py
├── LICENSE
└── README.md

Running python3 -m docs2md.py . will produce the following:

.
├── docs
│   ├── foo.md
│   └── blahbla
│       ├── __init__.md
│       └── blahblah.md
├── foo.py
├── blahbla
│   ├── __init__.py
│   └── blahblah.py
├── LICENSE
└── README.md

The command line arguments are as follow:

positional arguments:
  f                     File or directory to parse!

optional arguments:
  -h, --help            show this help message and exit
  -d [DOCS_DIR], --docs-dir [DOCS_DIR]
                        Documentation directory in which your .md files will
                        be saved. Defaults to [cwd]/docs
  -p, --just-print      Prints the results instead of creating a whole file!
  -s [SAVE_IMPORT], --save-import [SAVE_IMPORT]
                        Whether you'll want to save the imports to another
                        file. Simply place the path of the txt file you'll
                        want to save your imports to
  --test                Runs doctest!

How does this work anyway?

If the input is a directory, doc2md.py will glob all of the files looking for python files and then look for doctrings.

Note: That the program will also include the __init__ and main files, as these can include critical declarations.

The yield_docstrings function will use python's abstract syntax tree module to look for docstrings near the following nodes:

  • FunctionDef:

def foo()...

  • AsyncFunctionDef:

def async foo()...

  • ClassDef:

class foo:...

  • Module:

"""docstrings at the start of a file"""

And automatically generate a simple markdown based on them. Feel free to perouse this repo's docs folder, which was naturally created using this tool.

The program will also look for the following nodes:

  • ImportFrom
  • Import

And mentions the fact that a python file imports from this or that module.

(This is useful to keep track of dependencies, and you can save these separately using the -s flag)

As of the moment of writting, the program does not yet include global variables or data. Although I'm partial to including them in a future update.

Metadata

Release files for docs2md 1.0.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 docs2md 1.0.1
File Size Uploaded
docs2md-1.0.1.tar.gz 6.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for docs2md 1.0.1
File Interpreter ABI Platform
docs2md-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 26.3 kB

Release files / docs2md-1.0.1.tar.gz

Download URL docs2md-1.0.1.tar.gz
Size 6.8 kB
Tags Source
SHA-256 checksum
How to use checksums
42f98cc99a07f5d4101a46c2239e159064fbef59541fa52446f735520908bd7e
BLAKE2b-256 checksum
How to use checksums
49a26423b6efaf173003baf00aa9e9dc8a5b557ac4d2d46b56efbde6247b3ed9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release files / docs2md-1.0.1-py3-none-any.whl

Download URL docs2md-1.0.1-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16a550e91d573b629064dbd55008d2fe059e984ef61ee6979c46c16e54dfe126
BLAKE2b-256 checksum
How to use checksums
dff292e6b34f1b260c8a7e2e906e0ad9209ea707100ddfa8486f6afc863ffc16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

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