api-client-jsonmarshal 0.0.1

Last updated:

0 purchases

api-client-jsonmarshal 0.0.1 Image
api-client-jsonmarshal 0.0.1 Images
Add to Cart

Description:

apiclientjsonmarshal 0.0.1

Python API Client Json Marshal Extension
Installation
pip install api-client-jsonmarshal

Usage
The following decorators have been provided to marshal request data as python dataclasses to json
and to unmarshal json directly into a python dataclass.
# Marshal dataclass -> json
@marshal_request(date_fmt: Optional[str] = None, datetime_fmt: Optional[str] = None)

# Unmarshal json -> dataclass
@unmarshal_response(schema: T, date_fmt: Optional[str] = None, datetime_fmt: Optional[str] = None)

Usage:

Define the schema for your api in python dataclasses.
Add the @unmarshal_response decorator to the api client method to transform the response
directly into your defined schema.
@unmarshal_response(List[Account])
def get_accounts():
...


Add the @marshal_request decorator to the api client method to translate the incoming dataclass
into the required json for the endpoint:
@marshal_request()
def create_account(account: Account):
...



The marshalling functionality has been provided by: https://github.com/MikeWooster/jsonmarshal
More usage examples can be found there.

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.