marsh
¶
Root of the marsh framework.
Exposes the basic functionality and modules of the framework.
- unmarshal(type_: Type[_T], element: Union[None, int, float, bool, str, Sequence[Any], Mapping[str, Any]] = marsh.MISSING) _T [source]¶
- unmarshal(type_: Type[_T], element: Mapping[str, ElementType] = marsh.MISSING, **kwargs) _T
Unmarshal a JSON-like object to some type.
Note
Static type checkers may give an error for abstract types (issue).
Some type aliases are also not recognized as types. For the moment there is not better solution than using a simple
# type: ignore
comment.
- cast(type_, value='???')[source]¶
Cast a value to some type. The input value is serialized to a JSON-like object and then used for constructing an instance of the specified type.
Note
Static type checkers may give an error for abstract types (issue).
Some type aliases are also not recognized as types. For the moment there is not better solution than using a simple
# type: ignore
comment.
- unmarshal_args(callable_, element='???')[source]¶
Return the unmarshaled arguments of the given function.
- cast_args(callable_, value='???')[source]¶
Return the casted arguments of the given function.
The given input will be marshaled before being unmarshaled into the function arguments.
- main(*, setup_logging: bool = False, prog: Optional[str] = None, description: Optional[str] = None, epilog: Optional[str] = None, help_depth: int = 1) Callable[[_C], _C] [source]¶
- main(fn: _C, /, *, setup_logging: bool = False, prog: Optional[str] = None, description: Optional[str] = None, epilog: Optional[str] = None, help_depth: int = 1) _C
- main(*, config: Type[_T], setup_logging: bool = False, prog: Optional[str] = None, description: Optional[str] = None, epilog: Optional[str] = None, help_depth: int = 1) Callable[[Callable[[_T], _R]], Callable[[_T], _R]]
- main(fn: Callable[[_T], _R], /, *, config: Type[_T], setup_logging: bool = False, prog: Optional[str] = None, description: Optional[str] = None, epilog: Optional[str] = None, help_depth: int = 1) Callable[[_T], _R]
Decorates a function, allowing it to be called as an entry point for a python script being run from the command line.
If a config class is supplied, the decorated function will be passed an instance of that class as a single positional argument. If no config class is supplied, the arguments for the decorated function are filled out and passed to the function.
- Parameters:
fn – The callable function to decorate. When decorating, this argument should not be explicitly specified.
setup_loggin – Add console line arguments for logging level and format. Initiallizes logging through
logging.basicConfig()
.prog (
Optional
[str
]) – Optional program name. Defaults to the first value ofsys.argv
.description (
Optional
[str
]) – Optional description shown in the help message. Defaults to the docstring of the decorated function (or the config class if passed to the decorator). Can be set toNone
to disable completely.epilog (
Optional
[str
]) – Optional epilog shown in the help message.help_depth (
int
) – How many subfields of a config to flatten for--help [PATH]
.
- Returns:
The wrapped function.
- MISSING¶
Represents the missing value, i.e. when a value is unset (which is not equivalent to a value being
None
).Useful for when a default value is required by python even though there should not be one.
marsh
treats this the same as if there were no default value.The concrete value of
MISSING
is the string'???'
.See marsh.MISSING for more info.
- namespaces: marsh.schema.namespace.Namespaces¶
Gives access to all namespaces. Also allows for new namespaces to be created through its
new(...)
method.