Package: pixivpy3
PixivPy3Due to#158reason, password login
no longer exist. Please useapi.auth(refresh_token=REFRESH_TOKEN)insteadTo getrefresh_token, see@ZipFile Pixiv OAuth FloworOAuth with Selenium/ChromeDriverPixiv API for Python (with Auth supported)[2023/09/18]v3.7.3Addnovel_follow(), fix ByPassSniApi() host BUG, see#279(thanks@Solomon,@rhyryy)[2023/09/17] Move to new PEP 517 standard with poetry, and upgrade deps, see#270(thanks@Nachtalb)[2022/02/04] Remove Public-API support as it's deprecated by Pixiv, see#201[2021/11/23] Addillust_newfor get latest works, see#189[2021/03/02] Add userfollow/unfollow, addnovelAPI, see#161(thanks@y-young,@invobzvr)[2020/10/17] Usecloudscraperto
bypass Cloudflare, fixed issue #140 (thanks@lllusion3469)[2020/07/19] Add date specification forsearch_illust()(thanksXdynix)[2020/06/06] AddAppPixivAPI().search_novel()for novel search[2019/09/23] 增加大陆地区 AppAPI 的免翻墙访问支持, release v3.5 (Seeexample_bypass_sni.py,
thanks@Notsfsssf)[2019/09/03] Support new auth() checkX-Client-Time/X-Client-Hash(thanksDaRealFreak,#83)[2019/04/27] Support hosts proxy for AppAPI, which can use behind the Great
Wall (Seeexample_api_proxy.py)[2017/04/18] Fix encoder BUG forillust_bookmark_add()/illust_bookmark_delete()params (thanksnaplings)[2017/01/05] AddPixivAPI().works()liked APIillust_detail()for App-API
(thanksMapaler), release v3.3[2016/12/17] Fixed encoding BUG for Public-API, see #26 (thanksXdynix)[2016/07/27] NowAppPixivAPI()can callwithout auth(thankszzycami), checkdemo.py[2016/07/20] NewApp-API(Experimental) forPixivIOSApp/6.0.9[2016/07/11] Add newiOS 6.x APIreference to Wiki[2015/12/02] Add write API for favorite an user / illust, release v3.1[2015/08/11] Remove SPAI and release v3.0 (pixivpy3) (Public-API with Search
API)[2015/05/16] As PixivdeprecatedSAPI in recent days, push new Public-APIranking_all[2014/10/07] New framework,SAPI / Public-APIsupported (requests needed)Use pip for installing:# for Python3pipinstallpixivpy3--upgrade# for Python2pipinstallpixivpy--upgradeRequirements:requestsMikubill/PixivPy-Async: Async Pixiv API for Python 3性能对比（需要高性能访问场景，可以参
考这个脚本）Warning: The rate limit was hit multiple times during the test, so the result
may not be informative. Script:https://github.com/Mikubill/pixivpy-async/blob/master/Perf.pysg -> Singapore, jp -> Japan, unit -> secondMethodSync(10,sg)Async(10,sg)Sync(200,sg)Async(200,sg)illust_detail1.12090.864131.70412.4580illust_ranking1.06970.793628.45392.0693user_illusts0.88240.750528.39811.8199user_detail0.96280.755028.30551.7738ugoira_metadata0.85090.745929.55662.2331works1.12040.891232.20682.8513me_following_works1.12530.784539.31422.2785ranking1.09460.794439.65092.6548latest_works1.04830.866736.19922.5066MethodSync(500,jp)Async(500,jp)illust_detail6.21780.6400illust_ranking6.40460.6119user_illusts7.60931.5266user_detail6.67590.5952ugoira_metadata6.51550.7577works13.30740.8619me_following_works24.26932.0835ranking21.41193.2805latest_works17.35022.7029Projects base on pixivpyMikubill/PixivPy-Async: Async
Pixiv API for Python 3Example:frompixivpy3import*api=AppPixivAPI()# api.login("username", "password")   # Not required# get origin urljson_result=api.illust_detail(59580629)illust=json_result.illustprint(">>> origin url:%s"%illust.image_urls['large'])# get ranking: 1-30# mode: [day, week, month, day_male, day_female, week_original, week_rookie, day_manga]json_result=api.illust_ranking('day')forillustinjson_result.illusts:print(" p1 [%s]%s"%(illust.title,illust.image_urls.medium))# next page: 31-60next_qs=api.parse_qs(json_result.next_url)json_result=api.illust_ranking(**next_qs)forillustinjson_result.illusts:print(" p2 [%s]%s"%(illust.title,illust.image_urls.medium))# get all page:next_qs={"mode":"day"}whilenext_qs:json_result=api.illust_ranking(**next_qs)forillustinjson_result.illusts:print("[%s]%s"%(illust.title,illust.image_urls.medium))next_qs=api.parse_qs(json_result.next_url)Sniffer - App APISniffer - Public API (deprecated)Using API proxy behind the Great WallSee detail inIssue#73Upgrade pixivpy >=v3.2.0:pip install pixivpy --upgradeCallapi.download()like the below:aapi=AppPixivAPI()json_result=aapi.illust_ranking()forillustinjson_result.illusts[:3]:aapi.download(illust.image_urls.large)Migrate pixivpy2 to pixivpy3Replaceapi.papi.*toapi.*Change deprecated SPAI call to Public-API callprint(">>> new ranking_all(mode='daily', page=1, per_page=50)")#rank_list = api.sapi.ranking("all", 'day', 1)rank_list=api.ranking_all('daily',1,50)print(rank_list)# more fields about response: https://github.com/upbit/pixivpy/wiki/snifferranking=rank_list.response[0]forimginranking.works:# print(img.work)print("[%s/%s(id=%s)]%s"%(img.work.user.name,img.work.title,img.work.id,img.work.image_urls.px_480mw))AboutBlog:Pixiv Public-API (OAuth)分析If you have any questions, please feel free to contact me:rmusique@gmail.comFind Pixiv API inObjective-C? You might also likePixivAPI_iOSAPI functionsApp-API (6.0 - app-api.pixiv.net)classAppPixivAPI(BasePixivAPI):# 返回翻页用参数defparse_qs(next_url):# 用户详情defuser_detail(user_id):# 用户作品列表## type: [illust, manga]defuser_illusts(user_id,type="illust"):# 用户收藏作品列表# tag: 从 user_bookmark_tags_illust 获取的收藏标签defuser_bookmarks_illust(user_id,restrict="public"):# 用户收藏作品列表中的小说defuser_bookmarks_novel(user_id,restrict="public"):defuser_related(seed_user_id):# 关注用户的新作# restrict: [public, private]defillust_follow(restrict="public"):# 作品详情 (类似PAPI.works()，iOS中未使用)defillust_detail(illust_id):# 作品评论defillust_comments(illust_id,include_total_comments=None):# 相关作品列表defillust_related(illust_id):# 插画推荐 (Home - Main)# content_type: [illust, manga]defillust_recommended(content_type="illust"):# 小说推荐defnovel_recommended():# 作品排行# mode: [day, week, month, day_male, day_female, week_original, week_rookie, day_manga]# date: '2016-08-01'# mode (Past): [day, week, month, day_male, day_female, week_original, week_rookie,#               day_r18, day_male_r18, day_female_r18, week_r18, week_r18g]defillust_ranking(mode="day",date=None):# 趋势标签 (Search - tags)deftrending_tags_illust():# 搜索 (Search)# search_target - 搜索类型#   partial_match_for_tags  - 标签部分一致#   exact_match_for_tags    - 标签完全一致#   title_and_caption       - 标题说明文# sort: [date_desc, date_asc, popular_desc] - popular_desc为会员的热门排序# duration: [within_last_day, within_last_week, within_last_month]# start_date, end_date: '2020-07-01'defsearch_illust(word,search_target="partial_match_for_tags",sort="date_desc",duration=None,start_date=None,end_date=None):# 搜索小说 (Search Novel)# search_target - 搜索类型#   partial_match_for_tags  - 标签部分一致#   exact_match_for_tags    - 标签完全一致#   text                    - 正文#   keyword                 - 关键词# sort: [date_desc, date_asc]# start_date/end_date: 2020-06-01defsearch_novel(word,search_target="partial_match_for_tags",sort="date_desc",start_date=None,end_date=None):defsearch_user(word,sort='date_desc',duration=None):# 作品收藏详情defillust_bookmark_detail(illust_id):# 新增收藏defillust_bookmark_add(illust_id,restrict="public",tags=None):# 删除收藏defillust_bookmark_delete(illust_id):# 关注用户defuser_follow_add(user_id,restrict="public"):# 取消关注用户defuser_follow_delete(user_id):# 用户收藏标签列表defuser_bookmark_tags_illust(restrict="public"):# Following用户列表defuser_following(user_id,restrict="public"):# Followers用户列表defuser_follower(user_id):# 好P友defuser_mypixiv(user_id):# 黑名单用户defuser_list(user_id):# 获取ugoira信息defugoira_metadata(illust_id):# 用户小说列表defuser_novels(user_id):# 小说系列详情defnovel_series(series_id,last_order=None):# 小说详情defnovel_detail(novel_id):# 小说正文defnovel_text(novel_id):# 大家的新作# content_type: [illust, manga]defillust_new(content_type="illust",max_illust_id=None):defnovel_new(max_novel_id=None):# 特辑详情 (无需登录，调用Web API)defshowcase_article(showcase_id):Usage:aapi=AppPixivAPI()# 作品推荐json_result=aapi.illust_recommended()print(json_result)illust=json_result.illusts[0]print(">>>%s, origin url:%s"%(illust.title,illust.image_urls['large']))# 作品相关推荐json_result=aapi.illust_related(57065990)print(json_result)illust=json_result.illusts[0]print(">>>%s, origin url:%s"%(illust.title,illust.image_urls['large']))# 作品相关推荐-下一页 (.parse_qs(next_url) 用法)next_qs=aapi.parse_qs(json_result.next_url)json_result=aapi.illust_related(**next_qs)print(json_result)illust=json_result.illusts[0]print(">>>%s, origin url:%s"%(illust.title,illust.image_urls['large']))# 用户详情json_result=aapi.user_detail(660788)print(json_result)user=json_result.userprint("%s(@%s) region=%s"%(user.name,user.account,json_result.profile.region))# 用户作品列表json_result=aapi.user_illusts(660788)print(json_result)illust=json_result.illusts[0]print(">>>%s, origin url:%s"%(illust.title,illust.image_urls['large']))# 用户收藏列表json_result=aapi.user_bookmarks_illust(2088434)print(json_result)illust=json_result.illusts[0]print(">>>%s, origin url:%s"%(illust.title,illust.image_urls['large']))# 用户收藏列表中的小说json_result=aapi.user_bookmarks_novel(42862448)print(json_result)novel=json_result.novels[0]print(">>>{}, text_length:{}, series:{}".format(novel.title,novel.text_length,novel.series))# 2016-07-15 日的过去一周排行json_result=aapi.illust_ranking('week',date='2016-07-15')print(json_result)illust=json_result.illusts[0]print(">>>%s, origin url:%s"%(illust.title,illust.image_urls['large']))# 关注用户的新作 (需要login)json_result=aapi.illust_follow(req_auth=True)print(json_result)illust=json_result.illusts[0]print(">>>%s, origin url:%s"%(illust.title,illust.image_urls['large']))# 标签 "水着" 搜索json_result=aapi.search_illust('水着',search_target='partial_match_for_tags')print(json_result)illust=json_result.illusts[0]print(">>>%s, origin url:%s"%(illust.title,illust.image_urls['large']))# 用户 "gomzi" 搜索json_result=aapi.search_user("gomzi")print(json_result)illust=json_result.user_previews[0].illusts[0]print(">>>%s, origin url:%s"%(illust.title,illust.image_urls['large']))Package Publishing InstructionsFollow these simple steps to publish your Poetry package. We recommend
publishing to thetest.pypi.orginstance first, to
verify everything is working as expected.This step only has to be done once:# Configure test.pypi.orgpoetryconfigrepositories.testpypihttps://test.pypi.org/legacy/# Configure API Keys for both PyPI and TestPyPYpoetryconfigpypi-token.testpypi<testpypi_api_key>
poetryconfigpypi-token.pypi<pypi_api_key>Now publish the new version:# Adjust the package version at the top of the "pyproject.toml" filevimpyproject.toml# Build python packages to dist/ folderpoetrybuild# Publish package to TestPyPipoetrypublish-rtestpypi# Checkout published package in a different environmentpipinstall--index-urlhttps://test.pypi.org/simple/<your_package_name># Once confirmed that everything works, publish to the real PyPipoetrypublishLicenseFeel free to use, reuse and abuse the code in this project.