Skip to main content

Runtime access to Python class attribute, enum member, and dataclass field docstrings

Project description

attr-docs

Runtime access to Python class attribute, enum member, and dataclass field docstrings

Installation

pip install attr-docs

Usage

Class

attr_docs import docstrings, get_docstrings

@docstrings
class Person:
    """A person with various attributes."""
    
    name: str
    """The person's full name."""

    email: str
    """Contact email address."""

    age: int = 0
    """The person's age in years."""

# Access docstrings map directly on class (IDE style)
docs = get_docstrings(Person)
print(docs["name"])    # "The person's full name."
print(docs["age"])     # "The person's age in years."
print(docs["email"])   # "Contact email address."

# Access via PEP 224 style attributes (uses Python MRO lookup)
print(Person.__doc_name__)   # "The person's full name."
print(Person.__doc_age__)    # "The person's age in years."
print(Person.__doc_email__)  # "Contact email address."

Enum

Enums support lazy parsing of member docstrings, the decorator will not add overhead until you access the docstring of a member for the first time.

from enum import Enum
attr_docs import docstrings

@docstrings
class Status(Enum):
    """Status enumeration for task tracking."""
    
    PENDING = "pending"
    """Task is waiting to be processed."""
    
    RUNNING = "running"
    """Task is currently being executed."""
    
    COMPLETED = "completed"
    """Task has finished successfully."""
    
    FAILED = "failed"
    """Task encountered an error."""

# Supports these standard class access patterns
docs = get_docstrings(Status)
print(docs["COMPLETED"])   # "Task has finished successfully."

# Access via enum member __doc__ attribute
print(Status.PENDING.__doc__)    # "Task is waiting to be processed."
print(Status.COMPLETED.__doc__)  # "Task has finished successfully."

# Iterate through all members with their documentation
for member in Status:
    if member.__doc__:
        print(f"{member.name}: {member.__doc__}")

Dataclass

from dataclasses import dataclass, fields
attr_docs import docstrings, get_docstrings

@docstrings
@dataclass
class Product:
    """A product in an e-commerce system."""
    
    name: str
    """Product name."""
    
    price: float
    """Price in USD."""

    category: str = ""
    """Product category."""
    
    description: str = ""
    """Detailed product description."""

# Supports all the standard class access patterns

# Access via dataclass field metadata
for field in fields(Product):
    if field.metadata.get("__doc__"):
        print(f"{field.name}: {field.metadata['__doc__']}")

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

attr_docs-0.3.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

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

attr_docs-0.3.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file attr_docs-0.3.0.tar.gz.

File metadata

  • Download URL: attr_docs-0.3.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for attr_docs-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f53898d3f919a001fee764307da9ee53483c68fffc2f94e7b0bafc2cbf363c21
MD5 1ddb188cc54cf705d99107d311160164
BLAKE2b-256 0ccd2adc8555b64b31fd66d0bed9783ad903dbc82a9516dd4eefb6de9b5b5d41

See more details on using hashes here.

File details

Details for the file attr_docs-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: attr_docs-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for attr_docs-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 239187588ec88457d1fd4101540ba3387e97afefb1443ec43ef450f38b4d2176
MD5 a241167b84af2bf30851097f3843316f
BLAKE2b-256 5dff83744c5171be1e723e8af3bb1d7b8f85946a5f67398520815a505e935967

See more details on using hashes here.

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