gleanly
All-in-one, open-source text acquisition for AI. Turn any URL or file into clean
Markdown with a trust score, compliance metadata ("can I use this for AI
training?") and provenance for every block. One pip install, one process, no Docker.
pip install gleanly # core
pip install "gleanly[pdf,ocr]" # + PDFs and OCR (nothing else to install)
Alpha: the API may still change between 0.x releases (see the
versioning policy).
Feedback and bug reports are very welcome.
from gleanly import load
doc = load("https://example.com/article")
print(doc.markdown) # clean Markdown (tables and code preserved)
print(doc.quality.score) # 0..1, comparable across web, PDF and OCR sources
print(doc.compliance.ai_use) # "allowed" | "disallowed" | "unclear" + conditions and evidence
print(doc.blocks[0].provenance) # URL + XPath + character span in the Markdown
print(doc.fetch_trace.steps) # every fetch-ladder step that was tried, and why
Async: doc = await aload(url). Batch with shared rate limits: async with Client() as c: ...
CLI (if gleanly is "not recognized", pip's Scripts folder is not on your PATH: use
python -m gleanly ... instead, it works everywhere):
gleanly load https://example.com/article -o article.md
gleanly load https://example.com/article -o article.json # full Document as JSON
PDFs, scans and images
pip install "gleanly[pdf]" # native PDFs
pip install "gleanly[ocr]" # + OCR with glyphly: no other program to install
OCR without Tesseract: the [ocr] extra installs glyphly,
gleanly's own OCR engine: no other program to install (its models, about 31 MB, download
once on first use; other scripts such as Cyrillic or Arabic fetch theirs when a page needs
them), and on gleanly's
held-out OCR benchmark it makes fewer errors (standard pages: under 0.05% of characters
wrong vs 0.6% with Tesseract). Choose an engine with ocr_engine="glyphly" /
"tesseract" or --ocr-engine; the default "auto" prefers glyphly when installed.
Tesseract is still used when you ask for it and have it installed.
The script is detected by itself (Latin, Cyrillic, Greek, Arabic, Devanagari, Tamil, Telugu,
Thai, Chinese, Japanese, Korean, and since glyphly 0.2.0a3 also Malayalam, Bengali, Assamese,
Kannada, Gujarati, Punjabi and Odia). Naming the language still helps when you know it:
load("scan.jpg", ocr_lang="mal") or gleanly load scan.jpg --ocr-lang mal (eng+ben for
mixed pages). On real scanned pages in 34 languages, glyphly beats Tesseract in 13 and is
even in 10 (see the glyphly README).
doc = load("report.pdf") # or "scan.jpg", or a URL serving either
doc.blocks[3].provenance # kind="pdf" (text layer) or "image" (OCR), page, bbox
doc.quality.ocr_confidence # the OCR engine's word confidence, when OCR was used
doc.quality.extraction_confidence # PDFs: agreement between the text layer and OCR
What gleanly adds on top of plain PDF text extraction and Tesseract:
- Headings, lists and re-joined hyphenation; running headers, footers and page numbers
learned across pages and removed.
- Scanned pages inside a PDF are OCR'd automatically.
- Text-layer check: pages whose hidden text looks broken, plus a small sample, are
compared with OCR; a layer that does not match the page (a wrong font map, a poor old
OCR layer) is replaced and the page is named in a warning.
- OCR clean-up tuned on a benchmark: 0.77% characters wrong on held-out pages against
16.1% for plain Tesseract, mostly by fixing shadows, faint print and phone photos
(bench/README.md).
Search
from gleanly import search
resp = search("tide pool animals") # Wikipedia by default; Brave/SearXNG when configured
for r in resp.results:
print(r.score, r.hit.url, r.hit.engines) # which engines found it, and at what rank
print(r.document.quality.score, r.document.compliance.ai_use) # every result is a full Document
gleanly search "tide pool animals" -n 5 --exclude-disallowed
Backends use official APIs only: Wikipedia (no key), Brave Search (BRAVE_API_KEY) and
your own SearXNG instance (SEARXNG_URL). Results from several engines are merged with
reciprocal rank fusion, then every page is fetched through load() (robots.txt, rate
limits, trust score, AI-use verdict, provenance). Ranking v0 combines query relevance,
the fused rank and the page's trust score; it will be tuned on a search benchmark.
Source agreement (experimental): resp.agreement lists numeric and date facts that
two or more results agree on (corroborated) or contradict (conflicts), each quoting
every source with its exact location. It is strict on purpose (a conflict needs nearly
the same sentence with a different number) and reports candidates to check, not verdicts.
Status
Phases 1 (web pages) and 2 (PDFs and OCR) are done; Phase 3 (search) is in progress. See
docs/status.md.
| Capability |
Status |
| Web page → Markdown + metadata |
Done (v0) |
Fetch ladder: HTTP → embedded data (JSON-LD, __NEXT_DATA__) → Playwright |
Done (v0) |
| robots.txt (RFC 9309), per-host rate limiting, honest User-Agent |
Done |
Compliance: TDMRep, ai.txt, noai, AI-crawler opt-outs, license detection, PII flags |
Done (v0) |
| Quality report + trust score |
Done (v0, uncalibrated) |
Native PDFs (gleanly[pdf]): headings, lists, page + bounding-box provenance, running headers removed |
Done (v0) |
OCR for images and scanned PDF pages (gleanly[ocr], glyphly; Tesseract optional): columns and tables in reading order, 20 languages, OCR confidence in the trust score |
Done (v0) |
search() with reranking and cross-source agreement |
Phase 3 |
| Archive fallbacks, crawling, server mode, benchmark |
Phase 4 |
Ethics by design
The library identifies itself honestly (gleanly/<version> (+project URL)), respects
robots.txt by default, rate-limits per host and never tries to evade blocks: no fingerprint
spoofing, CAPTCHA solving or proxy rotation. When a site refuses access, you get a clear
explanation in FetchError.trace.
Install (development)
uv sync # core + dev tools
uv run pytest
uv sync --extra browser && uv run playwright install chromium # optional rung 3
License
Apache-2.0
Contributing and security
See CONTRIBUTING.md, docs/architecture.md,
SECURITY.md and the CHANGELOG.