Generate Docstrings with type-hint information.
Project description
Docstring Generator Extension
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
-
Clone the repository:
git clone https://github.com/FelixTheC/docstring_generator_ext.git cd docstring_generator_ext
-
Install the
buildpackage:pip install build
-
Build the package:
python -m build
-
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)
You can also audit an existing file to see how well its functions are documented, without making any changes:
import docstring_generator_ext
# Path to the Python file you want to audit
file_path = "path/to/your_script.py"
# Returns a dict with docstring coverage statistics
result = docstring_generator_ext.check_docstring(file_path)
print(f"Functions checked : {result['num_functions_checked']}")
print(f"Complete docstrings: {result['complete_docstrings']}")
print(f"Partial docstrings : {result['partial_docstrings']}")
print(f"No docstrings : {result['no_docstrings']}")
The returned dictionary always contains four keys:
| Key | Description |
|---|---|
num_functions_checked |
Total number of functions/methods found in the file |
complete_docstrings |
Functions whose docstring fully matches the signature |
partial_docstrings |
Functions with an incomplete or outdated docstring |
no_docstrings |
Functions with no docstring at all |
Docstring Styles
The extension provides an enum DocstringFormatStyle to choose the desired output:
docstring_generator_ext.DocstringFormatStyle.reSTdocstring_generator_ext.DocstringFormatStyle.GOOGLEdocstring_generator_ext.DocstringFormatStyle.NUMPY
C++20
The core of this extension is written in C++20 to take full advantage of the modern standard's best algorithms and features:
std::format: Used for clean, type-safe string formatting throughout the docstring generation logic.- Ranges & views: C++20 ranges enable expressive, composable data transformations without raw loops.
- Concepts: Improve template code clarity and provide better compiler error messages.
std::span: Provides safe, bounds-checked views over contiguous data without ownership overhead.
Compiler Requirements
Building from source requires a C++ compiler with full C++20 support:
| Platform | Minimum version |
|---|---|
| Linux | GCC 11+ / Clang 14+ |
| macOS | Apple Clang 15+ / GCC 13+ (via Homebrew) |
| Windows | MSVC 2022 (19.30+) |
Pre-built wheels on PyPI are compiled with C++20 enabled and require no special toolchain on the user's side.
Authors
- FelixTheC
License
This project is licensed under the MIT License - see the LICENSE.md file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docstring_generator_ext-2.0.1.tar.gz.
File metadata
- Download URL: docstring_generator_ext-2.0.1.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
670be9f39f6e578c218b3800e0427d308efa81ad37da6627c359644851b005db
|
|
| MD5 |
595f06f4e75f319022a3cc1b02365f8d
|
|
| BLAKE2b-256 |
8ea2665283b9813e92df64264660e58f08bc63c417ea1f8773b465844d7e38b5
|
Provenance
The following attestation bundles were made for docstring_generator_ext-2.0.1.tar.gz:
Publisher:
python-publish-ext.yml on FelixTheC/docstring_generator_ext
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docstring_generator_ext-2.0.1.tar.gz -
Subject digest:
670be9f39f6e578c218b3800e0427d308efa81ad37da6627c359644851b005db - Sigstore transparency entry: 2149496606
- Sigstore integration time:
-
Permalink:
FelixTheC/docstring_generator_ext@c507d89617cfdd37475948bbf329913ca627594d -
Branch / Tag:
refs/tags/2.0.1 - Owner: https://github.com/FelixTheC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish-ext.yml@c507d89617cfdd37475948bbf329913ca627594d -
Trigger Event:
release
-
Statement type:
File details
Details for the file docstring_generator_ext-2.0.1-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: docstring_generator_ext-2.0.1-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 248.2 kB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0a3e9c2acb7496a26cf211432a2231bbc2f08abb1ef60bdf341ad6bf3f0a69e
|
|
| MD5 |
0ab24052ada9c19a0b12651d5bed68a8
|
|
| BLAKE2b-256 |
4306b77d19068d2f06a60ba0f0cb7cdcb9b4b7f992e8c50c9bddb2a9702a74a5
|
Provenance
The following attestation bundles were made for docstring_generator_ext-2.0.1-cp313-cp313-win_amd64.whl:
Publisher:
python-publish-ext.yml on FelixTheC/docstring_generator_ext
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docstring_generator_ext-2.0.1-cp313-cp313-win_amd64.whl -
Subject digest:
d0a3e9c2acb7496a26cf211432a2231bbc2f08abb1ef60bdf341ad6bf3f0a69e - Sigstore transparency entry: 2149497026
- Sigstore integration time:
-
Permalink:
FelixTheC/docstring_generator_ext@c507d89617cfdd37475948bbf329913ca627594d -
Branch / Tag:
refs/tags/2.0.1 - Owner: https://github.com/FelixTheC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish-ext.yml@c507d89617cfdd37475948bbf329913ca627594d -
Trigger Event:
release
-
Statement type:
File details
Details for the file docstring_generator_ext-2.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: docstring_generator_ext-2.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 612.4 kB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e67e52ab48d1584d30c4bc5256d80c2ea067dd8bd1664f8ce5c0056036f1dc77
|
|
| MD5 |
fbcd3a105e86e671ae7dc60d86f25446
|
|
| BLAKE2b-256 |
de9e6eb3c7f075f274d5c0f2759ecea50e2ed18747ecfc4b2e2ae50cd9bc0d3a
|
Provenance
The following attestation bundles were made for docstring_generator_ext-2.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:
Publisher:
python-publish-ext.yml on FelixTheC/docstring_generator_ext
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docstring_generator_ext-2.0.1-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl -
Subject digest:
e67e52ab48d1584d30c4bc5256d80c2ea067dd8bd1664f8ce5c0056036f1dc77 - Sigstore transparency entry: 2149498121
- Sigstore integration time:
-
Permalink:
FelixTheC/docstring_generator_ext@c507d89617cfdd37475948bbf329913ca627594d -
Branch / Tag:
refs/tags/2.0.1 - Owner: https://github.com/FelixTheC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish-ext.yml@c507d89617cfdd37475948bbf329913ca627594d -
Trigger Event:
release
-
Statement type:
File details
Details for the file docstring_generator_ext-2.0.1-cp313-cp313-macosx_13_0_x86_64.whl.
File metadata
- Download URL: docstring_generator_ext-2.0.1-cp313-cp313-macosx_13_0_x86_64.whl
- Upload date:
- Size: 399.6 kB
- Tags: CPython 3.13, macOS 13.0+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52082c316e8fdb0bf5d73d0fad057562977d1c97a8bc8fc92f292b26a9b012fe
|
|
| MD5 |
2b38db9a4e3e3f7c1d0e807e8a40d33d
|
|
| BLAKE2b-256 |
b378e81604e4922eece55835219e1f2f938d233c6eed3fdde4b53d48f2e28524
|
Provenance
The following attestation bundles were made for docstring_generator_ext-2.0.1-cp313-cp313-macosx_13_0_x86_64.whl:
Publisher:
python-publish-ext.yml on FelixTheC/docstring_generator_ext
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docstring_generator_ext-2.0.1-cp313-cp313-macosx_13_0_x86_64.whl -
Subject digest:
52082c316e8fdb0bf5d73d0fad057562977d1c97a8bc8fc92f292b26a9b012fe - Sigstore transparency entry: 2149498610
- Sigstore integration time:
-
Permalink:
FelixTheC/docstring_generator_ext@c507d89617cfdd37475948bbf329913ca627594d -
Branch / Tag:
refs/tags/2.0.1 - Owner: https://github.com/FelixTheC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish-ext.yml@c507d89617cfdd37475948bbf329913ca627594d -
Trigger Event:
release
-
Statement type:
File details
Details for the file docstring_generator_ext-2.0.1-cp313-cp313-macosx_13_0_arm64.whl.
File metadata
- Download URL: docstring_generator_ext-2.0.1-cp313-cp313-macosx_13_0_arm64.whl
- Upload date:
- Size: 403.9 kB
- Tags: CPython 3.13, macOS 13.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
760d098e9ad56c3cc7c783cf99d9ece5d81a778af7caad00fc7dac8571227c4d
|
|
| MD5 |
55808e3427d2fcae0c7cba906a64d070
|
|
| BLAKE2b-256 |
885ecccf57f42ccb7fd5f76acf6acc9824e3b3c4378e16c6bbec56ee822c2eea
|
Provenance
The following attestation bundles were made for docstring_generator_ext-2.0.1-cp313-cp313-macosx_13_0_arm64.whl:
Publisher:
python-publish-ext.yml on FelixTheC/docstring_generator_ext
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
docstring_generator_ext-2.0.1-cp313-cp313-macosx_13_0_arm64.whl -
Subject digest:
760d098e9ad56c3cc7c783cf99d9ece5d81a778af7caad00fc7dac8571227c4d - Sigstore transparency entry: 2149497604
- Sigstore integration time:
-
Permalink:
FelixTheC/docstring_generator_ext@c507d89617cfdd37475948bbf329913ca627594d -
Branch / Tag:
refs/tags/2.0.1 - Owner: https://github.com/FelixTheC
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish-ext.yml@c507d89617cfdd37475948bbf329913ca627594d -
Trigger Event:
release
-
Statement type: