Skip to main content

AI-assisted web data extractor — paste a URL + plain-English instruction, get structured JSON or CSV. Resilient to DOM changes via semantic LLM extraction.

Project description

                          _
   ___ _ __   ___  ___ | |_ _   _ ___
  / __| '_ \ / _ \/ __|| __| | | / __|
  \__ \ |_) |  __/ (__ | |_| |_| \__ \
  |___/ .__/ \___|\___| \__|\__,_|___/
      |_|     AI-driven web extractor

PyPI Python tests License: MIT

spectus — paste a URL, describe what you want in plain English, get structured JSON or CSV. Resilient to DOM changes: when CSS selectors fail, falls back automatically to semantic LLM extraction over a facts bundle (structured data + visible text + anchors + label-value pairs). Same loop on any site; no per-site rules.

$ spectus extract https://news.ycombinator.com/ "Top stories: title, points, author, story_url" --output csv
title,points,author,story_url
Mercurial, 20 years and counting,70,ibobev,https://fosdem.org/...
...

Install

pip install spectus
spectus install-browsers              # one-time Playwright Chromium download (~110 MB)
export OPENAI_API_KEY=sk-...          # Windows PowerShell:  $env:OPENAI_API_KEY="sk-..."

Requires Python 3.10+ (tested on 3.10 / 3.11 / 3.12 / 3.13). Linux / macOS / Windows.


30-second tour

CLI

spectus extract https://example.com/products \
    "Each product: title, price, rating, link" --output json

Python (sync — works in Jupyter too)

from spectus import extract

result = extract(
    url="https://example.com/products",
    instruction="Each product: title, price, rating, link",
    openai_api_key="sk-...",          # optional; falls back to OPENAI_API_KEY env
)
print(result["records"])              # list[dict]
print(result["diagnostics"])          # strategy, quality_score, tokens, ...

Python (batched — reuses browser pool)

from spectus import SyncClient

with SyncClient.open(openai_api_key="sk-...") as client:
    r1 = client.extract(url1, "extract X, Y, Z")
    r2 = client.extract(url2, "another instruction")

Python (async — for FastAPI / aiohttp / asyncio code)

from spectus import Client

client = await Client.create(openai_api_key="sk-...")
result = await client.extract(url, instruction)
await client.close()

More patterns in EXAMPLES.md.


Why spectus

  • No selectors to maintain. You describe the data; the system finds it.
  • Survives DOM changes. Semantic fallback reads page meaning, not CSS class names.
  • Learns per domain. Successful extractions become templates → 3–5× faster on subsequent calls, planner LLM skipped.
  • Built-in safety. SSRF gate, robots.txt cache, per-domain rate limit. No CAPTCHA solving, no auth bypass.
  • Debug-friendly. Every job writes a full artifact bundle to disk: raw HTML, rendered HTML, screenshots, compact page representation, every LLM I/O, validation report.

What you get back

extract() always returns a plain dict:

{
  "status": "success" | "partial_success" | "failed",
  "url": "...",
  "instruction": "...",
  "records": [ {...}, {...}, ... ],          # list of dicts; single dict for single-entity
  "diagnostics": {
    "strategy_used":    "semantic_extraction" | "repeated_dom_selector" | ...,
    "page_type":        "article" | "product_listing" | ...,
    "static_or_browser": "static" | "browser",
    "records_found":    int,
    "quality_score":    0.0 - 1.0,
    "field_coverage":   {field_name: 0.0-1.0},
    "missing_required": {field_name: count},
    "repair_attempts":  int,
    "template_used":    bool,
    "template_id":      uuid | null,
    "runtime_ms":       int,
    "llm_calls":        int,
    "llm_tokens_in":    int,
    "llm_tokens_out":   int,
    "warnings":         [str, ...]
  },
  "message": null | "repair hint when partial"
}

How it works (one paragraph)

Every request runs: URL normalize → SSRF + robots + rate-limit → parallel(intent-LLM, static-fetch + analyze) → template lookup → planner-LLM → executor → validator → repair loop (≤ 2 attempts) → resilience pass: semantic LLM extraction over a facts bundle, per-field merge with type-aware tie-breakers → save winning strategy as template → return JSON or CSV with diagnostics.

Seven extraction strategies, chosen automatically:

Strategy When
structured_data JSON-LD / OpenGraph / __NEXT_DATA__ / __NUXT__ present
repeated_dom_selector Repeating containers (cards / rows / tiles) detected
single_dom_selector Page-level data with clear DOM hooks
table_extraction HTML tables with sensible headers
article_extraction Long-form content (article, blog, encyclopedia)
visible_text_regex Fallback regex over visible text
semantic_extraction LLM reads facts bundle — no DOM dependency, survives DOM redesigns

CLI reference

spectus extract URL "instruction"  [--browser auto|force|never] [--max-records N] [--output table|json|csv]
spectus templates                  [--status candidate|active|needs_review|deprecated] [--output table|json]
spectus migrate
spectus install-browsers
spectus version

Configuration

Set via env var (or pass to Client.create(settings={...})).

Var Default Purpose
OPENAI_API_KEY Required (or pass as openai_api_key= kwarg)
OPENAI_MODEL_INTENT gpt-4o-mini Intent parser model
OPENAI_MODEL_PLAN gpt-4.1 Planner + semantic model
OPENAI_MODEL_REPAIR gpt-4.1 Repair model
DB_URL sqlite+aiosqlite:///./spectus.db Swap to postgresql+asyncpg://... for Postgres
ARTIFACTS_DIR ./artifacts Per-job debug bundles
BROWSER_POOL_SIZE 3 Playwright contexts
RATE_LIMIT_RPS 1.0 Per-domain token-bucket refill
ALLOW_PRIVATE_TARGETS false Set true only for local fixture testing
JOB_DEADLINE_SEC 180 Hard wall-time per request
LLM_INTENT_TIMEOUT_SEC 45 Intent parser timeout
LLM_PLANNER_TIMEOUT_SEC 60 Planner timeout
LLM_REPAIR_TIMEOUT_SEC 60 Repair timeout

GPT-5 / o-series support: pass OPENAI_MODEL_*=gpt-5-nano and bump timeouts. Client auto-uses max_completion_tokens + reasoning_effort=low for those models.


Compliance + safety (built-in)

  • SSRF: blocks private / loopback / link-local / reserved IPs before any fetch.
  • Robots.txt: 1h-TTL cache, fail-open on 5xx.
  • Per-domain rate-limit token bucket.
  • Allowed selector attributes: text, href, src, alt, title, class, id, value, data-*, aria-*. Anything else rejected at the Pydantic boundary.
  • jQuery extensions (:has(), :is(), :visible, etc.) rejected. :contains('text') translated server-side.
  • No CAPTCHA solve, no auth bypass, no anti-bot evasion. Out of scope by design.

Links


License

MIT © 2026 Mrrobi

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spectus-0.2.4.tar.gz (61.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spectus-0.2.4-py3-none-any.whl (74.1 kB view details)

Uploaded Python 3

File details

Details for the file spectus-0.2.4.tar.gz.

File metadata

  • Download URL: spectus-0.2.4.tar.gz
  • Upload date:
  • Size: 61.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spectus-0.2.4.tar.gz
Algorithm Hash digest
SHA256 c68c89dacf0403eba8630ca64cbc1c8a7ae934adc5c379724ad19ea3bd1898ba
MD5 75bbd1c58a10dbf794094b251e396b1b
BLAKE2b-256 2a4f911007c5456b9296af48ed8b1b850942746b02364f5ed0df4f23104f21b9

See more details on using hashes here.

Provenance

The following attestation bundles were made for spectus-0.2.4.tar.gz:

Publisher: publish.yml on Mrrobi/spectus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spectus-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: spectus-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 74.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spectus-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 08b84c3c839853f378fbcf6df2bad83df95818ab5a5747a1ea12a3fc60eca828
MD5 cf5848f1167da4454d421ca16d6d6209
BLAKE2b-256 7c11ae2fb063b9aa2b7bea82fe526001e96f550670abf3f3bf08cb8f8358e7c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for spectus-0.2.4-py3-none-any.whl:

Publisher: publish.yml on Mrrobi/spectus

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page