Skip to main content

Async Pixiv API for Python

Project description

Async-Pixiv

Python 3.8 GitHub file size in bytes PyPI License

PyPI - Downloads View

异步调用 Pixiv API

Building...

此项目的开发者很忙,所以没啥时间修 bug ,写文档什么的

特点

  1. 支持 API 请求速率限制(RateLimiter
  2. 可使用账号和密码直接登录 Pixiv(注:可能会因为遇到 Cloudflare 验证而登录失败)
  3. 自动将请求后的数据转为 Model ,再也不用以字典形式调用获取数据了(pydantic typed)
  4. 支持多种代理模式(http/https/socks5)
  5. 支持下载 gif 帧序列文件,并将其转为 gif 或 mp4 (需要 ffmpeg
  6. 。。。(想到再写)

安装

使用 pip (任选一行指令进行安装)

pip install --upgrade async-pixiv

# 安装额外依赖(用于提升数据解析速度)
pip install --upgrade async-pixiv[extra]

# 安装 playwright,使之可以使用账号密码登录 
pip install --upgrade async-pixiv[playwright]

# 安装全部额外依赖
pip install --upgrade async-pixiv[full]

使用 poetry

poetry add async-pixiv

# 安装额外依赖(用于提升数据解析速度)
poetry add async-pixiv[extra]

# 安装 playwright,使之可以使用账号密码登录 
poetry add async-pixiv[playwright]

# 安装全部额外依赖
poetry add async-pixiv[full]

使用

from async_pixiv import PixivClient  # 导入

# 初始化 Client
client = PixivClient(
    max_rate=100,  # API 请求速率限制。默认 100 次
    rate_time_period=60,  # API 请求速率限制时间区间。默认 60 秒
    timeout=10,  # 默认超时秒数
    proxies=None,  # 代理配置
    trust_env=False,  # 是否从环境变量中获取代理配置
    retry=5,  # 默认请求重试次数
    retry_sleep=1,  # 默认重复请求间隔秒数
)


async def main():
    user = await client.login_with_token('TOKEN')  # 使用 token 登录 pixiv
    print(user.name)

    # 获取作品详情
    detail_result = await client.ILLUST.detail(91725675)
    illust = detail_result.illust
    print(
        f"链接:{illust.link}", 
        f"标题:{illust.title}", 
        f"作者:{illust.user.name}", 
        f"标签:#{' #'.join(map(str, illust.tags))}", 
        f"是否为 AI 作品:{'是' if illust.ai_type else '否'}",
        f"是否为 R18 作品:{'是' if await illust.is_r18() else '否'}",
        sep='\n'
    )
    file_data = illust.download() # 下载
    breakpoint()

    # 下载动图
    bytes_data = await client.ILLUST.download_ugoira(105369892, type='mp4')  # bytes
    gif_data = await client.ILLUST.download_ugoira(105369892, type='gif')
    breakpoint()

    # 小说
    novel_result = await client.NOVEL.detail(15739859)
    novel = novel_result.novel
    print(f"标题:{novel.title}", f"字数:{novel.text_length}", sep='\n')
    breakpoint()
    
    # 漫画
    # 下次再写

def __main__():
    import asyncio

    asyncio.run(main())


if __name__ == '__main__':
    __main__()

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

async_pixiv-1.0.0a0.tar.gz (39.6 kB view details)

Uploaded Source

Built Distribution

async_pixiv-1.0.0a0-py3-none-any.whl (49.7 kB view details)

Uploaded Python 3

File details

Details for the file async_pixiv-1.0.0a0.tar.gz.

File metadata

  • Download URL: async_pixiv-1.0.0a0.tar.gz
  • Upload date:
  • Size: 39.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.11.1 readme-renderer/44.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/2.2.2 tqdm/4.66.5 importlib-metadata/7.1.0 keyring/25.3.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.12

File hashes

Hashes for async_pixiv-1.0.0a0.tar.gz
Algorithm Hash digest
SHA256 3ac4ee5e4e7e4eac945e9e05b741fb2145fd5295c6b819156d5e00217cad6fff
MD5 0e6f57bd26a47a3ad9bd2a6267ead204
BLAKE2b-256 d403dd1abf1501f9a3ffaa8680ac364e77661c743e53c323765cfa3fb64b2ec9

See more details on using hashes here.

File details

Details for the file async_pixiv-1.0.0a0-py3-none-any.whl.

File metadata

  • Download URL: async_pixiv-1.0.0a0-py3-none-any.whl
  • Upload date:
  • Size: 49.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.11.1 readme-renderer/44.0 requests/2.32.3 requests-toolbelt/1.0.0 urllib3/2.2.2 tqdm/4.66.5 importlib-metadata/7.1.0 keyring/25.3.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.12

File hashes

Hashes for async_pixiv-1.0.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 a656d56d6fcf7481bbbfb9f5e54cc416c41e4f2408e72c4f14c5086e42be6696
MD5 dacdfc0026f707fbeeab3428668169f8
BLAKE2b-256 7ae350507338b17d138be02d31e3448b79120fd025bdfcf0d8865b1b68c1a426

See more details on using hashes here.

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