Type stubs for PyYAML, a full-featured YAML framework for Python
npx @tessl/cli install tessl/pypi-types-pyyaml@5.4.0Type stubs for PyYAML, a full-featured YAML framework for Python. This package provides comprehensive type annotations enabling static type checking for YAML parsing and serialization operations, covering the complete YAML processing pipeline from reading to dumping with support for both safe and unsafe operations.
pip install types-PyYAMLimport yamlFor specific functionality:
from yaml import load, dump, safe_load, safe_dump
from yaml import SafeLoader, SafeDumper, FullLoader
from yaml import YAMLError, YAMLObjectimport yaml
# Safe loading (recommended for untrusted input)
data = yaml.safe_load('hello: world\nlist:\n - item1\n - item2')
print(data) # {'hello': 'world', 'list': ['item1', 'item2']}
# Safe dumping
yaml_string = yaml.safe_dump({'name': 'John', 'age': 30, 'items': [1, 2, 3]})
print(yaml_string)
# Full loading (more features, safer than unsafe)
with open('config.yaml', 'r') as file:
config = yaml.full_load(file)
# Dumping to file
with open('output.yaml', 'w') as file:
yaml.safe_dump(data, file, default_flow_style=False)PyYAML provides a complete YAML processing pipeline with multiple abstraction levels:
load, dump, safe_load, safe_dump)Core functions for loading YAML documents with different safety levels and processing modes.
def safe_load(stream) -> Any: ...
def safe_load_all(stream) -> Iterator[Any]: ...
def full_load(stream) -> Any: ...
def full_load_all(stream) -> Iterator[Any]: ...
def load(stream, Loader=None) -> Any: ...
def load_all(stream, Loader=None) -> Iterator[Any]: ...
def unsafe_load(stream) -> Any: ...
def unsafe_load_all(stream) -> Iterator[Any]: ...Core functions for serializing Python objects to YAML with different safety levels and formatting options.
def safe_dump(data, stream=None, **kwargs) -> str | None: ...
def safe_dump_all(documents, stream=None, **kwargs) -> str | None: ...
def dump(data, stream=None, Dumper=None, **kwargs) -> str | None: ...
def dump_all(documents, stream=None, Dumper=None, **kwargs) -> str | None: ...Configurable loader and dumper classes that combine different processing components for customized YAML processing.
class BaseLoader(Reader, Scanner, Parser, Composer, BaseConstructor, BaseResolver): ...
class SafeLoader(Reader, Scanner, Parser, Composer, SafeConstructor, Resolver): ...
class FullLoader(Reader, Scanner, Parser, Composer, FullConstructor, Resolver): ...
class Loader(Reader, Scanner, Parser, Composer, Constructor, Resolver): ...
class UnsafeLoader(Reader, Scanner, Parser, Composer, Constructor, Resolver): ...
class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver): ...
class SafeDumper(Emitter, Serializer, SafeRepresenter, Resolver): ...
class Dumper(Emitter, Serializer, Representer, Resolver): ...Exception classes for handling various YAML processing errors with position information and detailed error messages.
class YAMLError(Exception): ...
class MarkedYAMLError(YAMLError):
context: str | None
context_mark: Mark | None
problem: str | None
problem_mark: Mark | None
note: str | None
class Mark:
name: str
index: int
line: int
column: int
def get_snippet(self, indent=4, max_length=75) -> str: ...Base classes and utilities for creating custom YAML-serializable Python objects with automatic tag registration.
class YAMLObject(metaclass=YAMLObjectMetaclass):
yaml_loader: Any
yaml_dumper: Any
yaml_tag: Any
yaml_flow_style: Any
@classmethod
def from_yaml(cls, loader, node): ...
@classmethod
def to_yaml(cls, dumper, data): ...Functions for registering custom constructors, representers, and resolvers to extend YAML processing capabilities.
def add_constructor(tag: str, constructor: Callable, Loader=None) -> None: ...
def add_multi_constructor(tag_prefix: str, multi_constructor: Callable, Loader=None) -> None: ...
def add_representer(data_type: type, representer: Callable, Dumper=None) -> None: ...
def add_multi_representer(data_type: type, multi_representer: Callable, Dumper=None) -> None: ...
def add_implicit_resolver(tag: str, regexp: Pattern[str], first=None, Loader=None, Dumper=None) -> None: ...
def add_path_resolver(tag: str, path: Iterable[Any], kind=None, Loader=None, Dumper=None) -> None: ...Lower-level YAML processing functions for advanced use cases requiring fine-grained control over the processing pipeline.
def scan(stream, Loader=None): ...
def parse(stream, Loader=None): ...
def compose(stream, Loader=None): ...
def compose_all(stream, Loader=None): ...
def serialize(node, stream=None, Dumper=None, **kwargs): ...
def serialize_all(nodes, stream=None, Dumper=None, **kwargs): ...
def emit(events, stream=None, Dumper=None, **kwargs): ...Internal processing components for custom loader and dumper construction, including constructors, representers, resolvers, and processing pipeline components.
class BaseConstructor: ...
class SafeConstructor(BaseConstructor): ...
class FullConstructor(SafeConstructor): ...
class BaseRepresenter: ...
class SafeRepresenter(BaseRepresenter): ...
class Representer(SafeRepresenter): ...
class BaseResolver: ...
class Resolver(BaseResolver): ...High-performance C-based implementations of loaders, dumpers, and processing components for improved performance.
class CBaseLoader(CParser, BaseConstructor, BaseResolver): ...
class CLoader(CParser, SafeConstructor, Resolver): ...
class CSafeLoader(CParser, SafeConstructor, Resolver): ...
class CFullLoader(CParser, FullConstructor, Resolver): ...
class CUnsafeLoader(CParser, UnsafeConstructor, Resolver): ...
class CBaseDumper(CEmitter, BaseRepresenter, BaseResolver): ...
class CDumper(CEmitter, SafeRepresenter, Resolver): ...
class CSafeDumper(CEmitter, SafeRepresenter, Resolver): ...
# Type alias
CSafeDumper = CDumper# Module constants
__with_libyaml__: Any # Indicates whether C extensions are available
__version__: str # PyYAML version string
# Type aliases used throughout the API
_Yaml = Any # YAML data type
_Str = str | Union[Text, str] # String type for Python 2/3 compatibility
# Stream types
StreamType = Union[str, bytes, IO[str], IO[bytes], Text, IO[Text]]
# Constructor and representer type variables
_Constructor = TypeVar("_Constructor", bound=BaseConstructor)
_Representer = TypeVar("_Representer", bound=BaseRepresenter)