{"id":25039349,"url":"https://github.com/multimeric/docstrands","last_synced_at":"2025-07-07T08:33:37.365Z","repository":{"id":275304853,"uuid":"922944932","full_name":"multimeric/DocStrands","owner":"multimeric","description":"Re-use segments of your docstrings on different objects","archived":false,"fork":false,"pushed_at":"2025-06-15T15:33:01.000Z","size":1069,"stargazers_count":5,"open_issues_count":4,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-15T16:32:45.788Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://multimeric.github.io/DocStrands/","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/multimeric.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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,"zenodo":null}},"created_at":"2025-01-27T11:24:32.000Z","updated_at":"2025-06-09T11:37:24.000Z","dependencies_parsed_at":"2025-02-01T15:31:40.705Z","dependency_job_id":"df12cf1d-bdc8-4710-82b0-42a50e550caf","html_url":"https://github.com/multimeric/DocStrands","commit_stats":null,"previous_names":["multimeric/docstrands"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/multimeric/DocStrands","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FDocStrands","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FDocStrands/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FDocStrands/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FDocStrands/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/multimeric","download_url":"https://codeload.github.com/multimeric/DocStrands/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FDocStrands/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264043191,"owners_count":23548518,"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":[],"created_at":"2025-02-06T02:21:07.222Z","updated_at":"2025-07-07T08:33:37.342Z","avatar_url":"https://github.com/multimeric.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n# DocStrands\n\n**[Read the full documentation\nhere](https://multimeric.github.io/DocStrands)**\n\nWhen documenting your functions, you might find yourself documenting the\nsame parameters over and over again. DocStrands provides a framework for\nre-using docstring information.\n\n## Installation\n\n``` bash\npip install docstrands\n```\n\n## Example\n\nImagine you’re writing an HTTP library. You start with a `get` function,\nbut add the `@docstring` decorator to tell DocStrands that it function\nuses Google-style docstrings.\n\n``` python\nfrom docstrands import docstring\n\n@docstring(\"google\")\ndef get(url: str, headers: dict[str, str], params: dict[str, str]) -\u003e str:\n    \"\"\"\n    Makes an HTTP GET request\n\n    Params:\n        url: Path to the resource to request\n        headers: Dictionary of HTTP headers. Keys will be automatically capitalised.\n        params: Dictionary of query parameters which will be URL encoded.\n\n    Returns:\n        The raw HTTP response body as a string.\n    \"\"\"\n```\n\nNext, you want to write a corresponding `post` function. The annoying\nthing is that many of these parameters are exactly the same as on our\n`get` function. Here DocStrands solves this by copying the repeated\ndocumentation using `@get.copy_*` functions:\n\n``` python\n@get.copy_params(\"url\", \"headers\")\n@get.copy_returns()\n@docstring(\"google\")\ndef post(url: str, headers: dict[str, str], body: bytes) -\u003e str:\n    \"\"\"\n    Makes an HTTP POST request.\n\n    Params:\n        body: POST body. Text such as JSON will have to be encoded beforehand.\n    \"\"\"\n```\n\nFinally, you can call `help` to prove this worked correctly:\n\n``` python\nhelp(post)\n```\n\n    Help on ParsedFunc in module docstrands.parsed_func:\n\n    \u003cfunction post\u003e\n        Makes an HTTP POST request.\n\n        Args:\n            body: POST body. Text such as JSON will have to be encoded beforehand.\n            url: Path to the resource to request\n            headers: Dictionary of HTTP headers. Keys will be automatically capitalised.\n\n        Returns:\n            : The raw HTTP response body as a string.\n\n## Type Annotations\n\nDocStrands supports another approach to re-using documentation:\nattaching it to types. The above example represents a common case where\nboth functions shared the same return documentation and return type, so\nwe can encode this using Python’s type system:\n\n``` python\nfrom typing import Annotated\nfrom docstrands import Description\n\nHttpResponse = Annotated[str, Description(\"The raw HTTP response body as a string.\")]\nUrl = Annotated[str, Description(\"Path to the resource to request\")]\nHeaders = Annotated[dict[str, str], Description(\"Dictionary of HTTP headers. Keys will be automatically capitalised.\")]\nParams = Annotated[dict[str, str], Description(\"Dictionary of query parameters which will be URL encoded.\")]\n```\n\nThen apply them to our new function. Note that we still need to define\nthe function description, and we still need to use the `@docstring`\ndecorator:\n\n``` python\n@docstring(\"google\")\ndef get(url: Url, headers: Headers, params: Params) -\u003e HttpResponse:\n    \"\"\"\n    Makes an HTTP POST request.\n    \"\"\"\n\nhelp(get)\n```\n\n    Help on ParsedFunc in module docstrands.parsed_func:\n\n    \u003cfunction get\u003e\n        Makes an HTTP POST request.\n\n        Args:\n            url: Path to the resource to request\n            headers: Dictionary of HTTP headers. Keys will be automatically capitalised.\n            params: Dictionary of query parameters which will be URL encoded.\n\n        Returns:\n            : The raw HTTP response body as a string.\n\nOf course, we can then re-use these parameters with `post`:\n\n``` python\nBody = Annotated[bytes, Description(\"POST body. Text such as JSON will have to be encoded beforehand.\")]\n\n@docstring(\"google\")\ndef post(url: Url, headers: Headers, body: Body) -\u003e HttpResponse:\n    \"\"\"\n    Makes an HTTP POST request.\n    \"\"\"\n\nhelp(post)\n```\n\n    Help on ParsedFunc in module docstrands.parsed_func:\n\n    \u003cfunction post\u003e\n        Makes an HTTP POST request.\n\n        Args:\n            url: Path to the resource to request\n            headers: Dictionary of HTTP headers. Keys will be automatically capitalised.\n            body: POST body. Text such as JSON will have to be encoded beforehand.\n\n        Returns:\n            : The raw HTTP response body as a string.\n\nYou can even re-use the same types as parameters and return values:\n\n``` python\n@docstring(\"google\")\ndef make_accept_headers() -\u003e Headers:\n    \"\"\"\n    Calculates the the `Accept`, `Accept-Encoding` and `Accept-Language` headers based on the capacity of the HTTP client\n    \"\"\"\n\nhelp(make_accept_headers)\n```\n\n    Help on ParsedFunc in module docstrands.parsed_func:\n\n    \u003cfunction make_accept_headers\u003e\n        Calculates the the `Accept`, `Accept-Encoding` and `Accept-Language` headers based on the capacity of the HTTP client\n\n        Returns:\n            : Dictionary of HTTP headers. Keys will be automatically capitalised.\n\n## Alternatives\n\nThere are other solutions to this problem.\n\nWe could choose to not use DocStrands at all, but then `post` would have\nan incomplete docstring:\n\nWe could also copy the entire docstring from `get` and add it to `post`\nalong with the extra `body` parameter, but then we would have to keep\nboth docstrings in sync.\n\nFinally, it is possible to link between docstrings using cross\nreferences (e.g. in\n[Sphinx](https://www.sphinx-doc.org/en/master/usage/referencing.html) or\n[`mkdocstrings`](https://mkdocstrings.github.io/usage/#cross-references)).\nFirstly, this only shows up in your final HTML documentation: standard\nPython functions like `help()` don’t understand this. Secondly, it can\nbe frustrating to read documentation that sends you to several other\npages just to understand one function. In contrast, DocStrands keeps\neverything all in one place.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultimeric%2Fdocstrands","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmultimeric%2Fdocstrands","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultimeric%2Fdocstrands/lists"}