Skip to main content

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: ./downloaded in 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

  1. Use the --json (-j) argument to specify a JSON file containing URLs.
  2. 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)

Source distribution for afetchx 1.1.1
File Size Uploaded Provenance Actions
afetchx-1.1.1.tar.gz 4.2 kB Without provenance Details for afetchx-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for afetchx 1.1.1
File Interpreter ABI Platform Actions
afetchx-1.1.1-py3-none-any.whl Python 3 none any Details for afetchx-1.1.1-py3-none-any.whl

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

Security for afetchx 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page