Skip to content

Load

langchain_core.load.dump.dumpd

dumpd(obj: Any) -> Any

Return a dict representation of an object.

Note

Unfortunately this function is not as efficient as it could be because it first dumps the object to a json string and then loads it back into a dictionary.

PARAMETER DESCRIPTION
obj

The object to dump.

TYPE: Any

RETURNS DESCRIPTION
Any

dictionary that can be serialized to json using json.dumps

langchain_core.load.dump.dumps

dumps(obj: Any, *, pretty: bool = False, **kwargs: Any) -> str

Return a json string representation of an object.

PARAMETER DESCRIPTION
obj

The object to dump.

TYPE: Any

pretty

Whether to pretty print the json. If True, the json will be indented with 2 spaces (if no indent is provided as part of kwargs).

TYPE: bool DEFAULT: False

**kwargs

Additional arguments to pass to json.dumps

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
str

A json string representation of the object.

RAISES DESCRIPTION
ValueError

If default is passed as a kwarg.

langchain_core.load.load.load

load(
    obj: Any,
    *,
    secrets_map: dict[str, str] | None = None,
    valid_namespaces: list[str] | None = None,
    secrets_from_env: bool = True,
    additional_import_mappings: dict[tuple[str, ...], tuple[str, ...]] | None = None,
    ignore_unserializable_fields: bool = False,
) -> Any

Revive a LangChain class from a JSON object.

Use this if you already have a parsed JSON object, eg. from json.load or orjson.loads.

PARAMETER DESCRIPTION
obj

The object to load.

TYPE: Any

secrets_map

A map of secrets to load. If a secret is not found in the map, it will be loaded from the environment if secrets_from_env is True.

TYPE: dict[str, str] | None DEFAULT: None

valid_namespaces

A list of additional namespaces (modules) to allow to be deserialized.

TYPE: list[str] | None DEFAULT: None

secrets_from_env

Whether to load secrets from the environment.

TYPE: bool DEFAULT: True

additional_import_mappings

A dictionary of additional namespace mappings You can use this to override default mappings or add new mappings.

TYPE: dict[tuple[str, ...], tuple[str, ...]] | None DEFAULT: None

ignore_unserializable_fields

Whether to ignore unserializable fields.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Any

Revived LangChain objects.

langchain_core.load.load.loads

loads(
    text: str,
    *,
    secrets_map: dict[str, str] | None = None,
    valid_namespaces: list[str] | None = None,
    secrets_from_env: bool = True,
    additional_import_mappings: dict[tuple[str, ...], tuple[str, ...]] | None = None,
    ignore_unserializable_fields: bool = False,
) -> Any

Revive a LangChain class from a JSON string.

Equivalent to load(json.loads(text)).

PARAMETER DESCRIPTION
text

The string to load.

TYPE: str

secrets_map

A map of secrets to load. If a secret is not found in the map, it will be loaded from the environment if secrets_from_env is True.

TYPE: dict[str, str] | None DEFAULT: None

valid_namespaces

A list of additional namespaces (modules) to allow to be deserialized.

TYPE: list[str] | None DEFAULT: None

secrets_from_env

Whether to load secrets from the environment.

TYPE: bool DEFAULT: True

additional_import_mappings

A dictionary of additional namespace mappings You can use this to override default mappings or add new mappings.

TYPE: dict[tuple[str, ...], tuple[str, ...]] | None DEFAULT: None

ignore_unserializable_fields

Whether to ignore unserializable fields.

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Any

Revived LangChain objects.