API Client extension for automatic request marshalling.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for api-client-jsonmarshal-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfae280c0295dc2413ed4f7fa54beb4778905b892a05d4f8a781110a26e90369 |
|
MD5 | 73c1f9d7187a427d7a3a0349b433c8ea |
|
BLAKE2b-256 | 9ecff696d6db203ba5f070235885c5fae6ded9adad3a92f4c1bf1c621cb9ad5f |