Skip to main content

make wrapper for RESTful API

Project description

apywrapper

Easy development of RESTful API wrapper

install

pip install apywrapper

Example (Chatwork API Wrapper)

from apywrapper import Apy
from dataclasses import dataclass

api = Apy(
    "https://api.chatwork.com/v2",
    headers={"X-ChatWorkToken": "xxxxxxxxx"},
)


@dataclass
class Room:
    room_id: int
    name: str
    type: str
    role: str
    sticky: bool
    unread_num: int
    mention_num: int
    mytask_num: int
    message_num: int
    file_num: int
    task_num: int
    icon_path: str
    last_update_time: int


@api.get("/rooms/{room_id}")
def get_room(room_id: int):
    return (
        Room,
        {"room_id": room_id},
    )  # Return Object, Request Params(Path Args, Query or JsonData(Dict))


@api.get("/rooms")
def get_rooms():
    return Room, {}


print(get_room(113377551))  # return Room
print(get_rooms()) # return List[Room]

Example (POST data)

@api.post("/users")
def create_user(username: str, user_id: str):
    return User, {"user_name": username, "user_id": user_id}

created_user = create_user("sh1ma", "sh1ma")

Example (GET with is_hello query)

@api.get("/users/{user_id}")
def get_user(user_id: str, is_hello: bool):
    return User, {"user_id": user_id, "is_hello": True}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apywrapper-0.1.5.tar.gz (16.1 kB view hashes)

Uploaded Source

Built Distribution

apywrapper-0.1.5-py3-none-any.whl (16.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page