Doclingdocling 2.127.0 · Python 3.10+
0%
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
26 small wins to finish your pathNext lesson

Docling from the command line

Installing Docling also installs a command. For converting a folder once, it is the whole program you were about to write.

bash
docling shipping.md --to md --output out

That converts one file and writes out/shipping.md. The snippets below run the same command through Python so this page can capture what it produced; on your machine you would type the line above.

Example
import subprocess
import sys
from pathlib import Path

def docling(*arguments):
    subprocess.run([sys.executable, "-m", "docling.cli.main", *arguments], check=True)

docling("shipping.md", "--to", "md", "--output", "out")
print(Path("out/shipping.md").read_text()[:44])

The output file is named after the input, with an extension for the format asked for. Give it several inputs and it converts them all in one process, which is the command line version of lesson 18's advice about reusing the converter.

Example
docling("shipping.md", "refunds.html", "orders.csv",
        "--to", "md", "--output", "many")
print(sorted(path.name for path in Path("many").iterdir()))

Chunks without writing any code

--to chunks runs the chunker from part 6 and writes one JSON object per chunk.

Example
docling("shipping.md", "--to", "chunks", "--output", "cut")
first = Path("cut/shipping.chunks.jsonl").read_text().splitlines()[0]
print(first[:96])

Text, headings, the addresses it came from and a token count, ready for an indexer. --chunks-max-tokens and --chunks-tokenizer set the same things lesson 24 sets in Python.

One output format lies

The list of output formats includes text. Ask for it and look at what lands on disk.

Example
docling("refunds.html", "--to", "text", "--output", "plain")
print(Path("plain/refunds.txt").read_text())

A file called .txt containing Markdown, hashes and table pipes and all. The command asks for plain text using the deprecated argument from lesson 10, and because that argument is now ignored the Markdown comes through untouched. export_to_text in Python still does the right thing; the command line does not.

The useful flags. --from pdf restricts the inputs the way lesson 19's allowed_formats does, --no-ocr is lesson 15's switch, --artifacts-path points at prefetched models, and --help lists about fifty more.
Try it yourself
  • Run docling returns.pdf --to json --output out and load the result with DoclingDocument.load_from_json.
  • Add --chunks-max-tokens 20 and count the lines in the chunk file.
  • Point the command at a file that does not exist and read the message and the exit code.

Little by little, you're building something great.