I made a Python Qiita API wrapper "qiipy"

TL;DR

--Qiita's API wrapper library "qiipy" has been created. --Unfinished --You can easily develop an API wrapper library with your own library "apywrapper". --____ [Important] We are looking for contributors! !! !! !! Those who want to contribute to OSS [Important] __ (I want you to cooperate at the end of the article)

I made qiipy

Why did you make it?

The other day, I made my own library called apywrapper that can easily develop API wrappers, so I wanted to test its power.

Development environment

Dependence

What kind of code did you write

The code I actually wrote is ~~~~

First, define the model like this ...

from typing import Optional
from dataclasses import dataclass


@dataclass
class User:
    id: str
    permanent_id: int
    name: str
    profile_image_url: str
    team_only: bool
    followees_count: int
    followers_count: int
    items_count: int
    description: Optional[str] = None
    organization: Optional[str] = None
    location: Optional[str] = None
    facebook_id: Optional[str] = None
    github_login_name: Optional[str] = None
    linkedin_id: Optional[str] = None
    twitter_screen_name: Optional[str] = None
    website_url: Optional[str] = None


@dataclass
class Comment:
    body: str
    created_at: str
    id: str
    rendered_body: str
    updated_at: str
    user: User

After that, it feels like defining an API (you don't have to worry about parameters such as queries, path variables, json, etc.)

from apywrapper import Apy, get, post, delete, patch
from ._models import Comment


class Qiipy(Apy):
    def __init__(self, access_token: str, host: str = "https://qiita.com/api/v2"):
        super().__init__(host=host, headers={"Authorization": f"Bearer {access_token}"})

    @get("/comments/{comment_id}")
    def get_comment(self, comment_id: str):
        """Get comments

        Args:
            comment_id:Comment id
        Returns:
            Comment
        """
        return Comment, {"comment_id": comment_id}

    @delete("/comments/{comment_id}")
    def delete_comment(self, comment_id: str):
        """Delete comment

        Args:
            comment_id:Comment id
        Returns:
            None
        """
        return None, {"comment_id": comment_id}
   ...

that's all! w

If you explain the code for the time being

@method("/path/to/api") #api path
def get_something(self, item_id: str):
  	return Something, {"item_id": item_id} 
  	#in this case`item_id`Becomes a query(Because there are no variables in the path)
    #The return value is`Something`object

How to use

from qiipy import Qiipy
qiita = Qiipy(access_token="xxx")
qiita.get_comment("zzzzzzzzz") #Comment object is returned

Feeling like

I want you to cooperate

--Definition of entity (model) (https://github.com/sh1ma/qiipy/blob/master/qiipy/_models.py) --Bug Report (https://github.com/sh1ma/qiipy/issues) --Definition of function to hit API (https://github.com/sh1ma/qiipy/blob/master/qiipy/_api.py) --Other advice

I look forward to working with you.

Recommended Posts

I made a Python Qiita API wrapper "qiipy"
I made a Python wrapper library for docomo image recognition API.
Created a Python wrapper for the Qiita API
I made a python text
I made a Line-bot using Python!
I made a fortune with Python.
I made a daemon with Python
kabu Station® API-I made a Python wrapper for REST API
I made a Chatbot using LINE Messaging API and Python
I made a payroll program in Python!
I made a character counter with Python
I made a Hex map with Python
After studying Python3, I made a Slackbot
I made a roguelike game with Python
I made a configuration file with Python
I made a Twitter Bot with Go x Qiita API x Lambda
I made a Chatbot using LINE Messaging API and Python (2) ~ Server ~
I made a python dictionary file for Neocomplete
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I made a GUI application with Python + PyQt5
I made a Twitter fujoshi blocker with Python â‘ 
[Python] I made a Youtube Downloader with Tkinter.
[IOS] I made a widget that displays Qiita trends in Pythonista3. [Python]
I made a Caesar cryptographic program in Python.
I made a bin picking game with Python
I made a Mattermost bot with Python (+ Flask)
I made a Twitter BOT with GAE (python) (with a reference)
I made a prime number generation program in Python
I made a login / logout process using Python Bottle.
I made a Christmas tree lighting game with Python
I made a net news notification app with Python
I made a Python module to translate comment outs
I made a Python3 environment on Ubuntu with direnv.
I made a LINE BOT with Python and Heroku
I made a discord bot
I made blackjack with Python.
I made wordcloud with Python.
I made a simple typing game with tkinter in Python
I made a package to filter time series with python
[VSCode] I made a user snippet for Python print f-string
I made LINE-bot with Python + Flask + ngrok + LINE Messaging API
I made a simple book application with python + Flask ~ Introduction ~
Qiita API Python wrapper for batch processing to grab Qiita posts
I made a puzzle game (like) with Tkinter in Python
I wrote a Python script that exports all my posts using the Qiita API v2
I made a C ++ learning site
I made a CUI-based translation script (2)
I made a wikipedia gacha bot
I made my own Python library
Quine Post with Qiita API (Python)
I made a simple circuit with Python (AND, OR, NOR, etc.)
I made a library to easily read config files with Python
[Python3] I made a decorator that declares undefined functions and methods.
A story about adding a REST API to a daemon made with Python
Python> I made a test code for my own external file
I created a Python library to call the LINE WORKS API
I made a Nyanko tweet form with Python, Flask and Heroku
I made a lot of files for RDP connection with Python
[Python] I made an image viewer with a simple sorting function.
I made a shuffle that can be reset (reverted) with Python