Skip to main content

Support Aria2 rpc client and manage server with async/await

Project description

提供aria2异步客户端的包

本模块提供与aria2异步通信的客户端与管理aria2进程的服务端

pypi地址

使用方法:

示例如下

import aioaria2
import asyncio
from pprint import pprint
async def main():
    async with aioaria2.Aria2HttpClient("id", "http://192.168.0.107:6800/jsonrpc", "normal",
                                        token="admin") as client:
        pprint(await client.getVersion())
asyncio.run(main())

相关ip地址应该换成自己的

client对象的相关方法见aria2手册

import aioaria2
import asyncio
from pprint import pprint
async def main():
    async with aioaria2.Aria2HttpClient("id", "http://192.168.0.107:6800/jsonrpc", "normal",
                                        token="admin") as client:
        pprint(await client.addUri(["http://www.demo.com"])) #即可下载
asyncio.run(main())
运行该协程函数即可,方法对应aria2jsonrpc的方法
对于服务端,每一个实例对应一个aria2进程
import aioaria2
import asyncio
async def main():
    server = aioaria2.AsyncAria2Server(r"128aria2c.exe",
                                       r"--conf-path=aria2.conf", "--rpc-secret=admin", daemon=True)
    await server.start()
    await server.wait()
asyncio.run(main())

即可启动一个aria2进程

参考选项及设置

todolist

  • 异步http通信
  • 异步websocket通信
  • 修复server类的bug
  • 单元测试

jsonrpc 本模块在其之上构建,提供了异步支持,以级websocket支持

windows用户应该加上以下设置

asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
asyncio.set_event_loop(asyncio.ProactorEventLoop())
python3.8以后默认是ProactorEventLoop因此可以不用修改

Notice

在最终v1.0发布之前不建议直接setup安装

v1.2.0更新

新增Aria2WebsocketTrigger类,可以监听websocket消息, 使用on*方法注册自定义回调函数,既可以是同步也可以是异步的

如下

@trigger.onDownloadStart
async def onDownloadStart(trigger, future):
    print("下载开始{0}".format(future.result()))

v1.2.3更新

可以给一个事件注册多个回调,现在只能是协程函数,同步函数需要自行从utils.run_sync包装

@trigger.onDownloadStart
async def callback1(trigger, future):
    print("第一个回调{0}".format(future.result()))

@trigger.onDownloadStart
@run_sync
def callback2(trigger, future):
    print("第二个回调{0}".format(future.result()))

title

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

aioaria2-1.2.3.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

aioaria2-1.2.3-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file aioaria2-1.2.3.tar.gz.

File metadata

  • Download URL: aioaria2-1.2.3.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for aioaria2-1.2.3.tar.gz
Algorithm Hash digest
SHA256 69b31fd9fe35bd98712fec919984fde3fff7f2b9dc022d10f5ee3ba461447302
MD5 335d0a696a6a035bf1129c65cb097a58
BLAKE2b-256 1bc42d89f84bb9ffeab27ef10a3371d54b65a74026d45f3fbb54a4c54ed388ab

See more details on using hashes here.

File details

Details for the file aioaria2-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: aioaria2-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 28.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

File hashes

Hashes for aioaria2-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a8ff8d232d36cb0dd270d62a9e4fd92aacea6a4a62e84216999c6249b9c74a70
MD5 358d791e398a6a7da3d8183cfc9f041b
BLAKE2b-256 a39e05cf7dee70c016aae0a5285fc8577d5a88287f6d60e44c5de7fedd5365cc

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