/ src / aria2p / __init__.py
__init__.py
 1  """aria2p package.
 2  
 3  Command-line tool and library to interact with an aria2c daemon process with JSON-RPC.
 4  """
 5  
 6  from __future__ import annotations
 7  
 8  import sys
 9  from typing import TextIO
10  
11  from loguru import logger
12  
13  from aria2p.api import API
14  from aria2p.client import Client, ClientException
15  from aria2p.downloads import BitTorrent, Download, File
16  from aria2p.options import Options
17  from aria2p.stats import Stats
18  
19  logger.disable("aria2p")
20  
21  
22  def enable_logger(sink: str | TextIO = sys.stderr, level: str = "WARNING") -> None:
23      """Enable the logging of messages.
24  
25      Configure the `logger` variable imported from `loguru`.
26  
27      Parameters:
28          sink (file): An opened file pointer, or stream handler. Default to standard error.
29          level (str): The log level to use. Possible values are TRACE, DEBUG, INFO, WARNING, ERROR, CRITICAL.
30              Default to WARNING.
31      """
32      logger.remove()
33      logger.configure(handlers=[{"sink": sink, "level": level}])  # type: ignore[misc,list-item]
34      logger.enable("aria2p")
35  
36  
37  __all__ = [
38      "API",
39      "BitTorrent",
40      "Client",
41      "ClientException",
42      "Download",
43      "File",
44      "Options",
45      "Stats",
46      "enable_logger",
47  ]