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::numpy::parse_numpy;

let docstring = r#"
Brief description.

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

let result = parse_numpy(docstring);
assert_eq!(result.summary.source_text(&result.source), "Brief description.");

§Style Auto-Detection

use pydocstring::{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

Re-exports§

pub use ast::LineIndex;
pub use ast::Style;
pub use ast::TextRange;
pub use ast::TextSize;
pub use parser::detect_style;
pub use styles::google;
pub use styles::google::GoogleArg;
pub use styles::google::GoogleAttribute;
pub use styles::google::GoogleDocstring;
pub use styles::google::GoogleDocstringItem;
pub use styles::google::GoogleException;
pub use styles::google::GoogleMethod;
pub use styles::google::GoogleReturns;
pub use styles::google::GoogleSection;
pub use styles::google::GoogleSectionBody;
pub use styles::google::GoogleSectionHeader;
pub use styles::google::GoogleSectionKind;
pub use styles::google::GoogleSeeAlsoItem;
pub use styles::google::GoogleWarning;
pub use styles::numpy;
pub use styles::numpy::NumPyAttribute;
pub use styles::numpy::NumPyDeprecation;
pub use styles::numpy::NumPyDocstring;
pub use styles::numpy::NumPyDocstringItem;
pub use styles::numpy::NumPyException;
pub use styles::numpy::NumPyMethod;
pub use styles::numpy::NumPyParameter;
pub use styles::numpy::NumPyReference;
pub use styles::numpy::NumPyReturns;
pub use styles::numpy::NumPySection;
pub use styles::numpy::NumPySectionBody;
pub use styles::numpy::NumPySectionHeader;
pub use styles::numpy::NumPySectionKind;
pub use styles::numpy::NumPyWarning;
pub use styles::numpy::SeeAlsoItem;

Modules§

ast
Core AST types, source location primitives, and shared utilities.
parser
Top-level style detection.
styles
Docstring style implementations.