CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pdoc

API Documentation for Python Projects with focus on simplicity and automatic HTML generation from docstrings

Pending
Overview
Eval results
Files

doc-objects.mddocs/

Documentation Objects

Object model for representing Python modules, classes, functions, and variables with their metadata, signatures, and docstrings. These objects form the core data structure that pdoc uses to represent Python code for documentation generation.

Capabilities

Base Documentation Object

Foundation class for all documentation objects, providing common attributes and methods for Python constructs.

class Doc:
    """
    Base documentation object for all Python constructs.
    
    Attributes:
    - name: str - Simple name of the object
    - qualname: str - Qualified name within module
    - fullname: str - Full dotted name including module
    - obj: Any - The actual Python object being documented
    - taken_from: tuple[str, str] - Module and qualname where defined
    """
    name: str
    qualname: str  
    fullname: str
    obj: Any
    taken_from: tuple[str, str]

Namespace Objects

Base class for containers that hold other documentation objects (modules and classes).

class Namespace(Doc):
    """
    Base class for modules and classes that contain other objects.
    
    Attributes:
    - members: dict[str, Doc] - Dictionary of contained documentation objects
    """
    members: dict[str, Doc]

Module Documentation

Represents Python modules with their contained classes, functions, and variables.

class Module(Namespace):
    """
    Module documentation object representing a Python module.
    
    Methods:
    - from_name(module_name): Create Module from module name string
    """
    
    @classmethod
    def from_name(cls, module_name: str) -> 'Module':
        """
        Create Module object from module name.
        
        Parameters:
        - module_name: str - Dotted module name or file path
        
        Returns:
        - Module: Documentation object for the module
        
        Raises:
        - ImportError: If module cannot be loaded
        """

Class Documentation

Represents Python classes with their methods, properties, and attributes.

class Class(Namespace):
    """
    Class documentation object representing a Python class.
    
    Inherits all Namespace functionality for containing methods and attributes.
    """
    pass

Function Documentation

Represents Python functions and methods with their signatures and docstrings.

class Function(Doc):
    """
    Function documentation object for functions and methods.
    
    Captures function signatures, parameters, return types, and docstrings.
    """
    pass

Variable Documentation

Represents module-level variables, class attributes, and instance variables.

class Variable(Doc):
    """
    Variable documentation object for module variables and class attributes.
    
    Handles type annotations and docstring extraction for variables.
    """
    pass

Usage Examples

Creating Documentation Objects

from pdoc.doc import Module, Class, Function

# Create module documentation from name
module_doc = Module.from_name("my_package.submodule")

# Access module contents
for name, obj in module_doc.members.items():
    print(f"{name}: {type(obj).__name__}")
    
# Get specific class from module
if "MyClass" in module_doc.members:
    class_doc = module_doc.members["MyClass"]
    if isinstance(class_doc, Class):
        # Access class methods
        for method_name, method_obj in class_doc.members.items():
            if isinstance(method_obj, Function):
                print(f"Method: {method_name}")

Working with Documentation Hierarchy

from pdoc.doc import Module

# Load module with all submodules
main_module = Module.from_name("my_package")

def walk_docs(doc_obj, level=0):
    """Recursively walk documentation objects"""
    indent = "  " * level
    print(f"{indent}{doc_obj.name} ({type(doc_obj).__name__})")
    
    if hasattr(doc_obj, 'members'):
        for member in doc_obj.members.values():
            walk_docs(member, level + 1)

walk_docs(main_module)

Accessing Object Metadata

from pdoc.doc import Module, Function

module_doc = Module.from_name("math")

# Access documentation attributes
for name, member in module_doc.members.items():
    print(f"Name: {member.name}")
    print(f"Full name: {member.fullname}")
    print(f"Qualified name: {member.qualname}")
    print(f"Taken from: {member.taken_from}")
    
    if isinstance(member, Function):
        # Access the actual Python function object
        actual_function = member.obj
        print(f"Function signature: {actual_function.__annotations__}")

Integration with Rendering

from pdoc.doc import Module
from pdoc import render

# Create documentation objects
modules = {
    "main": Module.from_name("my_package"),
    "utils": Module.from_name("my_package.utils")
}

# Render individual module
html_output = render.html_module(modules["main"], modules)

# Generate index page
index_html = render.html_index(modules)

Install with Tessl CLI

npx tessl i tessl/pypi-pdoc

docs

ast-processing.md

cli-interface.md

doc-objects.md

docstring-processing.md

html-rendering.md

index.md

main-api.md

module-extraction.md

search.md

web-server.md

tile.json