api ¤
Aria2 API.
This module defines the API class, which makes use of a JSON-RPC client to provide higher-level methods to interact easily with a remote aria2c process.
Classes:
-
API–A class providing high-level methods to interact with a remote aria2c process.
API ¤
API(client: Client | None = None)
A class providing high-level methods to interact with a remote aria2c process.
This class is instantiated with a reference to a Client instance. It then uses this client to call remote procedures, or remote methods. While the client methods reflect exactly what aria2c is providing through JSON-RPC, this class's methods allow for easier / faster control of the remote process. It also wraps the information the client retrieves in Python object, like Download, allowing for even more Pythonic interactions, without worrying about payloads, responses, JSON, etc..
Parameters:
-
client(Client | None, default:None) –An instance of the aria2p.client.Client class.
Methods:
-
add–Add a download (guess its type).
-
add_magnet–Add a download with a Magnet URI.
-
add_metalink–Add a download with a Metalink file.
-
add_torrent–Add a download with a torrent file (usually .torrent extension).
-
add_uris–Add a download with a URL (or more).
-
autopurge–Purge completed, removed or failed downloads from the queue.
-
copy_files–Copy downloaded files to another directory.
-
get_download–Get a
Downloadobject thanks to its GID. -
get_downloads–Get a list of
Downloadobject thanks to their GIDs. -
get_global_options–Get the global options.
-
get_options–Get options for each of the given downloads.
-
get_stats–Get the stats of the remote aria2c process.
-
listen_to_notifications–Start listening to aria2 notifications via WebSocket.
-
move–Move a download in the queue, relatively to its current position.
-
move_down–Move a download down in the queue.
-
move_files–Move downloaded files to another directory.
-
move_to–Move a download in the queue, with absolute positioning.
-
move_to_bottom–Move a download to the bottom of the queue.
-
move_to_top–Move a download to the top of the queue.
-
move_up–Move a download up in the queue.
-
parse_input_file–Parse a file with URIs or an aria2c input file.
-
pause–Pause the given (active) downloads.
-
pause_all–Pause all (active) downloads.
-
purge–Purge completed, removed or failed downloads from the queue.
-
remove–Remove the given downloads from the list.
-
remove_all–Remove all downloads from the list.
-
remove_files–Remove downloaded files.
-
resume–Resume (unpause) the given downloads.
-
resume_all–Resume (unpause) all downloads.
-
retry_downloads–Resume failed downloads from where they left off with new GIDs.
-
search–Not implemented.
-
set_global_options–Set global options.
-
set_options–Set options for specific downloads.
-
split_input_file–Helper to split downloads in an input file.
-
stop_listening–Stop listening to notifications.
Source code in src/aria2p/api.py
43 44 45 46 47 48 49 50 | |
add ¤
Add a download (guess its type).
If the provided URI is in fact a file-path, and is neither a torrent or a metalink, then we read its lines and try to add each line as a download, recursively.
Parameters:
-
uri(str) –The URI or file-path to add.
-
options(OptionsType | None, default:None) –An instance of the
Optionsclass or a dictionary containing aria2c options to create the download with. -
position(int | None, default:None) –The position where to insert the new download in the queue. Start at 0 (top).
Returns:
Source code in src/aria2p/api.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
add_magnet ¤
add_magnet(
magnet_uri: str,
options: OptionsType | None = None,
position: int | None = None,
) -> Download
Add a download with a Magnet URI.
Parameters:
-
magnet_uri(str) –The Magnet URI.
-
options(OptionsType | None, default:None) –An instance of the
Optionsclass or a dictionary containing aria2c options to create the download with. -
position(int | None, default:None) –The position where to insert the new download in the queue. Start at 0 (top).
Returns:
-
Download–The newly created download object.
Source code in src/aria2p/api.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
add_metalink ¤
add_metalink(
metalink_file_path: str | Path,
options: OptionsType | None = None,
position: int | None = None,
) -> list[Download]
Add a download with a Metalink file.
Parameters:
-
metalink_file_path(str | Path) –The path to the Metalink file.
-
options(OptionsType | None, default:None) –An instance of the
Optionsclass or a dictionary containing aria2c options to create the download with. -
position(int | None, default:None) –The position where to insert the new download in the queue. Start at 0 (top).
Returns:
Source code in src/aria2p/api.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
add_torrent ¤
add_torrent(
torrent_file_path: str | Path,
uris: list[str] | None = None,
options: OptionsType | None = None,
position: int | None = None,
) -> Download
Add a download with a torrent file (usually .torrent extension).
Parameters:
-
torrent_file_path(str | Path) –The path to the torrent file.
-
uris(list[str] | None, default:None) –A list of URIs used for Web-seeding.
-
options(OptionsType | None, default:None) –An instance of the
Optionsclass or a dictionary containing aria2c options to create the download with. -
position(int | None, default:None) –The position where to insert the new download in the queue. Start at 0 (top).
Returns:
-
Download–The newly created download object.
Source code in src/aria2p/api.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
add_uris ¤
add_uris(
uris: list[str],
options: OptionsType | None = None,
position: int | None = None,
) -> Download
Add a download with a URL (or more).
Parameters:
-
uris(list[str]) –A list of URIs that point to the same resource.
-
options(OptionsType | None, default:None) –An instance of the
Optionsclass or a dictionary containing aria2c options to create the download with. -
position(int | None, default:None) –The position where to insert the new download in the queue. Start at 0 (top).
Returns:
-
Download–The newly created download object.
Source code in src/aria2p/api.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
autopurge ¤
autopurge() -> bool
Purge completed, removed or failed downloads from the queue.
Deprecated. Use purge instead.
Returns:
-
bool–Success or failure of the operation.
Source code in src/aria2p/api.py
567 568 569 570 571 572 573 574 575 576 | |
copy_files staticmethod ¤
copy_files(
downloads: list[Download],
to_directory: str | Path,
force: bool = False,
) -> list[bool]
Copy downloaded files to another directory.
Parameters:
-
downloads(list[Download]) –the list of downloads for which to move files.
-
to_directory(str | Path) –The target directory to copy files into.
-
force(bool, default:False) –Whether to move files even if download is not complete.
Returns:
Source code in src/aria2p/api.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | |
get_download ¤
Get a Download object thanks to its GID.
Parameters:
-
gid(str) –The GID of the download to get.
Returns:
-
Download–The retrieved download object.
Source code in src/aria2p/api.py
264 265 266 267 268 269 270 271 272 273 | |
get_downloads ¤
Get a list of Download object thanks to their GIDs.
Parameters:
-
gids(list[str] | None, default:None) –The GIDs of the downloads to get. If None, return all the downloads.
Returns:
Source code in src/aria2p/api.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | |
get_global_options ¤
get_global_options() -> Options
Get the global options.
Returns:
-
Options–The global aria2c options.
Source code in src/aria2p/api.py
593 594 595 596 597 598 599 | |
get_options ¤
Get options for each of the given downloads.
Parameters:
Returns:
Source code in src/aria2p/api.py
578 579 580 581 582 583 584 585 586 587 588 589 590 591 | |
get_stats ¤
get_stats() -> Stats
Get the stats of the remote aria2c process.
Returns:
-
Stats–The global stats returned by the remote process.
Source code in src/aria2p/api.py
634 635 636 637 638 639 640 | |
listen_to_notifications ¤
listen_to_notifications(
threaded: bool = False,
on_download_start: Callable | None = None,
on_download_pause: Callable | None = None,
on_download_stop: Callable | None = None,
on_download_complete: Callable | None = None,
on_download_error: Callable | None = None,
on_bt_download_complete: Callable | None = None,
timeout: int = 5,
handle_signals: bool = True,
) -> None
Start listening to aria2 notifications via WebSocket.
This method differs from Client.listen_to_notifications in that it expects callbacks accepting two arguments, api and gid, instead of only gid. Accepting api allows to use the high-level methods of the API class.
Stop listening to notifications with the API.stop_listening method.
Parameters:
-
threaded(bool, default:False) –Whether to start the listening loop in a thread or not (non-blocking or blocking).
-
on_download_start(Callable | None, default:None) –Callback for the
onDownloadStartevent. -
on_download_pause(Callable | None, default:None) –Callback for the
onDownloadPauseevent. -
on_download_stop(Callable | None, default:None) –Callback for the
onDownloadStopevent. -
on_download_complete(Callable | None, default:None) –Callback for the
onDownloadCompleteevent. -
on_download_error(Callable | None, default:None) –Callback for the
onDownloadErrorevent. -
on_bt_download_complete(Callable | None, default:None) –Callback for the
onBtDownloadCompleteevent. -
timeout(int, default:5) –Timeout when waiting for data to be received. Use a small value for faster reactivity when stopping to listen. Default is 5 seconds.
-
handle_signals(bool, default:True) –Whether to add signal handlers to gracefully stop the loop on SIGTERM and SIGINT.
Source code in src/aria2p/api.py
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 | |
move ¤
Move a download in the queue, relatively to its current position.
Parameters:
-
download(Download) –The download object to move.
-
pos(int) –The relative position (1 to move down, -1 to move up, -2 to move up two times, etc.).
Returns:
-
int–The new position of the download.
Source code in src/aria2p/api.py
298 299 300 301 302 303 304 305 306 307 308 | |
move_down ¤
Move a download down in the queue.
Parameters:
-
download(Download) –The download object to move.
-
pos(int, default:1) –Number of times to move down. With negative values, will move up (use move or move_up instead).
Returns:
-
int–The new position of the download.
Source code in src/aria2p/api.py
339 340 341 342 343 344 345 346 347 348 349 | |
move_files staticmethod ¤
move_files(
downloads: list[Download],
to_directory: str | Path,
force: bool = False,
) -> list[bool]
Move downloaded files to another directory.
Parameters:
-
downloads(list[Download]) –the list of downloads for which to move files.
-
to_directory(str | Path) –The target directory to move files to.
-
force(bool, default:False) –Whether to move files even if download is not complete.
Returns:
Source code in src/aria2p/api.py
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | |
move_to ¤
Move a download in the queue, with absolute positioning.
Parameters:
-
download(Download) –The download object to move.
-
pos(int) –The absolute position in the queue where to move the download. 0 for top, -1 for bottom.
Returns:
-
int–The new position of the download.
Source code in src/aria2p/api.py
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
move_to_bottom ¤
Move a download to the bottom of the queue.
Parameters:
-
download(Download) –The download object to move.
Returns:
-
int–The new position of the download.
Source code in src/aria2p/api.py
362 363 364 365 366 367 368 369 370 371 | |
move_to_top ¤
Move a download to the top of the queue.
Parameters:
-
download(Download) –The download object to move.
Returns:
-
int–The new position of the download.
Source code in src/aria2p/api.py
351 352 353 354 355 356 357 358 359 360 | |
move_up ¤
Move a download up in the queue.
Parameters:
-
download(Download) –The download object to move.
-
pos(int, default:1) –Number of times to move up. With negative values, will move down (use move or move_down instead).
Returns:
-
int–The new position of the download.
Source code in src/aria2p/api.py
327 328 329 330 331 332 333 334 335 336 337 | |
parse_input_file ¤
Parse a file with URIs or an aria2c input file.
Parameters:
Returns:
-
InputFileContentsType–List of tuples containing list of URIs and dictionary with aria2c options.
Source code in src/aria2p/api.py
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 | |
pause ¤
Pause the given (active) downloads.
Parameters:
-
downloads(list[Download]) –The list of downloads to pause.
-
force(bool, default:False) –Whether to pause immediately without contacting servers or not.
Returns:
-
list[OperationResult]–Success or failure of the operation for each given download.
Source code in src/aria2p/api.py
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
pause_all ¤
Pause all (active) downloads.
Parameters:
-
force(bool, default:False) –Whether to pause immediately without contacting servers or not.
Returns:
-
bool–Success or failure of the operation to pause all downloads.
Source code in src/aria2p/api.py
515 516 517 518 519 520 521 522 523 524 525 | |
purge ¤
purge() -> bool
Purge completed, removed or failed downloads from the queue.
Returns:
-
bool–Success or failure of the operation.
Source code in src/aria2p/api.py
559 560 561 562 563 564 565 | |
remove ¤
remove(
downloads: list[Download],
force: bool = False,
files: bool = False,
clean: bool = True,
) -> list[OperationResult]
Remove the given downloads from the list.
Parameters:
-
downloads(list[Download]) –The list of downloads to remove.
-
force(bool, default:False) –Whether to force the removal or not.
-
files(bool, default:False) –Whether to remove downloads files as well.
-
clean(bool, default:True) –Whether to remove the aria2 control file as well.
Returns:
-
list[OperationResult]–Success or failure of the operation for each given download.
Source code in src/aria2p/api.py
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 | |
remove_all ¤
Remove all downloads from the list.
Parameters:
-
force(bool, default:False) –Whether to force the removal or not.
Returns:
-
bool–Success or failure of the operation to remove all downloads.
Source code in src/aria2p/api.py
477 478 479 480 481 482 483 484 485 486 | |
remove_files staticmethod ¤
Remove downloaded files.
Parameters:
-
downloads(list[Download]) –the list of downloads for which to remove files.
-
force(bool, default:False) –Whether to remove files even if download is not complete.
Returns:
Source code in src/aria2p/api.py
642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 | |
resume ¤
Resume (unpause) the given downloads.
Parameters:
Returns:
-
list[OperationResult]–Success or failure of the operation for each given download.
Source code in src/aria2p/api.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 | |
resume_all ¤
resume_all() -> bool
Resume (unpause) all downloads.
Returns:
-
bool–Success or failure of the operation to resume all downloads.
Source code in src/aria2p/api.py
551 552 553 554 555 556 557 | |
retry_downloads ¤
Resume failed downloads from where they left off with new GIDs.
Parameters:
-
downloads(list[Download]) –The list of downloads to remove.
-
clean(bool, default:False) –Whether to remove the aria2 control file as well.
Returns:
-
list[OperationResult]–Success or failure of the operation for each given download.
Source code in src/aria2p/api.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
search ¤
Not implemented.
Search and return Download objects based on multiple patterns.
Parameters:
Raises:
-
NotImplementedError–This method is not implemented yet.
Source code in src/aria2p/api.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
set_global_options ¤
set_global_options(options: OptionsType) -> bool
Set global options.
Parameters:
-
options(OptionsType) –An instance of the
Optionsclass or a dictionary containing aria2c options to create the download with.
Returns:
-
bool–Success or failure of the operation for changing global options.
Source code in src/aria2p/api.py
620 621 622 623 624 625 626 627 628 629 630 631 632 | |
set_options ¤
Set options for specific downloads.
Parameters:
-
options(OptionsType) –An instance of the
Optionsclass or a dictionary containing aria2c options to create the download with. -
downloads(list[Download]) –The list of downloads to set the options for.
Returns:
Source code in src/aria2p/api.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 | |
split_input_file ¤
Helper to split downloads in an input file.
Parameters:
Yields:
Source code in src/aria2p/api.py
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
stop_listening ¤
stop_listening() -> None
Stop listening to notifications.
If the listening loop was threaded, this method will wait for the thread to finish. The time it takes for the thread to finish will depend on the timeout given while calling listen_to_notifications.
Source code in src/aria2p/api.py
802 803 804 805 806 807 808 809 810 811 812 | |