# aioaria2
[](https://pypi.org/project/aioaria2/)




## Support async rpc call with aria2 and process management
## Usage:
### example
```python
import asyncio
from pprint import pprint
import aioaria2
async def main():
async with aioaria2.Aria2HttpClient("http://117.0.0.1:6800/jsonrpc",
token="token") as client:
pprint(await client.getVersion())
asyncio.run(main())
```
### The ip address should be replaced with your own
### See [aria2 manual](http://aria2.github.io/manual/en/html/) for more detail about client methods
```python
# exampe of http
import asyncio
from pprint import pprint
import aioaria2
import ujson
async def main():
async with aioaria2.Aria2HttpClient("http://127.0.0.1:6800/jsonrpc",
token="token",
loads=ujson.loads,
dumps=ujson.dumps) as client:
pprint(await client.addUri(["http://www.demo.com"])) # that would start downloading
asyncio.run(main())
```
```python
# exampe of websocket
import asyncio
from pprint import pprint
import aioaria2
import ujson
@aioaria2.run_sync
def on_download_complete(trigger, data):
print(f"downlaod complete {data}")
async def main():
client: aioaria2.Aria2WebsocketClient = await aioaria2.Aria2WebsocketClient.new("http://127.0.0.1:6800/jsonrpc",
token="token",
loads=ujson.loads,
dumps=ujson.dumps)
client.onDownloadComplete(on_download_complete)
pprint(await client.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.
```python
import aioaria2
import asyncio
async def main():
server = aioaria2.AsyncAria2Server(r"aria2c.exe",
r"--conf-path=aria2.conf", "--rpc-secret=admin", daemon=True)
await server.start()
await server.wait()
asyncio.run(main())
```
#### this start an aria2 process
[Aria2 Manual](http://aria2.github.io/manual/en/html/)
### todolist
- [x] async http
- [x] async websocket
- [x] async process management
- [x] unitest
This module is built on top of [aria2jsonrpc](https://xyne.archlinux.ca/projects/python3-aria2jsonrpc)
with 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 modify
#### v1.2.0
new Aria2WebsocketTrigger class for websocket events, use on* methods to add callbacks
Like
```
@trigger.onDownloadStart
async def onDownloadStart(trigger, future):
print("下载开始{0}".format(future.result()))
```
#### v1.2.3
Now you can add multiple callbacks for one event ,must be coroutine function or an async callable, use ```aioaria2.run_sync``` to 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.0
* Big changes for class```Aria2WebsocketTrigger```
* Callbacks now accept```dict```as second parameter instead of```asyncio.Future```
* methods of class```Aria2WebsocketTrigger``` now have same return value as ```Aria2HttpClient```
* ```id``` parameter 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.1
* custom json library with keyword arguments ```loads``` ```dumps```
### v1.3.2
* fix unclosed client_session when exception occurs during ws_connect
* alias for ```Aria2WebsocketTrigger```,named ```Aria2WebsocketClient```
### v1.3.3
* fix method problems in client
### v1.3.4rc1
* handle reconnect simply
* handle InvalidstateError while trying to ping aria2
### v1.3.4
* add async id factory support
* allow unregister callbacks in websocketclient
* add contextvars support in ```run_sync```
### v1.3.5rc1
* graceful shutdown
### v1.3.5rc2
* add parser for aria2 files
```python
from pprint import pprint
from aioaria2 import DHTFile
pprint(DHTFile.from_file2("dht.dat"))
```
### v1.3.5rc3
* add strong ref to pending tasks
### v1.3.6
* update latest aiohttp version
Raw data
{
"_id": null,
"home_page": "https://github.com/synodriver/aioaria2",
"name": "aioaria2",
"maintainer": "v-vinson",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "asyncio, Aria2",
"author": "synodriver",
"author_email": "diguohuangjiajinweijun@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/9d/89/ea5bc4d7f15b85ae172112f4da84229b05dfe3f11c7671554f698bfd4eb1/aioaria2-1.3.6.tar.gz",
"platform": null,
"description": "# aioaria2\n\n\n[](https://pypi.org/project/aioaria2/)\n\n\n\n\n\n## Support async rpc call with aria2 and process management\n\n## Usage:\n\n### example\n\n```python\nimport asyncio\nfrom pprint import pprint\n\nimport aioaria2\n\n\nasync def main():\n async with aioaria2.Aria2HttpClient(\"http://117.0.0.1:6800/jsonrpc\",\n token=\"token\") as client:\n pprint(await client.getVersion())\n\n\nasyncio.run(main())\n```\n\n### The ip address should be replaced with your own\n\n### See [aria2 manual](http://aria2.github.io/manual/en/html/) for more detail about client methods\n\n```python\n# exampe of http\nimport asyncio\nfrom pprint import pprint\n\nimport aioaria2\nimport ujson\n\n\nasync def main():\n async with aioaria2.Aria2HttpClient(\"http://127.0.0.1:6800/jsonrpc\",\n token=\"token\",\n loads=ujson.loads,\n dumps=ujson.dumps) as client:\n pprint(await client.addUri([\"http://www.demo.com\"])) # that would start downloading\n\n\nasyncio.run(main())\n```\n\n```python\n# exampe of websocket\nimport asyncio\nfrom pprint import pprint\n\nimport aioaria2\nimport ujson\n\n\n@aioaria2.run_sync\ndef on_download_complete(trigger, data):\n print(f\"downlaod complete {data}\")\n\n\nasync def main():\n client: aioaria2.Aria2WebsocketClient = await aioaria2.Aria2WebsocketClient.new(\"http://127.0.0.1:6800/jsonrpc\",\n token=\"token\",\n loads=ujson.loads,\n dumps=ujson.dumps)\n client.onDownloadComplete(on_download_complete)\n pprint(await client.addUri([\"http://www.demo.com\"]))\n\n\nloop = asyncio.get_event_loop()\nloop.create_task(main())\nloop.run_forever()\n```\n\n- Run that coroutine function and each method represent an aria2-rpc call. As for server, each instance represent an aria2 process.\n\n```python\nimport aioaria2\nimport asyncio\n\n\nasync def main():\n server = aioaria2.AsyncAria2Server(r\"aria2c.exe\",\n r\"--conf-path=aria2.conf\", \"--rpc-secret=admin\", daemon=True)\n await server.start()\n await server.wait()\n\n\nasyncio.run(main())\n```\n\n#### this start an aria2 process\n\n[Aria2 Manual](http://aria2.github.io/manual/en/html/)\n\n### todolist\n\n- [x] async http\n- [x] async websocket\n- [x] async process management\n- [x] unitest\n\nThis module is built on top of [aria2jsonrpc](https://xyne.archlinux.ca/projects/python3-aria2jsonrpc)\nwith async and websocket support.\n\n### For windows users, you should\n\n```\n# for start async aria2 process\nasyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())\nasyncio.set_event_loop(asyncio.ProactorEventLoop())\n```\n\nFor python version greater than 3.8, asyncio uses ProactorEventLoop by default, so there is no need to modify\n\n#### v1.2.0\n\nnew Aria2WebsocketTrigger class for websocket events, use on* methods to add callbacks\n\nLike\n\n```\n@trigger.onDownloadStart\nasync def onDownloadStart(trigger, future):\n print(\"\u4e0b\u8f7d\u5f00\u59cb{0}\".format(future.result()))\n```\n\n#### v1.2.3\n\nNow you can add multiple callbacks for one event ,must be coroutine function or an async callable, use ```aioaria2.run_sync``` to wrap a sync function\n\n```\n@trigger.onDownloadStart\nasync def callback1(trigger, future):\n print(\"\u7b2c\u4e00\u4e2a\u56de\u8c03{0}\".format(future.result()))\n\n@trigger.onDownloadStart\n@run_sync\ndef callback2(trigger, future):\n print(\"\u7b2c\u4e8c\u4e2a\u56de\u8c03{0}\".format(future.result()))\n```\n\n#### v1.3.0\n\n* Big changes for class```Aria2WebsocketTrigger```\n\n* Callbacks now accept```dict```as second parameter instead of```asyncio.Future```\n* methods of class```Aria2WebsocketTrigger``` now have same return value as ```Aria2HttpClient```\n* ```id``` parameter now accept a callable as idfactory to generate uuid, otherwise default uuid factory is used.\n\n\n```\n@trigger.onDownloadStart\nasync def callback1(trigger, data:dict):\n print(\"\u7b2c\u4e00\u4e2a\u56de\u8c03{0}\".format(data))\n\n@trigger.onDownloadStart\n@run_sync\ndef callback2(trigger, data:dict):\n print(\"\u7b2c\u4e8c\u4e2a\u56de\u8c03{0}\".format(data))\n```\n\n### v1.3.1\n\n* custom json library with keyword arguments ```loads``` ```dumps```\n\n### v1.3.2\n\n* fix unclosed client_session when exception occurs during ws_connect\n* alias for ```Aria2WebsocketTrigger```,named ```Aria2WebsocketClient```\n\n### v1.3.3\n\n* fix method problems in client\n\n### v1.3.4rc1\n\n* handle reconnect simply\n* handle InvalidstateError while trying to ping aria2\n\n### v1.3.4\n\n* add async id factory support\n* allow unregister callbacks in websocketclient\n* add contextvars support in ```run_sync```\n\n### v1.3.5rc1\n\n* graceful shutdown\n\n### v1.3.5rc2\n\n* add parser for aria2 files\n\n```python\nfrom pprint import pprint\nfrom aioaria2 import DHTFile\n\npprint(DHTFile.from_file2(\"dht.dat\"))\n```\n\n### v1.3.5rc3\n\n* add strong ref to pending tasks\n\n### v1.3.6\n\n* update latest aiohttp version\n",
"bugtrack_url": null,
"license": "GPLv3",
"summary": "Support Aria2 rpc client and manage server with async/await",
"version": "1.3.6",
"project_urls": {
"Bug Tracker": "https://github.com/synodriver/aioaria2/issues",
"Homepage": "https://github.com/synodriver/aioaria2"
},
"split_keywords": [
"asyncio",
" aria2"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6921439cbfe94e6550cad19a30d1d64f7f5c963087a37742650918706dd25d72",
"md5": "be6d81f50c6c894956411bc8fc7ab73f",
"sha256": "1225719a9ef4defa1af0310ec21be641b7b2b5c5b1e6c9ac5133f6d4cb5108d1"
},
"downloads": -1,
"filename": "aioaria2-1.3.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "be6d81f50c6c894956411bc8fc7ab73f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 32940,
"upload_time": "2024-12-10T13:31:22",
"upload_time_iso_8601": "2024-12-10T13:31:22.277106Z",
"url": "https://files.pythonhosted.org/packages/69/21/439cbfe94e6550cad19a30d1d64f7f5c963087a37742650918706dd25d72/aioaria2-1.3.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9d89ea5bc4d7f15b85ae172112f4da84229b05dfe3f11c7671554f698bfd4eb1",
"md5": "79dab506cf0f881ba941d740b30f30c8",
"sha256": "575c61ba6a001d1e16fba08e30635733c4f5a31ed467c12ef2b58d836916ce83"
},
"downloads": -1,
"filename": "aioaria2-1.3.6.tar.gz",
"has_sig": false,
"md5_digest": "79dab506cf0f881ba941d740b30f30c8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 35623,
"upload_time": "2024-12-10T13:31:23",
"upload_time_iso_8601": "2024-12-10T13:31:23.544380Z",
"url": "https://files.pythonhosted.org/packages/9d/89/ea5bc4d7f15b85ae172112f4da84229b05dfe3f11c7671554f698bfd4eb1/aioaria2-1.3.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-10 13:31:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "synodriver",
"github_project": "aioaria2",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "aiohttp",
"specs": []
},
{
"name": "aiofiles",
"specs": []
},
{
"name": "typing-extensions",
"specs": []
}
],
"lcname": "aioaria2"
}