0.0.4 - This version is safe to use because it has no known security vulnerabilities at this time. Find out if your coding project uses this component and get notified of any reported security vulnerabilities with Meterian-X Open Source Security Platform
Maintain your licence declarations and avoid unwanted licences to protect your IP the way you intended.
MIT - MIT LicenseDocument parameters, class attributes, return types, and variables inline, with Annotated.
pip install annotated-docOr with uv:
uv add annotated-docImport 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.
annotated-doc was made for:
annotated-doc is supported by griffe-typingdoc, which powers reference documentation like the one in the FastAPI Reference.
You are already comfortable with one of the existing docstring formats, like:
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.
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.
This project is licensed under the terms of the MIT license.