Skip to main content

Use DocHelper to simplify your python docstrings

If you have been writing classes or functions with many shared arguments, you might have going through the tedious and error prone process of copy-pasting, searching-updating same docstring again and again. Passing through **kwargs might not always be the solution not to say it's implicit and makes user to look up multiple documents to find available arguments.

So how about one place to store and update them all? DocHelper keeps the docstrings for arguments in the same place and you only need to write the template for each class or functions - it will compose and fill in the template in Google format.

Works from Jupyter notebook to Sphinx where docstrings were read by importing.

Installation

pip install doc-helper

Install from source

# make sure you have setuptools and wheel installed

git clone https://github.com/ynshen/DocHelper.git
cd DocHelper
python setup.py bdist_wheel
pip install dist/the-wheel-file-of-your-version.whl

Usage

Initialize a DocHelper with argument docstrings

from doc_helper import DocHelper

my_doc = DocHelper(
    arg1='Just an simple argument',           # defined as keyword arguments
    arg2=('Also an simple argument'),         # or a (not really) tuple
    arg3=('int', 'This argument is integer')  # tuple with data type
)

Add arguments when you needed

my_doc.add(
    arg4=('pd.DataFrame', 'Just a new argument')
)

Use DocHelper.get() to get formatted docstring for arguments

# Pass a list/tuple of argument names to `DocHelper.get()`
>>> my_doc.get(['arg1', 'arg3'])
    arg1: Just an simple argument
    arg3 (int): This argument is integer

# Pass a callable (function) to automatic find related arguments (except 'self')
def awesome_function(arg1, arg3):
    pass

>>> my_doc.get(awesome_function)
    arg1: Just an simple argument
    arg3 (int): This argument is integer

Use decorator DocHelper.compose to write template

Simply write a string with comma separated arguments name in << and >>. Default indents is 4, just add a number to change to desired indents.

# Example 1

@my_doc.compose("""This is my awesome function
Args:
<<arg1, arg2>>
   arg3: This arg3 is special
""")
def awesome_function(arg1, arg2, arg3):
    pass

>>> awesome_function.__doc__
This is my awesome function
Args:
    arg1: Just an simple argument
    arg2: Also an simple argument
    arg3: This arg3 is special


# Example 2

@my_doc.compose("""This is another awesome function only takes arg1, arg3, and I want indent = 8
Args:
<<arg1, arg2, 8>>
""")
def another_awesome_function(arg1, arg3):
    pass

>>> another_awesome_function.__doc__
This is another awesome function only takes arg1, arg3, and I wand indent = 8
Args:
        arg1: Just an simple argument
        arg3 (int): This argument is integer


# Example 3

@my_doc.compose("""Feeling lazy? left it blank to include all arguments (except 'self')
Args:
<<>>
""")
def another_another_awesome_function(arg1, arg2, arg3):
    pass

>>> another_another_awesome_function.__doc__
This is my awesome function
Args:
    arg1: Just an simple argument
    arg2: Also an simple argument
    arg3 (int): This argument is integer

Update

  • version 1.1.1: indents at the top of << >> can be controlled through DocHelper.compose(indent_at_top=False/True), default False.
  • version 1.1.0: extra indents at the top of each lines were subtracted

TODO

  • Add docstring formatting function to subtract extra indents
  • Include different formatting (Numpy, reStructuredText)

Metadata

Release files for doc-helper 1.1.1

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

Built distribution (wheel)

Table of built distributions (wheels) for doc-helper 1.1.1
File Interpreter ABI Platform Actions
doc_helper-1.1.1-py3-none-any.whl Python 3 none any Details for doc_helper-1.1.1-py3-none-any.whl

Release files / doc_helper-1.1.1-py3-none-any.whl

Download URL doc_helper-1.1.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25ec57ac2c28af6f5f1e724d462c70a00a82eefb810fbac982683eae437833b7
BLAKE2b-256 checksum
How to use checksums
4a24ab6b150662349282d2a628769ee5fd0ae1f4d829062c8124d9162509f820
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.42.0 CPython/3.6.3

Security for doc-helper 1.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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