diff options
| author | CoprDistGit <infra@openeuler.org> | 2023-05-15 09:15:51 +0000 |
|---|---|---|
| committer | CoprDistGit <infra@openeuler.org> | 2023-05-15 09:15:51 +0000 |
| commit | 47d53bc719394d401179bf6cfec211552d92e1b9 (patch) | |
| tree | 5cfd062b8cf38a9d2046a6f2f52c3227ff88653c /python-api-client-pydantic.spec | |
| parent | 4f94e88d60cc4149d9c95ceb31e5c575f429436c (diff) | |
automatic import of python-api-client-pydantic
Diffstat (limited to 'python-api-client-pydantic.spec')
| -rw-r--r-- | python-api-client-pydantic.spec | 410 |
1 files changed, 410 insertions, 0 deletions
diff --git a/python-api-client-pydantic.spec b/python-api-client-pydantic.spec new file mode 100644 index 0000000..1790d9c --- /dev/null +++ b/python-api-client-pydantic.spec @@ -0,0 +1,410 @@ +%global _empty_manifest_terminate_build 0 +Name: python-api-client-pydantic +Version: 2.2.1 +Release: 1 +Summary: API Client extension for validate and transform requests / responses using pydantic. +License: MIT +URL: https://github.com/mom1/api-client-pydantic +Source0: https://mirrors.nju.edu.cn/pypi/web/packages/0c/d0/69967ca4bd5a243f6dfbb9d46db54671e170f97f624905ff925d3d4bc959/api_client_pydantic-2.2.1.tar.gz +BuildArch: noarch + +Requires: python3-api-client +Requires: python3-pydantic + +%description + + + + + +[](https://github.com/mom1/api-client-pydantic/blob/master/LICENSE) + +[](https://pypi.python.org/pypi/api-client-pydantic) +[]() + + +<a href="https://gitmoji.dev"><img src="https://img.shields.io/badge/gitmoji-%20😜%20😍-FFDD67.svg" alt="Gitmoji"></a> +<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="black"></a> + +# Python API Client Pydantic Extension + +## Installation + +```bash +pip install api-client-pydantic +``` + +## Usage + +The following decorators have been provided to validate request data and converting json straight to pydantic class. + +```python +from apiclient_pydantic import params_serializer, response_serializer, serialize, serialize_all_methods + +# serialize incoming kwargs +@params_serializer(by_alias: bool = True, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = True) + +# serialize response in pydantic class +@response_serializer(response: Optional[Type[BaseModel]] = None) + +# serialize request and response data +@serialize(response: Optional[Type[BaseModel]] = None, by_alias: bool = True, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = True) + +# wraps all local methods of a class with a specified decorator. default 'serialize' +@serialize_all_methods(decorator=serialize) +``` + +Usage: +1. Define the schema for your api in pydantic classes. + ```python + from pydantic import BaseModel, Field + + + class Account(BaseModel): + account_number: int = Field(alias='accountNumber') + sort_code: int = Field(alias='sortCode') + date_opened: datetime = Field(alias='dateOpened') + ``` + +2. Add the `@response_serializer` decorator to the api client method to transform the response +directly into your defined schema. + ```python + @response_serializer(List[Account]) + def get_accounts(): + ... + # or + @response_serializer() + def get_accounts() -> List[Account]: + ... + ``` +3. Add the `@params_serializer` decorator to the api client method to translate the incoming kwargs +into the required dict for the endpoint: + ```python + @params_serializer(AccountHolder) + def create_account(data: dict): + ... + # or + @params_serializer() + def create_account(data: AccountHolder): + # data will be exactly a dict + ... + create_account(last_name='Smith', first_name='John') + # data will be a dict {"last_name": "Smith", "first_name": "John"} + ``` +4. `@serialize` - It is a combination of the two decorators `@response_serializer` and`@params_serializer`. +5. For more convenient use, you can wrap all APIClient methods with `@serialize_all_methods`. + ```python + from apiclient import APIClient + from apiclient_pydantic import serialize_all_methods + from typing import List + + from .models import Account, AccountHolder + + + @serialize_all_methods() + class MyApiClient(APIClient): + def decorated_func(self, data: Account) -> Account: + ... + + def decorated_func_holder(self, data: AccountHolder) -> List[Account]: + ... + ``` + +## Related projects + +### apiclient-pydantic-generator + +This code generator creates a [ApiClient](https://github.com/MikeWooster/api-client) app from an openapi file. + +[apiclient-pydantic-generator](https://github.com/mom1/apiclient-pydantic-generator) + +## Mentions + +Many thanks to [JetBrains](https://www.jetbrains.com/?from=api-client-pydantic) for supplying me with a license to use their product in the development +of this tool. + + + + +%package -n python3-api-client-pydantic +Summary: API Client extension for validate and transform requests / responses using pydantic. +Provides: python-api-client-pydantic +BuildRequires: python3-devel +BuildRequires: python3-setuptools +BuildRequires: python3-pip +%description -n python3-api-client-pydantic + + + + + +[](https://github.com/mom1/api-client-pydantic/blob/master/LICENSE) + +[](https://pypi.python.org/pypi/api-client-pydantic) +[]() + + +<a href="https://gitmoji.dev"><img src="https://img.shields.io/badge/gitmoji-%20😜%20😍-FFDD67.svg" alt="Gitmoji"></a> +<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="black"></a> + +# Python API Client Pydantic Extension + +## Installation + +```bash +pip install api-client-pydantic +``` + +## Usage + +The following decorators have been provided to validate request data and converting json straight to pydantic class. + +```python +from apiclient_pydantic import params_serializer, response_serializer, serialize, serialize_all_methods + +# serialize incoming kwargs +@params_serializer(by_alias: bool = True, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = True) + +# serialize response in pydantic class +@response_serializer(response: Optional[Type[BaseModel]] = None) + +# serialize request and response data +@serialize(response: Optional[Type[BaseModel]] = None, by_alias: bool = True, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = True) + +# wraps all local methods of a class with a specified decorator. default 'serialize' +@serialize_all_methods(decorator=serialize) +``` + +Usage: +1. Define the schema for your api in pydantic classes. + ```python + from pydantic import BaseModel, Field + + + class Account(BaseModel): + account_number: int = Field(alias='accountNumber') + sort_code: int = Field(alias='sortCode') + date_opened: datetime = Field(alias='dateOpened') + ``` + +2. Add the `@response_serializer` decorator to the api client method to transform the response +directly into your defined schema. + ```python + @response_serializer(List[Account]) + def get_accounts(): + ... + # or + @response_serializer() + def get_accounts() -> List[Account]: + ... + ``` +3. Add the `@params_serializer` decorator to the api client method to translate the incoming kwargs +into the required dict for the endpoint: + ```python + @params_serializer(AccountHolder) + def create_account(data: dict): + ... + # or + @params_serializer() + def create_account(data: AccountHolder): + # data will be exactly a dict + ... + create_account(last_name='Smith', first_name='John') + # data will be a dict {"last_name": "Smith", "first_name": "John"} + ``` +4. `@serialize` - It is a combination of the two decorators `@response_serializer` and`@params_serializer`. +5. For more convenient use, you can wrap all APIClient methods with `@serialize_all_methods`. + ```python + from apiclient import APIClient + from apiclient_pydantic import serialize_all_methods + from typing import List + + from .models import Account, AccountHolder + + + @serialize_all_methods() + class MyApiClient(APIClient): + def decorated_func(self, data: Account) -> Account: + ... + + def decorated_func_holder(self, data: AccountHolder) -> List[Account]: + ... + ``` + +## Related projects + +### apiclient-pydantic-generator + +This code generator creates a [ApiClient](https://github.com/MikeWooster/api-client) app from an openapi file. + +[apiclient-pydantic-generator](https://github.com/mom1/apiclient-pydantic-generator) + +## Mentions + +Many thanks to [JetBrains](https://www.jetbrains.com/?from=api-client-pydantic) for supplying me with a license to use their product in the development +of this tool. + + + + +%package help +Summary: Development documents and examples for api-client-pydantic +Provides: python3-api-client-pydantic-doc +%description help + + + + + +[](https://github.com/mom1/api-client-pydantic/blob/master/LICENSE) + +[](https://pypi.python.org/pypi/api-client-pydantic) +[]() + + +<a href="https://gitmoji.dev"><img src="https://img.shields.io/badge/gitmoji-%20😜%20😍-FFDD67.svg" alt="Gitmoji"></a> +<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="black"></a> + +# Python API Client Pydantic Extension + +## Installation + +```bash +pip install api-client-pydantic +``` + +## Usage + +The following decorators have been provided to validate request data and converting json straight to pydantic class. + +```python +from apiclient_pydantic import params_serializer, response_serializer, serialize, serialize_all_methods + +# serialize incoming kwargs +@params_serializer(by_alias: bool = True, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = True) + +# serialize response in pydantic class +@response_serializer(response: Optional[Type[BaseModel]] = None) + +# serialize request and response data +@serialize(response: Optional[Type[BaseModel]] = None, by_alias: bool = True, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = True) + +# wraps all local methods of a class with a specified decorator. default 'serialize' +@serialize_all_methods(decorator=serialize) +``` + +Usage: +1. Define the schema for your api in pydantic classes. + ```python + from pydantic import BaseModel, Field + + + class Account(BaseModel): + account_number: int = Field(alias='accountNumber') + sort_code: int = Field(alias='sortCode') + date_opened: datetime = Field(alias='dateOpened') + ``` + +2. Add the `@response_serializer` decorator to the api client method to transform the response +directly into your defined schema. + ```python + @response_serializer(List[Account]) + def get_accounts(): + ... + # or + @response_serializer() + def get_accounts() -> List[Account]: + ... + ``` +3. Add the `@params_serializer` decorator to the api client method to translate the incoming kwargs +into the required dict for the endpoint: + ```python + @params_serializer(AccountHolder) + def create_account(data: dict): + ... + # or + @params_serializer() + def create_account(data: AccountHolder): + # data will be exactly a dict + ... + create_account(last_name='Smith', first_name='John') + # data will be a dict {"last_name": "Smith", "first_name": "John"} + ``` +4. `@serialize` - It is a combination of the two decorators `@response_serializer` and`@params_serializer`. +5. For more convenient use, you can wrap all APIClient methods with `@serialize_all_methods`. + ```python + from apiclient import APIClient + from apiclient_pydantic import serialize_all_methods + from typing import List + + from .models import Account, AccountHolder + + + @serialize_all_methods() + class MyApiClient(APIClient): + def decorated_func(self, data: Account) -> Account: + ... + + def decorated_func_holder(self, data: AccountHolder) -> List[Account]: + ... + ``` + +## Related projects + +### apiclient-pydantic-generator + +This code generator creates a [ApiClient](https://github.com/MikeWooster/api-client) app from an openapi file. + +[apiclient-pydantic-generator](https://github.com/mom1/apiclient-pydantic-generator) + +## Mentions + +Many thanks to [JetBrains](https://www.jetbrains.com/?from=api-client-pydantic) for supplying me with a license to use their product in the development +of this tool. + + + + +%prep +%autosetup -n api-client-pydantic-2.2.1 + +%build +%py3_build + +%install +%py3_install +install -d -m755 %{buildroot}/%{_pkgdocdir} +if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi +if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi +if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi +if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi +pushd %{buildroot} +if [ -d usr/lib ]; then + find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/lib64 ]; then + find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/bin ]; then + find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst +fi +if [ -d usr/sbin ]; then + find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst +fi +touch doclist.lst +if [ -d usr/share/man ]; then + find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst +fi +popd +mv %{buildroot}/filelist.lst . +mv %{buildroot}/doclist.lst . + +%files -n python3-api-client-pydantic -f filelist.lst +%dir %{python3_sitelib}/* + +%files help -f doclist.lst +%{_docdir}/* + +%changelog +* Mon May 15 2023 Python_Bot <Python_Bot@openeuler.org> - 2.2.1-1 +- Package Spec generated |
