python-stub-package

Generate condensed structural stubs of Python packages showing signatures, imports, and docstrings.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill python-stub-package-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-stub-package
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/python/stub-package
Command: npx skills add https://github.com/asarchami/dotfiles --skill python-stub-package-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Reading an entire Python codebase to understand its API surface wastes time and context. This Skill produces a compact structural overview of any Python module or package, replacing function bodies with ellipses so you can grasp signatures, classes, and docstrings at a glance. ## Core Features & Use Cases - AST-Based Stub Generation: Parses Python source with the ast module to emit imports, class definitions, method signatures, module-level assignments, and docstrings with bodies replaced by .... - Package-Wide Overviews: Processes entire directories, grouping files under # === path/file.py === headers with __init__.py listed first, plus source location comments for each definition. - Flexible Filtering: Flags like --no-docstrings and --no-private control output verbosity, and --output writes results to a file. - Use Case: When onboarding to an unfamiliar library, run the stub generator on its package directory to get a single-file summary of every public class and function signature before diving into implementation details. ## Quick Start Ask the AI to run stub_package.py on a target Python file or package directory to produce a condensed structural overview of its signatures and docstrings.

Frequently Asked Questions about python-stub-package

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I generate a structural overview of a Python package?

Run stub_package.py with the path to a .py file or package directory. It parses the source with the ast module and prints signatures, imports, class attributes, and docstrings with all function bodies replaced by ellipses.

How to show only public functions in a Python stub?

Pass the --no-private flag to skip names starting with a single underscore while keeping dunder methods. Combine it with --no-docstrings for an even more compact signature-only output.

What Python version is required for ast.unparse stub generation?

The script requires Python 3.9 or newer because it relies on ast.unparse to reconstruct source text from AST nodes. Earlier versions lack this function and will raise an AttributeError.

Can I write Python stub output to a file instead of stdout?

Yes, use the --output or -o flag followed by a file path. The stub content is written to that file and a confirmation message is printed to stderr.

Why use AST-based stubs instead of reading source code directly?

AST-based stubs strip implementation details while preserving exact signatures, decorators, and docstrings, drastically reducing token count. This gives AI agents or reviewers the full API surface without the noise of function bodies.