Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

Python stub file generator.

Project description

pygenstub is a utility for generating stub files from docstrings in source files.

If the docstring of a function includes a sig field, the value of that field will be used to generate a stub by matching the types to the parameters in the same order.

For example, for the function given below:

def foo(a, b):
    """Do foo.

    :sig: (int, str) -> None
    """

pygenstub will generate the following stub:

def foo(a: int, b: str) -> None: ...

pygenstub consists of a single source file which contains such signatures. You can check the stub file generated by running pygenstub on itself as an example.

Getting started

pygenstub runs on Python 3.4+. It also supports Python 2.7 and PyPy. You can install the latest version from PyPI:

pip install pygenstub

Installation creates a script named pygenstub which can be used as follows:

pygenstub foo.py

This command will generate the file foo.pyi in the same directory as the input file. If the output file already exists, it will be overwritten.

If you download the source file, you can also run it directly without installing:

python pygenstub.py foo.py

If pygenstub is activated as a Sphinx extension (after sphinx.ext.autodoc), it will insert type comments into the docstring:

extensions = [
    "sphinx.ext.autodoc",
    "pygenstub"
]

As an example of the output, you can check the API documentation for pygenstub itself.

Getting help

The documentation is available on: https://pygenstub.readthedocs.io/

The source code can be obtained from: https://github.com/uyar/pygenstub

License

Copyright (C) 2016-2020 H. Turgut Uyar <uyar@tekir.org>

pygenstub is released under the GPL license, version 3 or later. Read the included LICENSE.txt 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.

Files for pygenstub, version 1.4.1
Filename, size File type Python version Upload date Hashes
Filename, size pygenstub-1.4.1-py2.py3-none-any.whl (36.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size pygenstub-1.4.1.tar.gz (34.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page