{"id":13472807,"url":"https://github.com/MichaelisTrofficus/gpt4docstrings","last_synced_at":"2025-03-26T17:31:18.540Z","repository":{"id":176814631,"uuid":"658264834","full_name":"MichaelisTrofficus/gpt4docstrings","owner":"MichaelisTrofficus","description":"Generating Python docstrings with OpenAI ChatGPT!!","archived":false,"fork":false,"pushed_at":"2024-03-03T01:34:03.000Z","size":1414,"stargazers_count":122,"open_issues_count":11,"forks_count":12,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-17T07:15:10.753Z","etag":null,"topics":["ai","chatgpt","code-quality","docstrings","precommit-hooks","python"],"latest_commit_sha":null,"homepage":"https://gpt4docstrings.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MichaelisTrofficus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-25T08:56:50.000Z","updated_at":"2025-02-23T05:13:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"ffc88833-8580-4d47-a4a2-d2e193341e6c","html_url":"https://github.com/MichaelisTrofficus/gpt4docstrings","commit_stats":null,"previous_names":["michaelistrofficus/gpt4docstrings"],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelisTrofficus%2Fgpt4docstrings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelisTrofficus%2Fgpt4docstrings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelisTrofficus%2Fgpt4docstrings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MichaelisTrofficus%2Fgpt4docstrings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MichaelisTrofficus","download_url":"https://codeload.github.com/MichaelisTrofficus/gpt4docstrings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245232777,"owners_count":20581699,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","chatgpt","code-quality","docstrings","precommit-hooks","python"],"created_at":"2024-07-31T16:00:58.173Z","updated_at":"2025-03-26T17:31:18.164Z","avatar_url":"https://github.com/MichaelisTrofficus.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg alt=\"gpt4docstrings logo\" src=\"images/logo.png\" width=300 /\u003e\n    \u003ch1 align=\"center\"\u003egpt4docstrings\u003c/h1\u003e\n    \u003ch3 align=\"center\"\u003eGenerating Python docstrings with OpenAI ChatGPT!!\u003c/h3\u003e\n\u003c/p\u003e\n\n---\n\n[![PyPI](https://img.shields.io/pypi/v/gpt4docstrings.svg)][pypi_]\n[![Status](https://img.shields.io/pypi/status/gpt4docstrings.svg)][status]\n[![Python Version](https://img.shields.io/pypi/pyversions/gpt4docstrings)][python version]\n[![License](https://img.shields.io/pypi/l/gpt4docstrings)][license]\n\n[![Read the documentation at https://gpt4docstrings.readthedocs.io/](https://img.shields.io/readthedocs/gpt4docstrings/latest.svg?label=Read%20the%20Docs)][read the docs]\n[![Tests](https://github.com/MichaelisTrofficus/gpt4docstrings/workflows/Tests/badge.svg)][tests]\n[![Codecov](https://codecov.io/gh/MichaelisTrofficus/gpt4docstrings/branch/main/graph/badge.svg)][codecov]\n\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\u0026logoColor=white)][pre-commit]\n[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)][black]\n\n[pypi_]: https://pypi.org/project/gpt4docstrings/\n[status]: https://pypi.org/project/gpt4docstrings/\n[python version]: https://pypi.org/project/gpt4docstrings\n[read the docs]: https://gpt4docstrings.readthedocs.io/\n[tests]: https://github.com/MichaelisTrofficus/gpt4docstrings/actions?workflow=Tests\n[codecov]: https://app.codecov.io/gh/MichaelisTrofficus/gpt4docstrings\n[pre-commit]: https://github.com/pre-commit/pre-commit\n[black]: https://github.com/psf/black\n\n## What is `gpt4docstrings`?\n\n`gpt4docstrings` is a library that helps you to write docstrings\nfor your Python code. Select a path / paths where you want `gpt4docstrings`\nto be applied and wait for the results!!\n\n![](images/usage.gif)\n\n## Requirements\n\n`gpt4docstrings` supports Python 3.9 and above.\n\n## Installation\n\n\u003e **Warning:** At the moment, this library is under heavy development, so it is recommended to always install\n\u003e the latest version.\n\nYou can install _gpt4docstrings_ via [pip] from [PyPI]:\n\n```console\n$ pip install -U gpt4docstrings\n```\n\n## Usage\n\nTo run `gpt4docstrings` on a specific file, run this command.\n\n```bash\ngpt4docstrings my_file.py\n```\n\nRemember that, if you don't have your OpenAI API Key defined as an Environment Variable (OPENAI_API_KEY),\n`gpt4docstrings` can accept the API Key as an option.\n\n```bash\ngpt4docstrings --api_key sk-xxxxxxxxxxxx my_file.py\n```\n\nBe aware that, as a safety measure , `gpt4docstrings` won't overwrite the file in place.\nInstead, it will generate a `patch` called `gpt4docstring_docstring_generator_patch.diff`\nthat contains the information about all the changes.\n\nIf you want to apply the `patch` to the file, simply run:\n\n```bash\npatch -p1 \u003c gpt4docstring_docstring_generator_patch.diff\n```\n\nIn case you don't want to generate a `patch` file and modify the files in place, you'll\nneed to add the `--overwrite, -w` option:\n\n```bash\ngpt4docstrings -w my_file.py\n```\n\nYou can also apply `gpt4docstrings` to folders recursively.\n\n```bash\ngpt4docstrings src/\n```\n\nAnother quite common situation is that you may want to exclude the `tests/` folder, for example,\nfrom the generation of docstrings. Doing this is very simple.\n\n```bash\ngpt4docstrings --exclude tests/ src/\n```\n\nBy default, `gpt4docstrings` generates `google` style docstrings. However,\nyou can choose between: `google`, `numpy`, `epytext`, `reStructuredText`.\n\nYou can specify the docstring style using the `-st` option. For example:\n\n```bash\ngpt4docstrings -st epytext my_file.py\n```\n\nFor more information about all the available options, you can check\nthe `help` info:\n\n```\nUsage: gpt4docstrings [OPTIONS] [PATHS]...\n\nOptions:\n  -h, --help                      Show this message and exit.\n  -S, --ignore-setters            Ignore methods with property setter\n                                  decorators.\n  -P, --ignore-property-decorators\n                                  Ignore methods with property setter/getter\n                                  decorators.\n  -n, --ignore-nested-functions   Ignore nested functions and methods.\n  -C, --ignore-nested-classes     Ignore nested classes.\n  -i, --ignore-init-method        Ignore `__init__` method of classes.\n  -s, --ignore-semiprivate        Ignore semiprivate classes, methods, and\n                                  functions starting with a single underscore.\n  -p, --ignore-private            Ignore private classes, methods, and\n                                  functions starting with two underscores.\n                                  [default: False]\n  -w, --overwrite                 If `True`, it will directly write the\n                                  docstrings into the files (it will not\n                                  generate git patches)\n  -v, --verbose INTEGER           Verbosity parameter. Defaults to 0.\n  -e, --exclude PATH              Exclude PATHs of files and/or directories.\n                                  Multiple `-e/--exclude` invocations\n                                  supported.\n  -k, --api_key TEXT              OpenAI's API key. If not provided,\n                                  `gpt4docstrings` will try to access\n                                  `OPENAI_API_KEY` environment variable.\n  -st, --style TEXT               Docstring style, which must be one of\n                                  'google', 'reStructuredText', 'epytext',\n                                  'numpy'\n  -m, --model TEXT                The model to be used by `gpt4docstrings`. By\n                                  default, `gpt-3.5-turbo`.\n```\n\nI also encourage you to see the [Command-line Reference] for more details!!\n\n## Example\n\nHere is a full example using `gpt4docstring` to generate docstrings\nfor the python code inside `example/example.py`.\n\n```python\nimport asyncio\n\n\nasync def async_example():\n    await asyncio.sleep(2)\n\n\nclass MyClass:\n\n    def __init__(self, value):\n        self.value = value\n\n    @staticmethod\n    def nested_method():\n        def inner_function():\n            print(\"Nested method inner function\")\n        print(\"Nested method start\")\n        inner_function()\n        print(\"Nested method completed\")\n```\n\nWe'll create `numpy` docstrings in this case and will generate a patch file (default) instead of directly overwriting\nthe file directly. We'll also increase the level of verbosity to see some additional information.\n\n\u003e **Warning:** We are assuming you already have the OpenAI API Key set as an Environment Variable. Otherwise, this\n\u003e example won't work.\n\n```\ngpt4docstrings example/example.py -v 1 -st numpy\n```\n\n![gpt4docstring-command-run.gif](images%2Fgpt4docstring-command-run.gif)\n\nAfter it finishes documenting, we should see a new patch file on our directory called `gpt4docstring_docstring_generator_patch.diff`.\n\nTo apply the patch, simply run:\n\n```bash\npatch -p1 \u003c gpt4docstring_docstring_generator_patch.diff\n```\n\nThe result should be similar to the following (`gpt-3.5-turbo` temperature\nis set to 1, so you should expect different results every time you run the command)\n\n```python\nimport asyncio\n\n\nasync def async_example():\n    \"\"\"\n    An asynchronous example function.\n\n    This function asynchronously sleeps for 2 seconds.\n\n    Returns\n    -------\n    None\n        This function does not return any value.\n    \"\"\"\n    await asyncio.sleep(2)\n\n\nclass MyClass:\n    \"\"\"\n    A class representing MyClass.\n\n    Parameters\n    ----------\n    value : any\n        The initial value for MyClass.\n\n    Methods\n    -------\n    nested_method : static method\n        A nested static method within MyClass.\n    \"\"\"\n    def __init__(self, value):\n        \"\"\"\n        Initialize a new instance of the class.\n\n        Parameters\n        ----------\n        value : any\n            The initial value for the instance.\n\n        Returns\n        -------\n        None\n\n        Raises\n        ------\n        None\n        \"\"\"\n        self.value = value\n\n    @staticmethod\n    def nested_method():\n        \"\"\"\n        This static method demonstrates a nested method.\n\n        Raises\n        ------\n        None\n\n        Returns\n        -------\n        None\n        \"\"\"\n        def inner_function():\n            \"\"\"\n            Inner function.\n\n            This function performs a nested method inner function.\n\n            Parameters\n            ----------\n            None\n\n            Returns\n            -------\n            None\n            \"\"\"\n            print(\"Nested method inner function\")\n\n        print(\"Nested method start\")\n        inner_function()\n        print(\"Nested method completed\")\n```\n\nSuppose now that we want to modify the docstring type. For example,\nsuppose we want to use `epytext` style. That's very easy with\n`gpt4docstrings`, we just need to run the same command changing the docstring style.\n\n\u003e Be aware that, by default, `gpt4docstrings` will allways generate\n\u003e docstrings for undocumented functions / classes and also translate the existing\n\u003e ones to follow the provided style. If you just want to generate docstrings (no translation),\n\u003e simply set the `-t` flag to `False`.\n\n```bash\ngpt4docstrings example/example.py -st epytext\n```\n\nIf we apply the patch, we'll get the previous code with the\ndocstrings translated:\n\n```python\nimport asyncio\n\n\nasync def async_example():\n    \"\"\"\n    An asynchronous example function.\n\n    This function asynchronously sleeps for 2 seconds.\n\n    @rtype: None\n    @return: This function does not return any value.\n    \"\"\"\n    await asyncio.sleep(2)\n\n\nclass MyClass:\n    \"\"\"\n    A class representing MyClass.\n\n    @type value: any\n    @ivar value: The initial value for MyClass.\n\n    @type nested_method: static method\n    @ivar nested_method: A nested static method within MyClass.\n    \"\"\"\n    def __init__(self, value):\n        \"\"\"\n        Initialize a new instance of the class.\n\n        @param value: The initial value for the instance.\n        @type value: any\n\n        @return: None\n\n        @raise None\n        \"\"\"\n        self.value = value\n\n    @staticmethod\n    def nested_method():\n        \"\"\"\n        This static method demonstrates a nested method.\n\n        @rtype: None\n        @return: None\n\n        @raise: None\n        \"\"\"\n        def inner_function():\n            \"\"\"\n            Inner function.\n\n            This function performs a nested method inner function.\n\n            @rtype: None\n            \"\"\"\n            print(\"Nested method inner function\")\n\n        print(\"Nested method start\")\n        inner_function()\n        print(\"Nested method completed\")\n```\n\n## Contributing\n\nContributions are very welcome.\nTo learn more, see the [Contributor Guide].\n\n## License\n\nDistributed under the terms of the [MIT license][license],\n_gpt4docstrings_ is free and open source software.\n\n## Issues\n\nIf you encounter any problems,\nplease [file an issue] along with a detailed description.\n\n## Credits\n\nThis project was generated from [@cjolowicz]'s [Hypermodern Python Cookiecutter] template.\n\n[@cjolowicz]: https://github.com/cjolowicz\n[pypi]: https://pypi.org/\n[hypermodern python cookiecutter]: https://github.com/cjolowicz/cookiecutter-hypermodern-python\n[file an issue]: https://github.com/MichaelisTrofficus/gpt4docstrings/issues\n[pip]: https://pip.pypa.io/\n\n\u003c!-- github-only --\u003e\n\n[license]: https://gpt4docstrings.readthedocs.io/en/latest/license.html\n[contributor guide]: https://gpt4docstrings.readthedocs.io/en/latest/contributing.html#\n[command-line reference]: https://gpt4docstrings.readthedocs.io/en/latest/use_as_cli.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMichaelisTrofficus%2Fgpt4docstrings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMichaelisTrofficus%2Fgpt4docstrings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMichaelisTrofficus%2Fgpt4docstrings/lists"}