Skip to main content

Runtime access to Python class attribute docstrings (PEP 224)

Project description

runtime-docstrings

Runtime access to Python class attribute docstrings (PEP 224)

Installation

pip install runtime-docstrings

Usage

Class

from runtime_docstrings 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

from enum import Enum
from runtime_docstrings 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 all the standard class access patterns

# 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
from runtime_docstrings 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

runtime_docstrings-0.1.0.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

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

runtime_docstrings-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file runtime_docstrings-0.1.0.tar.gz.

File metadata

  • Download URL: runtime_docstrings-0.1.0.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for runtime_docstrings-0.1.0.tar.gz
Algorithm Hash digest
SHA256 756daa1c38eaaf86a9f6e134b63a55641ecb55813044bf20f0f7de4790365ddf
MD5 baed667bfd0bac7d9e2cacc8d22f4c5a
BLAKE2b-256 6fc3764713f967d89bc10b0aaad9b87ace4469576f07b0be2d16e951d6510563

See more details on using hashes here.

Provenance

The following attestation bundles were made for runtime_docstrings-0.1.0.tar.gz:

Publisher: publish.yml on gesslerpd/runtime-docstrings

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

File details

Details for the file runtime_docstrings-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for runtime_docstrings-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40f63a9a76f3ac7e1723e01efdd35ad049c11ad1a2a9e309676bbd2f6f6f6fa9
MD5 bc9bd3bc638e8c4c321388bd21a8b753
BLAKE2b-256 0118d9ef055bd15a66ac89b98a9559cc1d12470b67449ce1f2f71bd723b79050

See more details on using hashes here.

Provenance

The following attestation bundles were made for runtime_docstrings-0.1.0-py3-none-any.whl:

Publisher: publish.yml on gesslerpd/runtime-docstrings

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