whaox-wapi


Namewhaox-wapi JSON
Version 1.1.6 PyPI version JSON
download
home_pagehttps://github.com/topanim/WApi
SummaryWeb-Library for Python
upload_time2024-06-25 11:32:15
maintainerNone
docs_urlNone
authorWHAOX
requires_pythonNone
licenseMIT LICENSE, see LICENSE file
keywords python web api requests aiohttp post get put patch delete rest
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# WApi: Library to simplify api development

[![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)
* [aiohttp](https://github.com/aio-libs/aiohttp)

## Features

* Routes
* Serialization
* Asynchrony
* Request Params
	* Smart substitution

## Installation

 You can install the latest version with the command:
 
```commandline
pip install whaox-wapi
```

## • Routes

> You can create paths as you like, splitting your api-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"
```

## • Asynchrony

> You can make the query asynchronous simply by adding an `async` keyword.

```python
@Route("https://example.com")
class WApi:

  @GET("/person")
  async def person(self): pass

```
```python
person = await api.person(params={"id": 1})
```

## • Request Params

> You can flexibly add parameters to request passing relevant attributes.

```python
@dataclass
class GetPersonRequest:
  id: int
  
@dataclass
class CreatePersonRequest:
  name: str


@Route("https://example.com")
class WApi:

  @POST("/person")
  def create_person(self, body: dict): pass
	
  @Route("/person") 
  @GET("/")
  def person(self, params: GetPersonRequest | dict): pass

```
```python
api.person(params={"id": 1})
api.create_person(body={"name": "john"})
# or
api.person(params=GetPersonRequest(1))
api.create_person(params=CreatePersonRequest("john"))
```


### • • Smart substitution

> The library understands what variables you used during formatting and will not substitute them into the path parameters.

```python
@dataclass
class GetPersonRequest:
    id: int
    preview: bool

@Route("https://example.com")
class WApi:

  @Route("/person")
  @GET("/{id}")
  def person(self, params: GetPersonRequest): pass
```

```python
person = api.person(params=GetPersonRequest(1, true))
# eq
person = requests.get("https://example.com/person/1?preview=true")
```


            

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, aiohttp, post, get, put, patch, delete, rest",
    "author": "WHAOX",
    "author_email": "gorogannisan641@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/cd/72/36b1ab74b72858c8ed973db6695742eec7879b3a36be3130066acbb49d28/whaox-wapi-1.1.6.tar.gz",
    "platform": null,
    "description": "\r\n# WApi: Library to simplify api development\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* [aiohttp](https://github.com/aio-libs/aiohttp)\r\n\r\n## Features\r\n\r\n* Routes\r\n* Serialization\r\n* Asynchrony\r\n* Request Params\r\n\t* Smart substitution\r\n\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\r\n\r\n> You can create paths as you like, splitting your api-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  name: 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 Asynchrony\r\n\r\n> You can make the query asynchronous simply by adding an `async` keyword.\r\n\r\n```python\r\n@Route(\"https://example.com\")\r\nclass WApi:\r\n\r\n  @GET(\"/person\")\r\n  async def person(self): pass\r\n\r\n```\r\n```python\r\nperson = await api.person(params={\"id\": 1})\r\n```\r\n\r\n## \u2022 Request Params\r\n\r\n> You can flexibly add parameters to request passing relevant attributes.\r\n\r\n```python\r\n@dataclass\r\nclass GetPersonRequest:\r\n  id: int\r\n  \r\n@dataclass\r\nclass CreatePersonRequest:\r\n  name: str\r\n\r\n\r\n@Route(\"https://example.com\")\r\nclass WApi:\r\n\r\n  @POST(\"/person\")\r\n  def create_person(self, body: dict): pass\r\n\t\r\n  @Route(\"/person\") \r\n  @GET(\"/\")\r\n  def person(self, params: GetPersonRequest | dict): pass\r\n\r\n```\r\n```python\r\napi.person(params={\"id\": 1})\r\napi.create_person(body={\"name\": \"john\"})\r\n# or\r\napi.person(params=GetPersonRequest(1))\r\napi.create_person(params=CreatePersonRequest(\"john\"))\r\n```\r\n\r\n\r\n### \u2022 \u2022 Smart substitution\r\n\r\n> The library understands what variables you used during formatting and will not substitute them into the path parameters.\r\n\r\n```python\r\n@dataclass\r\nclass GetPersonRequest:\r\n    id: int\r\n    preview: bool\r\n\r\n@Route(\"https://example.com\")\r\nclass WApi:\r\n\r\n  @Route(\"/person\")\r\n  @GET(\"/{id}\")\r\n  def person(self, params: GetPersonRequest): pass\r\n```\r\n\r\n```python\r\nperson = api.person(params=GetPersonRequest(1, true))\r\n# eq\r\nperson = requests.get(\"https://example.com/person/1?preview=true\")\r\n```\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT LICENSE, see LICENSE file",
    "summary": "Web-Library for Python",
    "version": "1.1.6",
    "project_urls": {
        "Homepage": "https://github.com/topanim/WApi"
    },
    "split_keywords": [
        "python",
        " web",
        " api",
        " requests",
        " aiohttp",
        " post",
        " get",
        " put",
        " patch",
        " delete",
        " rest"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cd7236b1ab74b72858c8ed973db6695742eec7879b3a36be3130066acbb49d28",
                "md5": "4a406afc823a1fb91db28ba65dbc243a",
                "sha256": "7cd368a53c32d1973c3f84bc7dee579de62d5c4cc90edd8478cfd0e2aefa3435"
            },
            "downloads": -1,
            "filename": "whaox-wapi-1.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "4a406afc823a1fb91db28ba65dbc243a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7467,
            "upload_time": "2024-06-25T11:32:15",
            "upload_time_iso_8601": "2024-06-25T11:32:15.163201Z",
            "url": "https://files.pythonhosted.org/packages/cd/72/36b1ab74b72858c8ed973db6695742eec7879b3a36be3130066acbb49d28/whaox-wapi-1.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-25 11:32:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "topanim",
    "github_project": "WApi",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "whaox-wapi"
}
        
Elapsed time: 0.26514s