# WApi: Web-Library for Python
[![PyPI version](https://badge.fury.io/py/whaox-wapi.svg)](https://badge.fury.io/py/whaox-wapi)
## Libraries used:
* [jsons](https://github.com/ramonhagenaars/jsons)
* [requests](https://github.com/psf/requests)
## Features
* Routes
* Serialization
* Params
* Auto-Complete
* Unpaking
## Installation
You can install the latest version with the command:
```commandline
pip install whaox-wapi
```
## • Routes #routes
> You can create paths as you like, splitting your client into modules
```python
@Route("https://example.com")
class WApi:
service = Service()
@Route("/wapi")
class Service:
@Route("/path")
@GET("/")
def get(self): pass
@POST("/path")
def post(self): pass
```
```python
wapi = WApi()
wapi.service.get()
# eq
requests.get("https://example.com/wapi/path/")
```
## • Serialization
> The library deserializes the received data according to the type that you specify in the \_T parameter of the decorator.
>
> NOTE: The specified type must be json serializable - these are the base types and classes marked with the @dataclass annotation
```python
@dataclass
class Person:
name: str
@Route("https://example.com")
class WApi:
@GET("/person", _T=Person)
def person(self) -> Person: pass
@GET("/people", _T=List[Person])
def people(self) -> List[Person]: pass
```
```python
api = WApi()
person = api.person()
print(person.name)
>>> "John"
```
## • Params
> You can flexibly add parameters to the path using {}. The library uses formatting from the standard library.
```python
@Route("https://example.com")
class WApi:
@GET("/path?name={name}")
def route(self, name: str): pass
```
### • • Auto-complete
> If you want the parameters to be set automatically, you can switch the auto flag to True.
>
> NOTE: if auto=True, you must pass named parameters so that they are added to the path.
```python
@Route("https://example.com")
class WApi:
@GET("/path", auto=True) # eq /path?name={name}
def route(self, name: str): pass
```
### • • Unpacking
> In order not to pass a lot of parameters, you can pass one by calling it body, it will automatically decompose into parameters, to do this, set the unpack flag to True.
>
> NOTE: Nested non-standard type parameters are not decomposed.
```python
@dataclass
class Person:
name: str
age: int
@Route("https://example.com")
class WApi:
@GET("/path", auto=True, unpack=True) # eq /path?name={name}&age={age}
def route(self, body: Person): pass
```
Raw data
{
"_id": null,
"home_page": "https://github.com/topanim/WApi",
"name": "whaox-wapi",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "python, web, api, requests, post, get, put, patch, delete, rest",
"author": "WHAOX",
"author_email": "gorogannisan641@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b0/5c/7e99ca531ce56f678fbab039537b3590a13969a072e28b58c8aaf1cc3c93/whaox-wapi-1.1.3.tar.gz",
"platform": null,
"description": "\r\n# WApi: Web-Library for Python\r\n\r\n[![PyPI version](https://badge.fury.io/py/whaox-wapi.svg)](https://badge.fury.io/py/whaox-wapi)\r\n\r\n## Libraries used:\r\n* [jsons](https://github.com/ramonhagenaars/jsons)\r\n* [requests](https://github.com/psf/requests) \r\n\r\n## Features\r\n\r\n* Routes\r\n* Serialization\r\n* Params\r\n\t* Auto-Complete\r\n\t* Unpaking\r\n## Installation\r\n\r\n You can install the latest version with the command:\r\n \r\n```commandline\r\npip install whaox-wapi\r\n```\r\n\r\n## \u2022 Routes #routes\r\n\r\n> You can create paths as you like, splitting your client into modules\r\n\r\n```python\r\n\r\n@Route(\"https://example.com\")\r\nclass WApi:\r\n service = Service()\r\n\r\n@Route(\"/wapi\")\r\nclass Service:\r\n\r\n @Route(\"/path\")\r\n @GET(\"/\")\r\n def get(self): pass\t\r\n\r\n @POST(\"/path\")\r\n def post(self): pass\r\n```\r\n\r\n```python \r\nwapi = WApi()\r\nwapi.service.get()\r\n# eq\r\nrequests.get(\"https://example.com/wapi/path/\")\r\n```\r\n\r\n## \u2022 Serialization\r\n\r\n> The library deserializes the received data according to the type that you specify in the \\_T parameter of the decorator. \r\n> \r\n> NOTE: The specified type must be json serializable - these are the base types and classes marked with the @dataclass annotation\r\n\r\n```python\r\n\r\n@dataclass\r\nclass Person:\r\n\tname: str\r\n\r\n@Route(\"https://example.com\")\r\nclass WApi:\r\n\r\n @GET(\"/person\", _T=Person)\r\n def person(self) -> Person: pass\r\n\r\n @GET(\"/people\", _T=List[Person])\r\n def people(self) -> List[Person]: pass\r\n\r\n```\r\n\r\n```python\r\napi = WApi()\r\nperson = api.person()\r\n\r\nprint(person.name)\r\n>>> \"John\"\r\n```\r\n\r\n## \u2022 Params\r\n\r\n> You can flexibly add parameters to the path using {}. The library uses formatting from the standard library.\r\n\r\n```python\r\n@Route(\"https://example.com\")\r\nclass WApi:\r\n\r\n @GET(\"/path?name={name}\")\r\n def route(self, name: str): pass\r\n```\r\n\r\n\r\n### \u2022 \u2022 Auto-complete\r\n\r\n> If you want the parameters to be set automatically, you can switch the auto flag to True.\r\n> \r\n> NOTE: if auto=True, you must pass named parameters so that they are added to the path.\r\n\r\n```python\r\n\r\n@Route(\"https://example.com\")\r\nclass WApi:\r\n\r\n @GET(\"/path\", auto=True) # eq /path?name={name}\r\n def route(self, name: str): pass\r\n```\r\n\r\n### \u2022 \u2022 Unpacking\r\n\r\n> In order not to pass a lot of parameters, you can pass one by calling it body, it will automatically decompose into parameters, to do this, set the unpack flag to True.\r\n> \r\n> NOTE: Nested non-standard type parameters are not decomposed.\r\n\r\n```python\r\n\r\n@dataclass\r\nclass Person:\r\n name: str\r\n age: int \r\n\r\n\r\n@Route(\"https://example.com\")\r\nclass WApi:\r\n\r\n @GET(\"/path\", auto=True, unpack=True) # eq /path?name={name}&age={age}\r\n def route(self, body: Person): pass\r\n```\r\n",
"bugtrack_url": null,
"license": "MIT LICENSE, see LICENSE file",
"summary": "Web-Library for Python",
"version": "1.1.3",
"project_urls": {
"Homepage": "https://github.com/topanim/WApi"
},
"split_keywords": [
"python",
" web",
" api",
" requests",
" post",
" get",
" put",
" patch",
" delete",
" rest"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b05c7e99ca531ce56f678fbab039537b3590a13969a072e28b58c8aaf1cc3c93",
"md5": "327c0c6d5da3246a1353af24a8f4945e",
"sha256": "ae8b6d25c4c1c7cfd764aabb7cf61c1ad3c45394ac339a301d371c5273ba1ad5"
},
"downloads": -1,
"filename": "whaox-wapi-1.1.3.tar.gz",
"has_sig": false,
"md5_digest": "327c0c6d5da3246a1353af24a8f4945e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 7000,
"upload_time": "2024-05-18T05:09:49",
"upload_time_iso_8601": "2024-05-18T05:09:49.084695Z",
"url": "https://files.pythonhosted.org/packages/b0/5c/7e99ca531ce56f678fbab039537b3590a13969a072e28b58c8aaf1cc3c93/whaox-wapi-1.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-18 05:09:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "topanim",
"github_project": "WApi",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "whaox-wapi"
}