Document parameters, class attributes, return types, and variables inline, with Annotated.
Project description
Annotated Doc
Document parameters, class attributes, return types, and variables inline, with Annotated.
Installation
pip install annotated-doc
Or with uv:
uv add annotated-doc
Usage
Import Doc and pass a single literal string with the documentation for the specific parameter, class attribute, return type, or variable.
For example, to document a parameter name in a function hi you could do:
from typing import Annotated
from annotated_doc import Doc
def hi(name: Annotated[str, Doc("Who to say hi to")]) -> None:
print(f"Hi, {name}!")
You can also use it to document class attributes:
from typing import Annotated
from annotated_doc import Doc
class User:
name: Annotated[str, Doc("The user's name")]
age: Annotated[int, Doc("The user's age")]
The same way, you could document return types and variables, or anything that could have a type annotation with Annotated.
Who Uses This
annotated-doc was made for:
annotated-doc is supported by griffe-typingdoc, which powers reference documentation like the one in the FastAPI Reference.
Reasons not to use annotated-doc
You are already comfortable with one of the existing docstring formats, like:
- Sphinx
- numpydoc
- Keras
Your team is already comfortable using them.
You prefer having the documentation about parameters all together in a docstring, separated from the code defining them.
You care about a specific set of users, using one specific editor, and that editor already has support for the specific docstring format you use.
Reasons to use annotated-doc
- No micro-syntax to learn for newcomers, it’s just Python syntax.
- Editing would be already fully supported by default by any editor (current or future) supporting Python syntax, including syntax errors, syntax highlighting, etc.
- Rendering would be relatively straightforward to implement by static tools (tools that don't need runtime execution), as the information can be extracted from the AST they normally already create.
- Deduplication of information: the name of a parameter would be defined in a single place, not duplicated inside of a docstring.
- Elimination of the possibility of having inconsistencies when removing a parameter or class variable and forgetting to remove its documentation.
- Minimization of the probability of adding a new parameter or class variable and forgetting to add its documentation.
- Elimination of the possibility of having inconsistencies between the name of a parameter in the signature and the name in the docstring when it is renamed.
- Access to the documentation string for each symbol at runtime, including existing (older) Python versions.
- A more formalized way to document other symbols, like type aliases, that could use Annotated.
- Support for apps using FastAPI, Typer and others.
- AI Accessibility: AI tools will have an easier way understanding each parameter as the distance from documentation to parameter is much closer.
History
I (@tiangolo) originally wanted for this to be part of the Python standard library (in PEP 727), but the proposal was withdrawn as there was a fair amount of negative feedback and opposition.
The conclusion was that this was better done as an external effort, in a third-party library.
So, here it is, with a simpler approach, as a third-party library, in a way that can be used by others, starting with FastAPI and friends.
License
This project is licensed under the terms of the MIT license.
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
Built Distribution
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 annotated_doc-0.0.4.tar.gz.
File metadata
- Download URL: annotated_doc-0.0.4.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fbcda96e87e9c92ad167c2e53839e57503ecfda18804ea28102353485033faa4
|
|
| MD5 |
825f2ecff1f182cd942ea09907ebafdb
|
|
| BLAKE2b-256 |
57ba046ceea27344560984e26a590f90bc7f4a75b06701f653222458922b558c
|
Provenance
The following attestation bundles were made for annotated_doc-0.0.4.tar.gz:
Publisher:
publish.yml on fastapi/annotated-doc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
annotated_doc-0.0.4.tar.gz -
Subject digest:
fbcda96e87e9c92ad167c2e53839e57503ecfda18804ea28102353485033faa4 - Sigstore transparency entry: 689232280
- Sigstore integration time:
-
Permalink:
fastapi/annotated-doc@a6b2d3869f24c9c04cd7c024e59ccec3e5422a56 -
Branch / Tag:
refs/tags/0.0.4 - Owner: https://github.com/fastapi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a6b2d3869f24c9c04cd7c024e59ccec3e5422a56 -
Trigger Event:
release
-
Statement type:
File details
Details for the file annotated_doc-0.0.4-py3-none-any.whl.
File metadata
- Download URL: annotated_doc-0.0.4-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
571ac1dc6991c450b25a9c2d84a3705e2ae7a53467b5d111c24fa8baabbed320
|
|
| MD5 |
ca0b005f5bcfb025d36cba1b10c77927
|
|
| BLAKE2b-256 |
1ed326bf1008eb3d2daa8ef4cacc7f3bfdc11818d111f7e2d0201bc6e3b49d45
|
Provenance
The following attestation bundles were made for annotated_doc-0.0.4-py3-none-any.whl:
Publisher:
publish.yml on fastapi/annotated-doc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
annotated_doc-0.0.4-py3-none-any.whl -
Subject digest:
571ac1dc6991c450b25a9c2d84a3705e2ae7a53467b5d111c24fa8baabbed320 - Sigstore transparency entry: 689232317
- Sigstore integration time:
-
Permalink:
fastapi/annotated-doc@a6b2d3869f24c9c04cd7c024e59ccec3e5422a56 -
Branch / Tag:
refs/tags/0.0.4 - Owner: https://github.com/fastapi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a6b2d3869f24c9c04cd7c024e59ccec3e5422a56 -
Trigger Event:
release
-
Statement type: