• Stars
    star
    471
  • Rank 93,216 (Top 2 %)
  • Language
    Python
  • License
    ISC License
  • Created almost 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Command-line tool and library to interact with an aria2c daemon process with JSON-RPC.

aria2p

ci documentation pypi version gitpod gitter

Command-line tool and Python library to interact with an aria2c daemon process through JSON-RPC.

demo

To avoid confusion:

  • aria2 is a lightweight multi-protocol & multi-source, cross platform download utility operated in command-line. It supports HTTP/HTTPS, FTP, SFTP, BitTorrent and Metalink.
  • aria2c is the name of the command-line executable provided by aria2. It can act as a daemon.
  • aria2p (p for Python) is a command-line client that can interact with an aria2c daemon. It is not an official client. There are other Python packages allowing you to interact with an aria2c daemon. These other packages do not offer enough usability (in my opinion), this is why I'm developing aria2p.

Purpose: aria2c can run in the foreground, for one-time downloads, or in the background, as a daemon. This is where aria2p intervenes: when an instance of aria2c is running in the background, aria2p will be able to communicate with it to add downloads to the queue, remove, pause or resume them, etc.

In order for aria2p to be able to communicate with the aria2c process, RPC mode must be enabled with the --enable-rpc option of aria2c. RPC stands for Remote Procedure Call. Although aria2c supports both JSON-RPC and XML-RPC protocols, aria2p works with JSON only (not XML). More information about how to configure aria2c to run as a daemon with RPC mode enabled can be found in the Configuration section of the documentation.

Table of contents

Requirements

aria2 must be installed. On systems with apt-get:

sudo apt-get install aria2

Installation

With pip:

python3.6 -m pip install aria2p[tui]

With pipx:

python3.6 -m pip install --user pipx

pipx install --python python3.6 aria2p[tui]

The tui extra is needed for the interactive interface. If you don't need the interface (for example when you are writing a Python package with a dependency to aria2p), simply install aria2p without any extra.

Usage (as a library)

This library is still a work in progress. More examples will be added later. In the meantime, you can read the Reference section on the official documentation.

import aria2p

# initialization, these are the default values
aria2 = aria2p.API(
    aria2p.Client(
        host="http://localhost",
        port=6800,
        secret=""
    )
)

# list downloads
downloads = aria2.get_downloads()

for download in downloads:
    print(download.name, download.download_speed)

# add downloads
magnet_uri = "magnet:?xt=urn:..."

download = aria2.add_magnet(magnet_uri)

Usage (command-line)

usage: aria2p [GLOBAL_OPTS...] COMMAND [COMMAND_OPTS...]

Command-line tool and Python library to interact with an `aria2c` daemon
process through JSON-RPC.

Global options:
  -h, --help            Show this help message and exit. Commands also accept
                        the -h/--help option.
  -p PORT, --port PORT  Port to use to connect to the remote server.
  -H HOST, --host HOST  Host address for the remote server.
  -s SECRET, --secret SECRET
                        Secret token to use to connect to the remote server.
  -L {TRACE,DEBUG,INFO,SUCCESS,WARNING,ERROR,CRITICAL}, --log-level {TRACE,DEBUG,INFO,SUCCESS,WARNING,ERROR,CRITICAL}
                        Log level to use
  -P LOG_PATH, --log-path LOG_PATH
                        Log path to use. Can be a directory or a file.
  -T CLIENT_TIMEOUT, --client-timeout CLIENT_TIMEOUT
                        Timeout in seconds for requests to the remote server.
                        Floats supported. Default: 60.0.

Commands:
  
    add                 Add downloads with URIs/Magnets/torrents/Metalinks.
    add-magnets (add-magnet)
                        Add downloads with Magnet URIs.
    add-metalinks (add-metalink)
                        Add downloads with Metalink files.
    add-torrents (add-torrent)
                        Add downloads with torrent files.
    autopurge (autoclear)
                        Automatically purge completed/removed/failed
                        downloads.
    call                Call a remote method through the JSON-RPC client.
    pause (stop)        Pause downloads.
    remove (rm, del, delete)
                        Remove downloads.
    resume (start)      Resume downloads.
    show                Show the download progression.
    top                 Launch the top-like interactive interface.
    listen              Listen to notifications.

Calling aria2p without any arguments will by default call the top command, which is a console interactive interface.

Commands:


add

usage: aria2p add [-h] [-f FROM_FILE] [uris [uris ...]]

Add downloads with URIs/Magnets/torrents/Metalinks.

positional arguments:
  uris                  The URIs/file-paths to add.

optional arguments:
  -h, --help            Show this help message and exit.
  -f FROM_FILE, --from-file FROM_FILE
                        Load URIs from a file.


add-magnets

usage: aria2p add-magnets [-h] [-f FROM_FILE] [uris [uris ...]]

Add downloads with Magnet URIs.

positional arguments:
  uris                  The magnet URIs to add.

optional arguments:
  -h, --help            Show this help message and exit.
  -f FROM_FILE, --from-file FROM_FILE
                        Load URIs from a file.


add-metalinks

usage: aria2p add-metalinks [-h] [-f FROM_FILE]
                            [metalink_files [metalink_files ...]]

Add downloads with Metalink files.

positional arguments:
  metalink_files        The paths to the metalink files.

optional arguments:
  -h, --help            Show this help message and exit.
  -f FROM_FILE, --from-file FROM_FILE
                        Load file paths from a file.


add-torrents

usage: aria2p add-torrents [-h] [-f FROM_FILE]
                           [torrent_files [torrent_files ...]]

Add downloads with torrent files.

positional arguments:
  torrent_files         The paths to the torrent files.

optional arguments:
  -h, --help            Show this help message and exit.
  -f FROM_FILE, --from-file FROM_FILE
                        Load file paths from a file.


autopurge

usage: aria2p autopurge [-h]

Automatically purge completed/removed/failed downloads.

optional arguments:
  -h, --help  Show this help message and exit.


call

usage: aria2p call [-h] [-P PARAMS [PARAMS ...] | -J PARAMS] method

Call a remote method through the JSON-RPC client.

positional arguments:
  method                The method to call (case insensitive). Dashes and
                        underscores will be removed so you can use as many as
                        you want, or none. Prefixes like 'aria2.' or 'system.'
                        are also optional.

optional arguments:
  -h, --help            Show this help message and exit.
  -P PARAMS [PARAMS ...], --params-list PARAMS [PARAMS ...]
                        Parameters as a list of strings.
  -J PARAMS, --json-params PARAMS
                        Parameters as a JSON string. You should always wrap it
                        at least once in an array '[]'.

As explained in the help text, the method can be the exact method name, or just the name without the prefix. It is case-insensitive, and dashes and underscores will be removed.

The following are all equivalent:

  • aria2.addUri
  • aria2.adduri
  • addUri
  • ADDURI
  • aria2.ADD-URI
  • add_uri
  • A-d_D-u_R-i (yes it's valid)
  • A---R---I---A---2.a__d__d__u__r__i (I think you got it)
  • and even more ugly forms...

Examples

List all available methods. This example uses jq.

$ aria2p call listmethods | jq
[
  "aria2.addUri",
  "aria2.addTorrent",
  "aria2.getPeers",
  "aria2.addMetalink",
  "aria2.remove",
  "aria2.pause",
  "aria2.forcePause",
  "aria2.pauseAll",
  "aria2.forcePauseAll",
  "aria2.unpause",
  "aria2.unpauseAll",
  "aria2.forceRemove",
  "aria2.changePosition",
  "aria2.tellStatus",
  "aria2.getUris",
  "aria2.getFiles",
  "aria2.getServers",
  "aria2.tellActive",
  "aria2.tellWaiting",
  "aria2.tellStopped",
  "aria2.getOption",
  "aria2.changeUri",
  "aria2.changeOption",
  "aria2.getGlobalOption",
  "aria2.changeGlobalOption",
  "aria2.purgeDownloadResult",
  "aria2.removeDownloadResult",
  "aria2.getVersion",
  "aria2.getSessionInfo",
  "aria2.shutdown",
  "aria2.forceShutdown",
  "aria2.getGlobalStat",
  "aria2.saveSession",
  "system.multicall",
  "system.listMethods",
  "system.listNotifications"
]

List the GIDs (identifiers) of all active downloads. Note that we must give the parameters as a JSON string.

$ aria2p call tellactive -J '[["gid"]]'
[{"gid": "b686cad55029d4df"}, {"gid": "4b39a1ad8fd94e26"}, {"gid": "9d331cc4b287e5df"}, {"gid": "8c9de0df753a5195"}]

Pause a download using its GID. Note that when a single string argument is required, it can be passed directly with -P.

$ aria2p call pause -P b686cad55029d4df
"b686cad55029d4df"

Add a download using magnet URIs. This example uses jq -r to remove the quotation marks around the result.

$ aria2p call adduri -J '[["magnet:?xt=urn:..."]]' | jq -r
4b39a1ad8fd94e26f

Purge download results (remove completed downloads from the list).

$ aria2p call purge_download_result
"OK"

listen

usage: aria2p listen [-h] [-c CALLBACKS_MODULE] [-t TIMEOUT]
                     [event_types [event_types ...]]

Listen to notifications.

positional arguments:
  event_types           The types of notifications to process: start, pause,
                        stop, error, complete or btcomplete. Example: aria2p
                        listen error btcomplete. Useful if you want to spawn
                        multiple specialized aria2p listener, for example one
                        for each type of notification, but still want to use
                        only one callback file.

optional arguments:
  -h, --help            Show this help message and exit.
  -c CALLBACKS_MODULE, --callbacks-module CALLBACKS_MODULE
                        Path to the Python module defining your notifications
                        callbacks.
  -t TIMEOUT, --timeout TIMEOUT
                        Timeout in seconds to use when waiting for data over
                        the WebSocket at each iteration. Use small values for
                        faster reactivity when stopping to listen.


pause

usage: aria2p pause [-h] [-a] [-f] [gids [gids ...]]

Pause downloads.

positional arguments:
  gids         The GIDs of the downloads to pause.

optional arguments:
  -h, --help   Show this help message and exit.
  -a, --all    Pause all the downloads.
  -f, --force  Pause without contacting servers first.


remove

usage: aria2p remove [-h] [-a] [-f] [gids [gids ...]]

Remove downloads.

positional arguments:
  gids         The GIDs of the downloads to remove.

optional arguments:
  -h, --help   Show this help message and exit.
  -a, --all    Remove all the downloads.
  -f, --force  Remove without contacting servers first.


resume

usage: aria2p resume [-h] [-a] [gids [gids ...]]

Resume downloads.

positional arguments:
  gids        The GIDs of the downloads to resume.

optional arguments:
  -h, --help  Show this help message and exit.
  -a, --all   Resume all the downloads.


show

usage: aria2p show [-h]

Show the download progression.

optional arguments:
  -h, --help  Show this help message and exit.


top

usage: aria2p top [-h]

Launch the top-like interactive interface.

optional arguments:
  -h, --help  Show this help message and exit.

Troubleshooting

  • Error outputs like below when using aria2p as a Python library:

    requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=6800): Max retries exceeded with url: /jsonrpc (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x1115b1908>: Failed to establish a new connection: [Errno 61] Connection refused',))
    

    Solution: aria2c needs to be up and running first.

Support

To support me as an open-source software author, consider donating or be a supporter through one of the following platforms

Thank you!

More Repositories

1

docker-nginx-postgres-django-example

Example using Docker, Django, multiple Postgres databases, NginX, Gunicorn, pipenv, GitLab CI and tox.
Python
162
star
2

git-changelog

Automatic Changelog generator using Jinja2 templates.
Python
134
star
3

shell-history

Visualize your shell usage with Highcharts!
Python
110
star
4

markdown-exec

Utilities to execute code blocks in Markdown files.
Python
95
star
5

duty

A simple task runner.
Python
89
star
6

django-zxcvbn-password

Back-end and Front-end password validation with ZXCVBN
Python
86
star
7

copier-pdm

Copier template for Python projects managed by PDM.
Jinja
83
star
8

django-suit-dashboard

Create a dashboard within Django admin interface.
Python
83
star
9

copier-poetry

Copier template for Python projects managed by Poetry.
Jinja
79
star
10

awesome-repository

A curated list of services, tools and standards about (open source) repository management.
60
star
11

website

My personal website.
Python
46
star
12

cookiecutter-awesome

Cookiecutter to create an awesome list.
Python
41
star
13

shellman

Write documentation in comments and render it with templates.
Python
37
star
14

docker-nginx-auth-request-django-shiny-example

Example using Docker, Nginx with auth-request module, and Django acting as a authentication wrapper around a Shiny app.
Python
22
star
15

dependenpy

Show the inter-dependencies between modules of Python packages.
Python
22
star
16

mkdocs-coverage

MkDocs plugin to integrate your coverage HTML report into your site.
Python
21
star
17

mkdocs-spellcheck

A spell checker plugin for MkDocs.
Python
16
star
18

copier-uv

Copier template for Python projects managed by uv.
Jinja
16
star
19

django-appsettings

Application settings helper for Django apps.
Python
15
star
20

django-meerkat

Security audit tool for Django sites
JavaScript
14
star
21

archan

Analysis of your architecture strength based on DSM data.
Python
12
star
22

mkdocs-gallery

A gallery of MkDocs themes, showing off a few plugins and extensions.
Python
12
star
23

moving-stars

โญ Copy GitHub stars to GitLab ๐ŸŒ 
Python
10
star
24

pawabot

A Telegram Bot for many things: aria2 management, torrent sites crawling, media organization with filebot and Plex.
Python
9
star
25

django-archan

A Django app that displays dependency matrices and other project architecture information
Python
9
star
26

cookie-poetry

Cookiecutter for Poetry projects.
Roff
8
star
27

pdm-multirun

A PDM plugin to run a command on multiple Python versions.
Python
8
star
28

failprint

Run a command, print its output only if it fails.
Python
8
star
29

neopy

Neo4j for Python. Manipulate graph data in Python with Neo4j as data storage.
Python
7
star
30

django-cerberus-ac

Django Cerberus Access Control, extended permission system.
JavaScript
7
star
31

ansito

Transform ANSI codes to any other format (currently only Conky style)
Python
7
star
32

stars

My stars on GitHub, grouped by language.
6
star
33

yore

Manage legacy code with comments.
Python
5
star
34

mkdocs-pygments

Highlighting themes for code blocks. Available to sponsors only.
Python
5
star
35

django-cs-models

A Django app that helps you creating models within a Complex System
Python
4
star
36

privibot

A Python library to add a privilege/permission system to your Telegram bot.
Python
4
star
37

shelldemo

Run a set of Bash commands as if typed by a robo- I mean, a person.
Shell
4
star
38

wps-light

The strictest and most opinionated python linter ever! (lighter fork)
Python
4
star
39

gestion-de-stock

Graphical UI in Qt for database management
C++
3
star
40

logan

Log analysis tool (alpha).
HTML
3
star
41

happy-path

Code and data flow visualization tool for Python. Available to sponsors only.
3
star
42

github-labels

The source of truth for labels in my GitHub projects.
2
star
43

rosetta-suit

Integration of django-rosetta into django-suit admin interface
HTML
2
star
44

suit-dashboard-demo

Demo site using django-suit-dashboard
Shell
2
star
45

fastapi-ref

API reference of FastAPI.
2
star
46

pawamoy.github.io

HTML
2
star
47

mvodb

Rename and move files using metadata from online databases.
Python
2
star
48

odoo-matrix

D3.js visualization for Odoo's inter-dependencies
Python
2
star
49

pypi-insiders

Self-hosted PyPI server with automatic updates for Insiders versions of projects. Only available to sponsors.
2
star
50

cookiecutter-cookiecutter

The cookiecutter that generated itself.
Python
1
star
51

django-access-control

Control how users access resources in your Django project
Python
1
star
52

mkdocs-manpage

MkDocs plugin to generate a manpage from the documentation site.
Python
1
star
53

pawamoy

My profile readme.
Shell
1
star
54

archan-pylint

Archan plugin for Pylint (number of messages per module).
Python
1
star
55

taskhub

[ALPHA] Task management tool, supporting import/export from/to different services, with multiple interfaces.
Python
1
star
56

cookiecutter-pypackage

Roff
1
star
57

Omnidia

Abstract elements manager (multimedia, data, stuff) in browser
HTML
1
star
58

mkdocs-logging

Logging utilities for MkDocs plugins.
Python
1
star
59

fulfill

Manage your project. Fulfill your duties.
Python
1
star
60

devboard

A development dashboard for your projects. Available to sponsors only.
1
star
61

keycut

A command line tool that helps you remembering ALL the numerous keyboard shortcuts of ALL your favorite programs
Python
1
star