afetchx
Asynchronously fetch image URLs using httpx.
afetchx parses command-line arguments to determine the list of image URLs to fetch, the maximum number of concurrent connections, the cooldown time between requests, an optional JSON file containing URLs, and output options. It then fetches the images, saves them in the specified output directory, and prints the number of successfully downloaded images.
Usage
Invoke the script with
python -m afetchx {args}
Command-line arguments
-n,--max_connections: Max number of concurrent connections (default: 5).-c,--cooldown: Cooldown time between requests in seconds (default: 1.0).-j,--json: Path to a JSON file containing URLs to fetch.-o,--output-dir: Directory to save downloaded images (default:./downloadedin the current working directory).--filename-format: Lambda function as a string to format filenames based on the URL (e.g.,"lambda url: url.split('/')[-1].split('.')[0] + '.png'").urls: List of image URLs to fetch (positional arguments).
Note: You must satisfy exactly one of the following conditions
- Use the
--json(-j) argument to specify a JSON file containing URLs. - Provide one or more URLs directly as positional arguments.
Examples
Basic Usage
Download images from a JSON file with a cooldown of 1 second between each download and a maximum of 5 concurrent connections:
python -m afetchx -j urls.json -c 1.0 -n 5
Specify Output Directory
Download images from URLs provided as positional arguments and save them to a custom directory:
python -m afetchx -c 1.0 -n 5 -o ./downloaded_pictures "https://unsplash.it/256.jpg" "https://unsplash.it/512.jpg"
Use Custom Filename Format
Download images and apply a custom filename format based on the URL:
python -m afetchx -c 1.0 -n 5 --filename-format "lambda url: url.split('/')[-1].split('.')[0] + '.png'" "https://example.com/image1.png" "https://example.com/image2.jpg"
In this example, each downloaded image will be named according to the lambda function. The filename format option can be especially useful for sanitizing or modifying filenames before saving.
Error Handling
If both URLs and a JSON file are provided, the script will print an error and exit. Likewise, if neither URLs nor a JSON file are provided, the script will print an error and exit. Ensure exactly one source for URLs.
Metadata
Release files for afetchx 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| afetchx-1.1.1.tar.gz | 4.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| afetchx-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.0 kB
Release files / afetchx-1.1.1.tar.gz
| Download URL | afetchx-1.1.1.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9bf1db1d78be4ca8e99ee628cb5c29211a0b2ee7237f7093d467e88d9db1522c
|
|
BLAKE2b-256 checksum How to use checksums |
dadfb305a295265cbf478bb1d3ef23444a8800e2a5e88160fb27bfcbd8142012
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.3 Windows/11
|
Release files / afetchx-1.1.1-py3-none-any.whl
| Download URL | afetchx-1.1.1-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0cfe72b57997097a230eea343e9743c95fd057146d1003e804d2e0329da6c6f3
|
|
BLAKE2b-256 checksum How to use checksums |
de41505979237faa9925852a8a176cb310560fda2b221980c962173c39da3628
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.12.3 Windows/11
|