Skip to main content

A script to add docstrings to Python type stubs using reflection

Project description

docify

A script to add docstrings to Python type stubs using reflection

Features

  • Uses LibCST to parse and modify the stub file
  • Dynamically imports the actual module to get the runtime docstring
  • Handles most sys.version and sys.platform conditional blocks, will only add docstrings to the correct branch
  • Able to modify files in-place with -i or --in-place
  • Won't overwrite existing docstrings
  • With -b or --builtins-only, will only add docstrings for modules found in sys.builtin_module_names (stdlib modules written in C).
  • With --if-needed, will only add docstrings if the object's (Python) source code is unavailable. Useful for language servers like basedpyright that are able to extract docstrings from source code.

Installation

Install from PyPI:

pip install docify

docify
# or
python -m docify

Or from conda-forge:

conda install conda-forge::docify

docify
# or
python -m docify

Or just download and run the script directly:

# Install dependencies
pip install libcst tqdm  # tqdm is optional, and is only used if not running with -q

python docify.py
# or
python -m docify
# or
chmod +x docify.py
./docify.py

Usage

docify [-h] [-V] [-v] [-q] [-b] [--if-needed] (-i | -o OUTPUT_DIR) INPUT_DIR [INPUT_DIR ...]

A script to add docstrings to Python type stubs using reflection

positional arguments:
  INPUT_DIR             directory to read stubs from

options:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -v, --verbose         increase verbosity
  -q, --quiet           decrease verbosity
  -b, --builtins-only   only add docstrings to modules found in `sys.builtin_module_names`
  --if-needed           only add a docstring if the object's source code cannot be found
  -i, --in-place        modify stubs in-place
  -o, --output OUTPUT_DIR
                        directory to write modified stubs to

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

docify-1.1.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

docify-1.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file docify-1.1.0.tar.gz.

File metadata

  • Download URL: docify-1.1.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.6

File hashes

Hashes for docify-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d9475055a330b4edc31be5854d78704a9c231dcf29b4c6e79421e4ce2adb90aa
MD5 23a3cba7c43d6192cff86aaad609e5ae
BLAKE2b-256 5c43b6b3ed504910ce076e6b7b6659aba4d26e51da3d3116393232278df22284

See more details on using hashes here.

File details

Details for the file docify-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: docify-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.6

File hashes

Hashes for docify-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b45a82f0da74e97f80d5ace255b417ec289cb2d22d321bfe3124f38a42df68b
MD5 77fc2433daf07e4a23610d7e6174e558
BLAKE2b-256 d1b4a5ea211025bf8544a1366e04c57efca6c9d1ba45028e53269ce1182bb49d

See more details on using hashes here.

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