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, nodes::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::{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 styles::Style;pub use styles::detect_style;pub use styles::google;pub use styles::google::GoogleSectionKind;pub use styles::numpy;pub use styles::numpy::NumPySectionKind;pub use syntax::Parsed;pub use syntax::SyntaxElement;pub use syntax::SyntaxKind;pub use syntax::SyntaxNode;pub use syntax::SyntaxToken;pub use syntax::Visitor;pub use syntax::walk;pub use text::TextRange;pub use text::TextSize;