Skip to main content

Query Python package documentation for AI agents

Project description

pydocq

pydocq is a command-line interface tool for querying Python package documentation, specifically designed for AI agents. It provides structured, machine-readable JSON metadata about Python packages, classes, functions, and methods.

Features

Core Functionality

  • Path Resolution: Query any Python element using dot notation (e.g., pandas.DataFrame.merge)
  • Runtime Introspection: Extract signatures, docstrings, and source locations using Python's inspect module
  • Member Discovery: List and categorize all members of modules and classes
  • Type Annotation Parsing: Parse and analyze complex type annotations (Optional, Union, generics)
  • AST Static Analysis: Analyze Python source code without importing it
  • Search Functionality: Search elements by name pattern, docstring content, type, or metadata

SDK Decorators

Add custom metadata to your code using decorators:

  • @metadata(**kwargs): Add arbitrary metadata
  • @example(code, description): Add code examples
  • @deprecated(reason, since, version): Mark as deprecated
  • @param(name, **info): Document parameters
  • @returns(**info): Document return values
  • @category(*categories): Categorize elements
  • @tag(*tags): Add tags
  • @when(version, condition): Add version information
  • @note(text): Add notes
  • @author(name, email): Add author information
  • @see_also(*references): Add cross-references

Output Formats

  • json: Structured, machine-readable JSON (default)
  • raw: Human-readable text format
  • signature: Minimal signature-only output
  • markdown: Markdown documentation format
  • yaml: YAML structure

Installation

pip install pydocq

Usage

Basic Query

# Query a module
pydocq json

# Query a function
pydocq json.dumps

# Query a class
pydocq pandas.DataFrame

# Query a method
pydocq pandas.DataFrame.merge

Output Options

# Verbose output (includes SDK metadata)
pydocq --verbose my_package.MyClass

# Compact output (only path, type, module_path)
pydocq --compact json.dumps

# Include source location
pydocq --include-source os.path.join

# Include SDK metadata
pydocq --include-metadata my_module.my_func

# Exclude docstring or signature
pydocq --no-docstring json.dumps
pydocq --no-signature json.dumps

Output Formats

# JSON (default)
pydocq --format json json.dumps

# Raw text format
pydocq --format raw json.dumps

# Signature only
pydocq --format signature json.dumps

# Markdown format
pydocq --format markdown pandas.DataFrame

# YAML format
pydocq --format yaml json.dumps

Member Discovery

# List all members of a module
pydocq --list-members json

# List all members including private ones
pydocq --list-members --include-private json

# List class members
pydocq --list-members builtins.str

# List class members including inherited
pydocq --list-members --include-inherited my_package.MyClass

Using SDK Decorators

from pydocq import metadata, example, deprecated, tag

@metadata(category="api", version="1.0")
@tag("important", "stable")
@example("result = my_function(42)", "Basic usage")
@deprecated("Use new_function instead", since="1.0", version="2.0")
def my_function(x: int) -> int:
    """Process an integer value.

    Args:
        x: The input value

    Returns:
        The processed value
    """
    return x * 2

Query with metadata:

pydocq --include-metadata my_module.my_function

Output:

{
  "path": "my_module.my_function",
  "type": "function",
  "module_path": "my_module",
  "signature": {
    "parameters": [
      {
        "name": "x",
        "kind": "POSITIONAL_OR_KEYWORD",
        "annotation": "int",
        "default": null
      }
    ],
    "return_type": "int"
  },
  "docstring": {
    "docstring": "Process an integer value...",
    "length": 123
  },
  "sdk_metadata": {
    "category": "api",
    "version": "1.0",
    "tags": ["important", "stable"],
    "example": {"code": "result = my_function(42)", "description": "Basic usage"},
    "deprecated": {"reason": "Use new_function instead", "since": "1.0", "version": "2.0"}
  }
}

Development

Setup

# Clone the repository
git clone https://github.com/yourusername/pydocq.git
cd pydocq

# Install with uv
uv pip install -e .

# Or with pip
pip install -e .

Running Tests

# Install development dependencies
uv pip install pytest pytest-cov

# Run tests
pytest

# Run tests with coverage
pytest --cov=pydocq --cov-report=html

Building for Distribution

# Build with uv
uv build

# Or with pip
python -m build

# The built package will be in dist/

Project Structure

pydocq/
├── pydocq/
│   ├── __init__.py
│   ├── cli.py              # CLI interface
│   ├── analyzer/
│   │   ├── resolver.py      # Path resolution
│   │   ├── inspector.py     # Runtime introspection
│   │   ├── formatter.py     # JSON formatting
│   │   ├── discovery.py     # Member discovery
│   │   ├── errors.py        # Error handling
│   │   ├── type_parser.py   # Type annotation parsing
│   │   ├── ast_analyzer.py  # AST static analysis
│   │   ├── output_formats.py # Output formatters
│   │   └── search.py        # Search functionality
│   └── sdk/
│       ├── __init__.py
│       └── decorators.py     # SDK decorators
├── tests/
│   ├── test_cli.py
│   ├── test_resolver.py
│   ├── test_inspector.py
│   ├── test_formatter.py
│   ├── test_discovery.py
│   ├── test_errors.py
│   ├── test_type_parser.py
│   ├── test_ast_analyzer.py
│   ├── test_output_formats.py
│   ├── test_sdk_decorators.py
│   └── test_search.py
├── docs/                    # Internal documentation
├── README.md
├── LICENSE
├── pyproject.toml
└── .python-version

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Built with:

  • Typer for CLI interface
  • Python's inspect module for runtime introspection
  • Python's AST module for static analysis
  • pytest for testing

Changelog

0.1.0 (Unreleased)

  • Initial release
  • Path resolution for Python packages
  • Runtime introspection with inspect module
  • Member discovery for modules and classes
  • Type annotation parsing
  • AST static analysis
  • SDK decorators for custom metadata
  • Search functionality
  • Multiple output formats (JSON, raw, signature, markdown, YAML)
  • Comprehensive test coverage (178 tests)

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

pydocq-0.1.0.tar.gz (98.4 kB view details)

Uploaded Source

Built Distribution

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

pydocq-0.1.0-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pydocq-0.1.0.tar.gz
  • Upload date:
  • Size: 98.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pydocq-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d392fa3d4d018a2b6716a018d50c2bf87d277e931c67c2344892185e7968bbdb
MD5 980edc4c7bb56ee6c5a956b4f30180e2
BLAKE2b-256 369875be2c7325c35fcd1fe664bb981cc89d72f71fde7ce7f3f4fe6b48864e64

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pydocq-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pydocq-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7eb3f2b6a5c432e711072b36dbfde2511003c219ccd9b0c3e23ad8d2407fcb51
MD5 e7ae5b6c57741fdbc3babeaaf6953f79
BLAKE2b-256 841f3aea46d1fac6459136ecea168c852ee0b568b9a72d7efddfd10853642b9e

See more details on using hashes here.

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