encoders ¤
This module contains data encoders/serializers and decoders/deserializers.
The available formats are:
JSON
: see theJSONEncoder
andjson_decoder
.
Classes:
-
JSONEncoder
–JSON encoder.
Functions:
-
json_decoder
–Decode dictionaries as data classes.
JSONEncoder ¤
JSONEncoder(
*args: Any,
full: bool = False,
docstring_parser: Parser | None = None,
docstring_options: dict[str, Any] | None = None,
**kwargs: Any
)
flowchart TD
griffe.encoders.JSONEncoder[JSONEncoder]
click griffe.encoders.JSONEncoder href "" "griffe.encoders.JSONEncoder"
JSON encoder.
JSON encoders can be used directly, or through the json.dump
or json.dumps
methods.
Examples:
>>> from griffe.encoders import JSONEncoder
>>> JSONEncoder(full=True).encode(..., **kwargs)
>>> import json
>>> from griffe.encoders import JSONEncoder
>>> json.dumps(..., cls=JSONEncoder, full=True, **kwargs)
Parameters:
-
*args
(Any
, default:()
) –See
json.JSONEncoder
. -
full
(bool
, default:False
) –Whether to dump full data or base data. If you plan to reload the data in Python memory using the
json_decoder
, you don't need the full data as it can be infered again using the base data. If you want to feed a non-Python tool instead, dump the full data. -
docstring_parser
(Parser | None
, default:None
) –Deprecated. The docstring parser to use. By default, no parsing is done.
-
docstring_options
(dict[str, Any] | None
, default:None
) –Deprecated. Additional docstring parsing options.
-
**kwargs
(Any
, default:{}
) –See
json.JSONEncoder
.
Methods:
-
default
–Return a serializable representation of the given object.
json_decoder ¤
json_decoder(
obj_dict: dict[str, Any]
) -> (
dict[str, Any] | Object | Alias | Parameter | str | Expr
)
Decode dictionaries as data classes.
The json.loads
method walks the tree from bottom to top.
Examples:
>>> import json
>>> from griffe.encoders import json_decoder
>>> json.loads(..., object_hook=json_decoder)
Parameters:
Returns: