PyTKDocs

0.16.5 · active · verified Thu Apr 16

PyTKDocs is a Python library designed to load and parse documentation for Python objects. It serves as the powerful backend for `mkdocstrings`, enabling it to extract and render API documentation directly from Python source code. It is currently at version 0.16.5 and typically releases bug fixes and minor improvements frequently, with major version bumps being less common.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Loader` and use `get_object_documentation` to extract structured documentation from a Python object. The example uses `os.path` from the standard library. For documenting your own code, ensure your package is correctly installed or discoverable in the Python path.

from pytkdocs.loader import Loader

# Example: Load documentation for a Python object
# Ensure 'your_module' is importable in your environment.
# For demonstration, we'll use a placeholder or common library if available.
# In a real scenario, you'd point to your own code.

# To make this runnable without specific external dependencies, 
# we'll create a dummy module temporarily if needed, or use a built-in concept.
# However, pytkdocs usually works on actual code.

# Let's assume a simple module structure to document:
# # my_package/my_module.py
# class MyClass:
#     """A sample class."""
#     def __init__(self, name: str): 
#         """Initialize the class."""
#         self.name = name

# For this quickstart, we'll try to document 'os.path'
# If you were documenting your own code, ensure it's in PYTHONPATH.

loader = Loader()

try:
    # Try to document a common stdlib module
    data = loader.get_object_documentation(
        objects=["os.path"],
        # You can add options like 'members', 'docstring_style', etc.
        # Example: members={"os.path": ["abspath", "join"]}
    )
    print("Successfully loaded documentation for os.path:")
    # In real usage, 'data' would be processed. Here, we just print parts.
    if data and data[0].get('members'):
        print(f"Found {len(data[0]['members'])} members.")
    else:
        print("No detailed members found (might need 'members' option or different object).")
except Exception as e:
    print(f"Could not load documentation for os.path: {e}")

# To document your own module, ensure it's importable:
# For example, if you have 'my_package.my_module.MyClass' and 'my_package' is on PYTHONPATH:
# my_own_data = loader.get_object_documentation(
#     objects=["my_package.my_module.MyClass"],
#     members={"my_package.my_module.MyClass": True} # To get all members
# )
# print(my_own_data)

view raw JSON →