Configuration¶
You can usually leave every setting alone. This page covers the few you're likely to touch, and why. The configuration reference lists all of them.
Three ways to set options¶
Every option is a field of DownloadConfig and can be passed as a keyword to
download(), adownload() or Downloader(). To reuse a set of options, build a config object:
import machyon
from machyon import DownloadConfig
polite = DownloadConfig(
max_concurrency=16, # never more than 16 requests in flight
max_retries=8,
user_agent="my-dataset-bot/1.0 (+mailto:me@example.com)",
headers={"Accept": "image/avif,image/webp,image/*"},
)
report = machyon.download("urls.csv", "images/", config=polite)
# DownloadConfig is a dataclass: derive variants without mutating the original.
strict = polite.replace(verify_existing=True, fsync=True)
print(report, strict.max_concurrency, strict.fsync)
Or keep them in an INI file, which the CLI reads too:
from pathlib import Path
import machyon
from machyon import DownloadConfig
Path("machyon.ini").write_text(
"[SETTINGS]\n"
"max_concurrency = 64\n"
"max_retries = 8\n"
"timeout = 20\n",
encoding="utf-8",
)
cfg = DownloadConfig.from_ini("machyon.ini") # the CLI takes the same file: --config machyon.ini
print(cfg.max_concurrency, cfg.max_retries, cfg.timeout)
report = machyon.download("urls.csv", "images/", config=cfg)
Keywords win over config=, and CLI flags win over --config.
Sites that need headers¶
Some sites refuse requests that don't look like they come from their own pages, or need a token:
machyon.download("urls.csv", "images/",
referer="https://shop.example.com/", # hotlink protection
headers={"Authorization": "Bearer …", "Cookie": "session=…"})
machyon urls.csv -o images/ --referer https://shop.example.com/ \
--header "Authorization: Bearer …" --header "Cookie: session=…"
A run full of http_403 or
not_image usually means a missing referer.
machyon doctor <url> tells you which. Troubleshooting
The default user_agent is a current desktop browser's, because many image hosts reject unknown clients. For
research crawls, an honest one with a contact address is the polite choice:
user_agent="my-lab-crawler/1.0 (+mailto:me@uni.edu)".
How hard to push¶
Machyon finds its own concurrency between 2 and max_concurrency (256). You rarely need to set it, but you might
want to cap it:
| Situation | Setting |
|---|---|
| A server you share, or whose operator asked you to be gentle | max_concurrency=8 to 16 |
| A known per-client limit (say, 50 connections) | max_concurrency just under it |
| Measuring something and want a fixed number | adaptive=False, concurrency=N |
| A quota that counts every request | hedge=False |
How the adaptive limiter decides
Timeouts and retries¶
| Option | Default | Raise it when |
|---|---|---|
timeout |
15 s | Servers take long to start answering, or links are very slow. It bounds the connect time and any silence between received bytes |
max_request_time |
120 s | Single files are huge. The cap already grows with the file's size |
max_retries |
5 | A flaky server needs more patience |
backoff |
0.5 s | You want longer waits between retries |
HTTPS trust¶
By default Machyon checks certificates against your operating system's trust store (tls_trust="native"),
like your browser, so company and antivirus certificates installed on your machine are honoured. The other choices
are "certifi" (Mozilla's bundle, like requests) and "python" (Python's own defaults).
verify_ssl=False (--insecure) turns verification off entirely. Use it only for a host you trust, after
machyon doctor has shown you why verification fails.
File safety¶
| Option | Default | Turn it on when |
|---|---|---|
verify_existing |
off | Files in the folder may not have come from Machyon. Existing files must start with an image signature to be skipped |
fsync |
off | A power cut must not cost you anything. Each file is flushed to the physical disk before it's renamed into place. Slower |
validate |
on | Leave it on. Turning it off keeps bodies that aren't images |
Logs and run history¶
log_dir="logs/" (--log logs/) writes a rotating machyon.log with one line per failed URL. metrics_dir="runs/"
(--metrics runs/) appends a summary of every run (counts, rate, latency, concurrency, failure reasons) to
runs/metrics_json_info.json, which is handy for comparing runs over time.