Skip to main content

imgagent

Universal image discovery, search, listing, download and asset agent — standalone, headless, deterministic, machine-friendly.

CI PyPI Python 3.10+ License: MIT Landing

🌐 Landing page · 📦 PyPI · 🤖 Agent manual (AGENTS.md) · 👤 ansaribilal.com

imgagent is a production-grade, installable image acquisition agent for AI agents and humans: one command takes a query from search → normalize → rank → dedupe → download → validate → manifest → verified local paths. Every stage is also independently callable. It runs fully deterministic without any LLM, works headless on Linux / macOS / Windows / Termux / containers / CI, and needs no paid API for its default public-source workflow.

pip install imgagent            # live on PyPI

Sibling doctrine of ytagent, ttagent and igagent: one input, one JSON contract, verified bytes, honest negatives.


Quickstart

# From PyPI (published)
pip install imgagent
# or from a clone
pip install .

# One command: discover, rank, download the top 5, write the manifest
imgagent run "Isdal Woman Norway 1970 historical photographs" \
  --limit 20 --top 5 --out ./assets --json

# Search only (no downloads)
imgagent search "Isdal Woman Bergen" --limit 30 --json

# List candidates of the latest job
imgagent list --job latest --json

# Download selected results
imgagent download --job latest --top 10 --out ./assets --project myfilm --scene scene-04 --json

# Inspect a URL without downloading its contents
imgagent inspect "https://commons.wikimedia.org/wiki/File:Isdal_Woman.jpg"

# The complete machine-facing contract
imgagent agent-instructions

One-command workflow

INPUT QUERY
→ SEARCH MULTIPLE SOURCES      (wikimedia · openverse · duckduckgo · custom official APIs)
→ NORMALIZE RESULTS            (single ImageCandidate schema, versioned)
→ RANK RELEVANCE               (text + entity + technical + rights, deterministic, no LLM)
→ DEDUPLICATE                  (cross-provider URL dedup; SHA-256 + perceptual near-dup)
→ LIST CANDIDATES
→ DOWNLOAD SELECTED IMAGES     (streaming, bounded concurrency, atomic .part)
→ VALIDATE FILES               (magic bytes + full decode; never trust headers)
→ SAVE METADATA AND MANIFEST   (.imgagent/manifests/<job>.json + metadata.jsonl)
→ RETURN VERIFIED PATHS

A broken provider never breaks the others: per-source failures come back as structured entries in errors[], and a partial success is explicitly represented in the JSON payload.

Supported providers

Provider Type API key Default Status Notes
wikimedia Official MediaWiki API no yes tested License metadata, originals, best historical coverage
openverse Official Openverse API optional (OPENVERSE_API_KEY) yes tested CC/public-domain focus, rights-cleared mode
duckduckgo Community vqd flow (unofficial) no yes best-effort Volatile; failures are graceful and explicit
generic Webpage extractor (og:image, JSON-LD, <img>) no inspect-only tested Also resolves public Pinterest pin pages as page references
custom:* Config-driven official APIs (Unsplash, Pexels, your own) per-config opt-in tested Declared in config.toml [sources.custom.*]

Google Images is deliberately not implemented as fragile HTML scraping; use a configured official API (custom source) instead. No CAPTCHA, paywall, login or access-control bypass exists in this codebase. See docs/PROVIDERS.md for the full support matrix.

Verification & security

  • Downloads are validated by magic bytes + full Pillow decode — HTML pages masquerading as images, corrupt files, empty files and oversized payloads are rejected.
  • SHA-256 content hashing, exact-duplicate reuse, atomic .part → rename writes.
  • SSRF protection: http/HTTPS only, private/link-local/loopback ranges blocked, cloud metadata endpoints hard-blocked, redirect-by-redirect validation, response size caps.
  • TLS verification is never disabled as a fallback. See docs/SECURITY.md.

Rights & provenance

Technical downloadability is separated from publication permission. Every asset records source URL, provider, creator, license name/URL, attribution text, retrieval timestamps, file hash, dimensions and a rights state:

verified_public_domain · verified_license · permission_required · unknown · restricted

--require-reuse-rights keeps only verified states — and a high relevance score can never override that gate. Generic illustration and authentic case evidence remain distinguishable via authenticity and --prefer-authentic.

Workspace layout

.imgagent/
  config.toml          # optional configuration
  jobs/
  database.sqlite      # transactional job/candidate/asset state (WAL)
  manifests/           # <job_id>.json — the stable contract for consumers
  cache/               # TTL JSON cache for API responses

assets/
  <project>/
    originals/         # verified originals only
    processed/
    thumbnails/
    metadata.jsonl     # one record per downloaded asset

The workspace is configurable (--workspace, IMGAGENT_WORKSPACE); jobs resume after interruption and repeated invocations never re-download verified files.

Machine integration

  • --json emits exactly one JSON object on stdout; diagnostics go to stderr, always.
  • Exit codes: 0 success (incl. explicit partial), 1 no usable results, 2 usage, 3 config/dependency.
  • imgagent agent-instructions prints the complete contract an agent can follow without a human.
  • Optional MCP server (pip install 'imgagent[mcp]' + imgagent-mcp) wraps the same functions.
  • Programmatic API: from imgagent import api — search_images, list_candidates, download_selected, run_image_job, get_manifest, … See docs/API_REFERENCE.md.

Configuration

Copy config.example.toml into .imgagent/config.toml or set environment variables (IMGAGENT_*). Everything works with defaults; API keys are read from environment variables only and are never logged.

Environments

Python ≥ 3.10, ~2 runtime dependencies (httpx, Pillow). CPU-only, no browser required for the default provider set. Dockerfile included; GitHub Actions CI runs the full test suite on 3.10–3.13. For read-only filesystems point IMGAGENT_WORKSPACE at a writable path — imgagent detects and warns before work is lost.

Development

pip install -e '.[dev]'
pytest                    # unit suite (mock servers, no network)
pytest -m integration     # opt-in live-source tests
ruff check src tests

Authors & owners

License & attribution

MIT — see LICENSE. imgagent was built as an independent implementation; it studies the architecture of projects like gallery-dl (GPL) and img2dataset (Apache-2.0) without copying their code. Downloaded images carry their own licenses — the manifest records them; you are responsible for respecting them at publication time.

Metadata

Release files for imgagent 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for imgagent 0.1.2
File Size Uploaded
imgagent-0.1.2.tar.gz 75.9 kB Details

Built distribution (wheel)

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

Total release size: 142.9 kB

Release files / imgagent-0.1.2.tar.gz

Download URL imgagent-0.1.2.tar.gz
Size 75.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a10bd18dfcb40a4cc4abfaa4bcd84a4fc62c3eb7b84a897ca23fd934d40b9aba
BLAKE2b-256 checksum
How to use checksums
44e30ffbccd02a640a3d5dfddc64f1f719ec96e7430eac513824c13437ac47b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release files / imgagent-0.1.2-py3-none-any.whl

Download URL imgagent-0.1.2-py3-none-any.whl
Size 67.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a90678c96ffa9eb295c67ffdf9d79399879f236fa21be4a671a8b5da68192e8
BLAKE2b-256 checksum
How to use checksums
a6747c397193bdac3638dbbe7ae09259a3f5d824ab17c3464f34d23730bf0ed9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.15

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

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