Skip to content

Commit

Permalink
Update docs and bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
mjishnu committed Jun 18, 2024
1 parent af7ca11 commit 5de66eb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
25 changes: 18 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The `Pypdl` object provides additional options for advanced usage:
```py
from pypdl import Pypdl

dl = Pypdl(allow_reuse=False)
dl = Pypdl(allow_reuse=False, logger=default_logger("Pypdl"))
dl.start(
url='http://example.com/file.txt',
file_path='file.txt',
Expand All @@ -63,7 +63,8 @@ dl.start(
```

Each option is explained below:
- `allow_reuse`: Whether to allow reuse of existing Pypdl object for next download. The default value is `False`.
- `allow_reuse`: Whether to allow reuse of existing Pypdl object for next download. The default value is `False`.
- `logger`: A logger object to log messages. The default value is custom `Logger` with the name Pypdl.
- `url`: The URL of the file to download.
- `file_path`: An optional path to save the downloaded file. By default, it uses the present working directory. If `file_path` is a directory, then the file is downloaded into it otherwise, the file is downloaded into the given path.
- `segments`: The number of segments the file should be divided in multi-segmented download. The default value is 10.
Expand Down Expand Up @@ -119,14 +120,17 @@ if __name__ == '__main__':

This example downloads a file from the internet using 10 segments and displays the download progress. If the download fails, it will retry up to 3 times. we are also using headers, proxies and authentication.

Another example of implementing pause resume functionality and printing the progress to console:
Another example of implementing pause resume functionality, printing the progress to console and changing log level to debug:

```py
from pypdl import Pypdl

# create a pypdl object
dl = Pypdl()

# changing log level to debug
dl.logger.setLevel('DEBUG')

# start the download process
# block=False so we can print the progress
# display=False so we can print the progress ourselves
Expand Down Expand Up @@ -183,9 +187,10 @@ if dl.completed:
else:
print('Hash is invalid')
```
An example of using Pypdl object with `allow_reuse` set to `True`:
An example of using Pypdl object with `allow_reuse` set to `True` and custom logger:

```py
import logging
from pypdl import Pypdl

urls = [
Expand All @@ -196,8 +201,11 @@ urls = [
'https://example.com/file5.zip',
]

# create a custom logger
logger = logging.getLogger('custom')

# create a pypdl object
dl = Pypdl(allow_reuse=True)
dl = Pypdl(allow_reuse=True, logger=logger)

for url in urls:
dl.start(url, block=True)
Expand Down Expand Up @@ -274,7 +282,7 @@ The `Pypdl` class represents a file downloader that can download a file from a g

#### Arguments
- `allow_reuse`: (bool, Optional) Whether to allow reuse of existing `Pypdl` object for next download. The default value is `False`.It's essential to use `shutdown()` method when `allow_reuse` is enabled to ensure efficient resource management.
- Additional keyword arguments
- Supported Keyword Arguments:
- `params` (default `None`): Parameters to be sent in the query string of the new request.
- `data` (default `None`): The data to send in the body of the request.
- `json` (default `None`): A JSON-compatible Python object to send in the body of the request.
Expand All @@ -289,6 +297,7 @@ The `Pypdl` class represents a file downloader that can download a file from a g
- `ssl` (default `None`): SSL validation mode.
- `proxy_headers` (default `None`): HTTP headers to send to the proxy if the `proxy` parameter has been provided.

For detailed information on each parameter, refer the [aiohttp documentation](https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession.request). Please ensure that only the *supported keyword arguments* are used. Using unsupported or irrelevant keyword arguments may lead to unexpected behavior or errors.
#### Attributes

- `size`: The total size of the file to be downloaded, in bytes.
Expand Down Expand Up @@ -336,7 +345,7 @@ The `PypdlFactory` class manages multiple instances of the `Pypdl` downloader. I

- `instances`: (int, Optional) The number of `Pypdl` instances to create. The default value is 5.
- `allow_reuse`: (bool, Optional) Whether to allow reuse of existing `PypdlFactory` objects for next download. The default value is `False`. It's essential to use `shutdown()` method when `allow_reuse` is enabled to ensure efficient resource management.
- Additional keyword arguments
- Supported Keyword Arguments:
- `params` (default `None`): Parameters to be sent in the query string of the new request.
- `data` (default `None`): The data to send in the body of the request.
- `json` (default `None`): A JSON-compatible Python object to send in the body of the request.
Expand All @@ -351,6 +360,8 @@ The `PypdlFactory` class manages multiple instances of the `Pypdl` downloader. I
- `ssl` (default `None`): SSL validation mode.
- `proxy_headers` (default `None`): HTTP headers to send to the proxy if the `proxy` parameter has been provided.

For detailed information on each parameter, refer the [aiohttp documentation](https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientSession.request). Please ensure that only the *supported keyword arguments* are used. Using unsupported or irrelevant keyword arguments may lead to unexpected behavior or errors.


#### Attributes

Expand Down
2 changes: 0 additions & 2 deletions pypdl/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,7 @@ def download():
try:
_url = mirror_func() if i > 0 and callable(mirror_func) else url
self._reset()

self.logger.debug("Downloading, url: %s attempt: %s", _url, (i + 1))

result = self._execute(
_url,
file_path,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

VERSION = "1.4.0"
VERSION = "1.4.1"
DESCRIPTION = "A concurrent python download manager"
with open("README.md", "r") as f:
LONG_DESCRIPTION = f.read()
Expand Down

0 comments on commit 5de66eb

Please sign in to comment.