Skip to main content

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")]

Who Uses This

This was made for:

Reasons not to use annotated-doc

You are already comfortable with one of the existing docstring formats, like:

  • Sphinx
  • numpydoc
  • Google
  • 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, and its users.

License

This project is licensed under the terms of the MIT license.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

annotated_doc-0.0.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

annotated_doc-0.0.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file annotated_doc-0.0.2.tar.gz.

File metadata

  • Download URL: annotated_doc-0.0.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for annotated_doc-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f25664061aee278227abfaec5aeb398298be579b934758c16205d48e896e149c
MD5 7be4ea2803fdfb0aeece7b4486bedc3d
BLAKE2b-256 c4922974dba489541ed4af531d00a4df075bc3a455557d3b54fd6932c51c95cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for annotated_doc-0.0.2.tar.gz:

Publisher: publish.yml on fastapi/annotated-doc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file annotated_doc-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: annotated_doc-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for annotated_doc-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2188cb99e353fcb5c20f23b8bc6f5fa7c924b213fac733d4b44883f9edffa090
MD5 afcee667b8f1e9d24df35f62702bdd84
BLAKE2b-256 bdeecc5109cdd46a6ccd3d923db3c5425383abe51b5c033647aad1b5e2452e82

See more details on using hashes here.

Provenance

The following attestation bundles were made for annotated_doc-0.0.2-py3-none-any.whl:

Publisher: publish.yml on fastapi/annotated-doc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page