Install & Compatibility
Where this runs
tested against v2.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.222s · 20MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.5s · import 0.197s · 21MB
18MB installed
● package 18MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load a docspec-conformant JSON payload, access its structured API elements (like modules and functions), and perform basic modifications. It highlights docspec's role in handling the JSON representation of API documentation.
import docspec
from io import StringIO
# Example of a docspec-conformant JSON payload for a simple module
# In a real-world scenario, this might come from a file or from docspec-python.
example_json_input = '''
{
"name": "example_module",
"location": {"filename": "example_module.py", "lineno": 1},
"docstring": "A module demonstrating docspec structure.",
"members": [
{
"name": "my_function",
"type": "function",
"location": {"filename": "example_module.py", "lineno": 3},
"docstring": "This is a sample function.",
"args": [],
"returns": null,
"decorations": [],
"is_async": false
}
]
}
'''
# Load module(s) from a JSON string (simulating file input)
modules = docspec.load_modules(StringIO(example_json_input))
# Iterate and process loaded modules
for module in modules:
print(f"\nProcessing Module: {module.name}")
print(f" Module Docstring: {module.docstring}")
# Example: Filter members to only include those with docstrings
original_members_count = len(module.members)
module.members = [member for member in module.members if member.docstring]
print(f" Original member count: {original_members_count}")
print(f" Members with docstrings after filtering: {[m.name for m in module.members]}")
# To dump the modified module back to JSON (e.g., to stdout or a file):
# from sys import stdout
# for module in modules: # Assuming 'modules' might have multiple
# docspec.dump_module(stdout, module)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'docspec'
The 'docspec' package is not installed in your Python environment or is not accessible via the Python path.
ImportError: cannot import name 'Docstring' from 'docspec.models'
The 'Docstring' class is typically exposed directly under the 'docspec' module, not within a submodule like 'docspec.models'.
fixfrom docspec import Docstring
AttributeError: 'Docstring' object has no attribute 'text'
You are trying to access a non-existent attribute named 'text' on a `docspec.Docstring` object. The primary attribute for its content is usually `content`.
fixdocstring_object.content
Upgrade
Version history
2.2.2latest on PyPI · released May 6, 2025
Audit
Dependencies
pythonrequiredRuntime environment for the Python library.