Skip to main content

Crate pydocstring

Crate pydocstring 

Source
Expand description

§pydocstring

A fast, zero-dependency Rust parser for Python docstrings with full AST and source location tracking. Supports NumPy and Google styles.

§Quick Start

use pydocstring::parse::numpy::{parse_numpy, NumPyDocstring};

let docstring = r#"
Brief description.

Parameters
----------
x : int
    The first parameter.
"#;

let result = parse_numpy(docstring);
let doc = NumPyDocstring::cast(result.root()).unwrap();
assert_eq!(doc.summary().unwrap().text(result.source()), "Brief description.");

§Style Auto-Detection

use pydocstring::parse::{detect_style, Style};

let numpy_doc = "Summary.\n\nParameters\n----------\nx : int\n    Desc.";
assert_eq!(detect_style(numpy_doc), Style::NumPy);

let google_doc = "Summary.\n\nArgs:\n    x: Desc.";
assert_eq!(detect_style(google_doc), Style::Google);

§Features

  • Zero external dependencies — pure Rust
  • Accurate source spans (byte offsets) on every AST node
  • NumPy style: fully supported
  • Google style: fully supported

Modules§

emit
Emit (code generation) from the style-independent document model.
model
Style-independent document model (IR) for docstrings.
parse
Docstring style implementations.
syntax
Unified syntax tree types.
text
Source location types (offset-only).