Skip to main content

Generate Docstrings with type-hint information.

Project description

Docstring Generator Extension

C++ Tests Build Extension PyPI version Python versions License: MIT

docstring_generator_ext is a high-performance Python extension written in C++ (using pybind11) designed to automatically generate and inject docstrings into Python source files. It leverages Python's ast module to extract type-hint information and function signatures to create well-formatted docstrings in various styles.

Features

  • Automatic Docstring Injection: Parses Python files and inserts docstrings for functions and methods.
  • Type-Hint Awareness: Extracts type information from annotations and default values.
  • Multiple Styles: Supports popular docstring formats:
    • reST (reStructuredText)
    • Google style
    • NumPy style
  • High Performance: Core logic implemented in C++ for fast processing.
  • Preserves Existing Content: Can update existing docstrings while trying to preserve manually added descriptions (using a special $ marker convention).

Installation

Prerequisites

  • Python 3.13 or higher
  • A C++ compiler with C++20 support (e.g., GCC, Clang, or MSVC)
  • pybind11

Building from Source

  1. Clone the repository:

    git clone https://github.com/FelixTheC/docstring_generator_ext.git
    cd docstring_generator_ext
    
  2. Install the build package:

    pip install build
    
  3. Build the package:

    python -m build
    
  4. Install the built wheel:

    pip install dist/docstring_generator_ext-*.whl
    

Usage

After installation, you can use the extension in your Python scripts:

import docstring_generator_ext

# Path to the Python file you want to process
file_path = "path/to/your_script.py"

# Choose a style: GOOGLE, NUMPY, or reST
style = docstring_generator_ext.DocstringFormatStyle.GOOGLE

# Generate and inject docstrings
docstring_generator_ext.parse_file(file_path, style)

Docstring Styles

The extension provides an enum DocstringFormatStyle to choose the desired output:

  • docstring_generator_ext.DocstringFormatStyle.reST
  • docstring_generator_ext.DocstringFormatStyle.GOOGLE
  • docstring_generator_ext.DocstringFormatStyle.NUMPY

Authors

  • FelixTheC

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

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

docstring_generator_ext-1.0.3a5.tar.gz (9.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

docstring_generator_ext-1.0.3a5-cp313-cp313-win_amd64.whl (242.3 kB view details)

Uploaded CPython 3.13Windows x86-64

docstring_generator_ext-1.0.3a5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (583.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

docstring_generator_ext-1.0.3a5-cp313-cp313-macosx_13_0_x86_64.whl (367.9 kB view details)

Uploaded CPython 3.13macOS 13.0+ x86-64

docstring_generator_ext-1.0.3a5-cp313-cp313-macosx_13_0_arm64.whl (383.8 kB view details)

Uploaded CPython 3.13macOS 13.0+ ARM64

File details

Details for the file docstring_generator_ext-1.0.3a5.tar.gz.

File metadata

File hashes

Hashes for docstring_generator_ext-1.0.3a5.tar.gz
Algorithm Hash digest
SHA256 bf7eaf750b24fa94ac72ede5e84f6407de7649864f20101b50ece857de58da7f
MD5 cbd8a93b9cc6bbb116f3deb3ecf5517c
BLAKE2b-256 106a07fbcfb1819181eeb5319feaf22832aa748f0d71bbc4ddb752d471a67be3

See more details on using hashes here.

Provenance

The following attestation bundles were made for docstring_generator_ext-1.0.3a5.tar.gz:

Publisher: python-publish-ext.yml on FelixTheC/docstring_generator_ext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docstring_generator_ext-1.0.3a5-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for docstring_generator_ext-1.0.3a5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 feee86d4b6dbe0ebf4cbaed407f2517aa87ed7fdd760b964858bd8583a322697
MD5 3a9bcd6d614c612ec0d61ea4716e31b8
BLAKE2b-256 f49cb25b3f23416c1ea445c01cc6b5b1c2a9eb9132d966846fcd5e43be93e596

See more details on using hashes here.

Provenance

The following attestation bundles were made for docstring_generator_ext-1.0.3a5-cp313-cp313-win_amd64.whl:

Publisher: python-publish-ext.yml on FelixTheC/docstring_generator_ext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docstring_generator_ext-1.0.3a5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for docstring_generator_ext-1.0.3a5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 344a4d283eeded55230a68a554930aad7a5dc7dd4424b1df0c6ea1a1f2856b6e
MD5 7af5d4be47c4e3f80d46fc34dbd36e9c
BLAKE2b-256 5effa15f3286ec428fed38714cb4201c57b0a6e2bafec0327e9a0cba9694b803

See more details on using hashes here.

Provenance

The following attestation bundles were made for docstring_generator_ext-1.0.3a5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-publish-ext.yml on FelixTheC/docstring_generator_ext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docstring_generator_ext-1.0.3a5-cp313-cp313-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for docstring_generator_ext-1.0.3a5-cp313-cp313-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 ae5c403a2c7c446e3666fd0fcb297e066c59be49d3ebef0b5030efd59269e6f2
MD5 ecefa9da7cc78357eb887d3d35e08667
BLAKE2b-256 4f141c5f85aa604b4e12f7fb404a322bc1ea35eb5d6f384e15135e43c4966c52

See more details on using hashes here.

Provenance

The following attestation bundles were made for docstring_generator_ext-1.0.3a5-cp313-cp313-macosx_13_0_x86_64.whl:

Publisher: python-publish-ext.yml on FelixTheC/docstring_generator_ext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file docstring_generator_ext-1.0.3a5-cp313-cp313-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for docstring_generator_ext-1.0.3a5-cp313-cp313-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 766f9733f96f37d0822b4350b8d336258f10699c6b05bdac70cfe9cc7bf13ef0
MD5 1de02290c8c19740bfe78567bef6d719
BLAKE2b-256 d1a8a5b94f62e9f2bc527effbd5d4e23637eb25a5359948e006a682820fb1d63

See more details on using hashes here.

Provenance

The following attestation bundles were made for docstring_generator_ext-1.0.3a5-cp313-cp313-macosx_13_0_arm64.whl:

Publisher: python-publish-ext.yml on FelixTheC/docstring_generator_ext

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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