Skip to main content

It parses and composes docstrings in Google, Numpydoc, ReST and Epydoc.

Project description

The project is a fork from the original project - https://github.com/rr-/docstring_parser/

PyDocSmith

PyDocSmith is a versatile Python package designed for parsing, detecting, and composing docstrings in various styles. It supports multiple docstring conventions, including reStructuredText (reST), Google, NumPydoc, and Epydoc, providing flexibility in documentation practices for Python developers.

Features

  • Docstring Style Detection: Automatically detect the style of docstrings (e.g., reST, Google, NumPydoc, Epydoc) using simple heuristics.
  • Docstring Parsing: Convert docstrings into structured representations, making it easier to analyze and manipulate documentation.
  • Docstring Composition: Render structured docstrings back into text, allowing for automated docstring generation and modification.
  • Attribute Docstrings: Parse attribute docstrings defined at class and module levels, enhancing the documentation of class properties and module-level variables.

Installation

pip install PyDocSmith

Usage

Detecting Docstring Style

Detect the docstring style of a given text:

from PyDocSmith import detect_docstring_style, DocstringStyle

docstring = """
This is an example docstring.
:param param1: Description of param1
:return: Description of return value
"""
style = detect_docstring_style(docstring)
print(style)  # Outputs: DocstringStyle.EPYDOC

Parsing Docstrings

Parse a docstring into its components:

from PyDocSmith import parse, DocstringStyle

parsed_docstring = parse(docstring, style=DocstringStyle.AUTO)
print(parsed_docstring)

Composing Docstrings

Render a parsed docstring back into text:

from PyDocSmith import compose

docstring_text = compose(parsed_docstring, style=DocstringStyle.REST)
print(docstring_text)

Advanced Features

  • Parse From Object: PyDocSmith can parse docstrings directly from Python objects, including classes and modules, incorporating attribute docstrings into the structured representation.
  • Custom Rendering Styles: Customize the rendering of docstrings with compact or detailed styles, and specify custom indentation for the generated docstring text.

Things that have been modified wrt to docstring_parser

  1. Better heuristics to detect docstring style
  2. Google Docstring has been modified to accommodate Notes, Examples
  3. Sometime GoogleDoc string doesn't have proper indentation specially when generated from LLMs like GPT or Mistral. PyDocSmith can fix those bad docstrings.
  4. Additional test-cases were added to accommodate a different style of GoogleDocstring

I have updated it based on use case for - https://www.penify.dev

Contributing

Contributions are welcome! Please submit pull requests or report issues on the project's GitHub page.

Project details


Download files

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

Source Distribution

pydocsmith-0.1.5.tar.gz (33.1 kB view details)

Uploaded Source

Built Distribution

PyDocSmith-0.1.5-py3-none-any.whl (40.5 kB view details)

Uploaded Python 3

File details

Details for the file pydocsmith-0.1.5.tar.gz.

File metadata

  • Download URL: pydocsmith-0.1.5.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for pydocsmith-0.1.5.tar.gz
Algorithm Hash digest
SHA256 4a2af749174c674b76b7be0e69f68eaaa2d85a9dc49cb7ce507c614ec5583903
MD5 aeefd21a9a7a2a67f348f97e53d5db2d
BLAKE2b-256 758f76ae3ce6412211d0b94396e3ba8a33088cde6dfe0b327436edc895429d0a

See more details on using hashes here.

File details

Details for the file PyDocSmith-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: PyDocSmith-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 40.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for PyDocSmith-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 271b52f97c75b45bf775d56876289f9c90cc70de64f6f077b8a74994474adb60
MD5 bf4a42e05ef159c31213766bc7cef311
BLAKE2b-256 3f7ba033d95396cdf946a914d7faf4aa7796cf40605f2402b0d09929454b26a8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page