Package: aioaria2
aioaria2Support async rpc call with aria2 and process managementUsage:exampleimportasynciofrompprintimportpprintimportaioaria2asyncdefmain():asyncwithaioaria2.Aria2HttpClient("http://117.0.0.1:6800/jsonrpc",token="token")asclient:pprint(awaitclient.getVersion())asyncio.run(main())The ip address should be replaced with your ownSeearia2 manualfor more detail about client methods# exampe of httpimportasynciofrompprintimportpprintimportaioaria2importujsonasyncdefmain():asyncwithaioaria2.Aria2HttpClient("http://127.0.0.1:6800/jsonrpc",token="token",loads=ujson.loads,dumps=ujson.dumps)asclient:pprint(awaitclient.addUri(["http://www.demo.com"]))# that would start downloadingasyncio.run(main())# exampe of websocketimportasynciofrompprintimportpprintimportaioaria2importujson@aioaria2.run_syncdefon_download_complete(trigger,data):print(f"downlaod complete{data}")asyncdefmain():client:aioaria2.Aria2WebsocketTrigger=awaitaioaria2.Aria2WebsocketTrigger.new("http://127.0.0.1:6800/jsonrpc",token="token",loads=ujson.loads,dumps=ujson.dumps)client.onDownloadComplete(on_download_complete)pprint(awaitclient.addUri(["http://www.demo.com"]))loop=asyncio.get_event_loop()loop.create_task(main())loop.run_forever()Run that coroutine function and each method represent an aria2-rpc call. As for server, each instance represent an aria2 process.importaioaria2importasyncioasyncdefmain():server=aioaria2.AsyncAria2Server(r"aria2c.exe",r"--conf-path=aria2.conf","--rpc-secret=admin",daemon=True)awaitserver.start()awaitserver.wait()asyncio.run(main())this start an aria2 processAria2 Manualtodolistasync httpasync websocketasync process managementunitestThis module is built on top ofaria2jsonrpcwith async and websocket support.For windows users, you should# for start async aria2 process
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
asyncio.set_event_loop(asyncio.ProactorEventLoop())For python version greater than 3.8, asyncio uses ProactorEventLoop by default, so there is no need to modifyv1.2.0new Aria2WebsocketTrigger class for websocket events, use on* methods to add callbacksLike@trigger.onDownloadStart
async def onDownloadStart(trigger, future):
    print("下载开始{0}".format(future.result()))v1.2.3Now you can add multiple callbacks for one event ,must be coroutine function or an async callable, useaioaria2.run_syncto wrap a sync function@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.0Big changes for classAria2WebsocketTriggerCallbacks now acceptdictas second parameter instead ofasyncio.Futuremethods of classAria2WebsocketTriggernow have same return value asAria2HttpClientidparameter now accept a callable as idfactory to generate uuid, otherwise default uuid factory is used.@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))v1.3.1custom json library with keyword argumentsloadsdumpsv1.3.2fix  unclosed client_session when exception occurs during ws_connectalias forAria2WebsocketTrigger,namedAria2WebsocketClientv1.3.3fix method problems in clientv1.3.4rc1handle reconnect simplyhandle InvalidstateError while trying to ping aria2v1.3.4add async id factory supportallow unregister callbacks in websocketclientadd contextvars support inrun_sync