Support Aria2 rpc client and manage server with async/await
Project description
aioaria2
提供aria2异步客户端通信
本模块提供与aria2异步通信的客户端与管理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.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
- 单元测试
本模块在aria2jsonrpc 之上构建,提供了异步支持,以级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()))
v1.3.0更新
本版本大量修改了Aria2WebsocketTrigger类的方法,Aria2HttpClient保持不变
- 回调直接接受dict参数
- Aria2WebsocketTrigger的相应方法获得了返回值
- id现在需要传入一个可以调用的id工厂函数作为uuid使用,否则将使用默认的uuid生成器
@trigger.onDownloadStart
async def callback1(trigger, data:dict):
print("第一个回调{0}".format(data))
@trigger.onDownloadStart
@run_sync
def callback2(trigger, data:dict):
print("第二个回调{0}".format(data))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aioaria2-1.3.0.tar.gz.
File metadata
- Download URL: aioaria2-1.3.0.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5af755815bc22457637fd7a19629fdbc5dd7ba3482477799b65a3a4f4158c92f
|
|
| MD5 |
d776bbc3926120c96d76d88000a87085
|
|
| BLAKE2b-256 |
ca2405508a08de21e23f09c139986415b20d08f0c96f077accc3e3e9f9848c50
|
File details
Details for the file aioaria2-1.3.0-py3-none-any.whl.
File metadata
- Download URL: aioaria2-1.3.0-py3-none-any.whl
- Upload date:
- Size: 30.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.6.0.post20201009 requests-toolbelt/0.9.1 tqdm/4.53.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ae8e2ee2f65a938e945dce689131f2034e352df56e17199a991024aa3774ce3
|
|
| MD5 |
1c948f9f1074a644af42ef3cba7845b9
|
|
| BLAKE2b-256 |
9a8c1482b9ddd49915698d0e2dc61e5d4256073756d95f7261c45cc4dc4b4b52
|