deft / guides

Deft or a Python script for common file jobs

For a file job, an agent or a person usually reaches for a Python library. This page lists common jobs, the library people use for each, and the deft command that does the same job.

PDF

JobUsual Python routeDeft
Merge filespypdf: a PdfWriter, append each file, writedeft pdf merge a.pdf b.pdf -o all.pdf
Split into pagespypdf: loop over pages, one writer eachdeft pdf split doc.pdf -o pages/
Reorder or keep pagespypdf: pick pages by index, mind zero-based numbersdeft pdf select doc.pdf --pages 3,1-2 -o out.pdf
Make smallerOften Ghostscript from a subprocess, or pikepdfdeft pdf compress doc.pdf --target-size 2MB -o small.pdf
Extract textpypdf or pdfminer.sixdeft pdf to-text doc.pdf -o doc.txt
Stamp "DRAFT"reportlab to draw a page, pypdf to merge it onto each pagedeft pdf watermark doc.pdf --text DRAFT -o draft.pdf

Images

JobUsual Python routeDeft
ResizePillow: open, compute the size that keeps the ratio, resize, savedeft image resize photo.jpg --size 800x -o small.jpg
Convert formatPillow, plus a plugin for HEIC or AVIFdeft image convert photo.jpg --to png -o photo.png
Make lighterPillow with a hand-picked qualitydeft image compress photo.jpg -o lighter.jpg
Remove metadataPillow or piexif, per formatdeft image strip photo.jpg -o clean.jpg
Photos into a PDFPillow save(..., save_all=True) or img2pdfdeft image to-pdf a.jpg b.jpg -o album.pdf

Documents and slides

JobUsual Python routeDeft
Markdown to PDFA Markdown library to HTML, then a browser or WeasyPrint to PDFdeft md to-pdf notes.md -o notes.pdf
Markdown to Wordpandoc from a subprocessdeft md to-docx notes.md -o notes.docx
Word to Markdownpython-docx and your own mapping, or mammothdeft doc to-md letter.docx -o letter.md
Slide text and notespython-pptx: walk shapes and notes slidesdeft slides to-text deck.pptx --notes -o deck.txt
Web page to MarkdownBeautifulSoup and markdownifydeft html to-md page.html -o page.md

Spreadsheets

JobUsual Python routeDeft
CSV to Excelpandas and openpyxldeft sheet convert people.csv --to xlsx -o table.xlsx
Pivot tablepandas pivot_tabledeft sheet pivot sales.csv --rows city --columns year --values amount -o pivot.csv

What the difference is

Deft does not replace Python. Custom analysis, unusual formats and one-of-a-kind logic still belong in a script. Run deft find "<what you want>" first: if it says no command does this, write the script.

Every deft command above was run on deft 0.1.0 before this page was published. See every command's test cases for inputs and outputs.