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
| Job | Usual Python route | Deft |
| Merge files | pypdf: a PdfWriter, append each file, write | deft pdf merge a.pdf b.pdf -o all.pdf |
| Split into pages | pypdf: loop over pages, one writer each | deft pdf split doc.pdf -o pages/ |
| Reorder or keep pages | pypdf: pick pages by index, mind zero-based numbers | deft pdf select doc.pdf --pages 3,1-2 -o out.pdf |
| Make smaller | Often Ghostscript from a subprocess, or pikepdf | deft pdf compress doc.pdf --target-size 2MB -o small.pdf |
| Extract text | pypdf or pdfminer.six | deft pdf to-text doc.pdf -o doc.txt |
| Stamp "DRAFT" | reportlab to draw a page, pypdf to merge it onto each page | deft pdf watermark doc.pdf --text DRAFT -o draft.pdf |
Images
| Job | Usual Python route | Deft |
| Resize | Pillow: open, compute the size that keeps the ratio, resize, save | deft image resize photo.jpg --size 800x -o small.jpg |
| Convert format | Pillow, plus a plugin for HEIC or AVIF | deft image convert photo.jpg --to png -o photo.png |
| Make lighter | Pillow with a hand-picked quality | deft image compress photo.jpg -o lighter.jpg |
| Remove metadata | Pillow or piexif, per format | deft image strip photo.jpg -o clean.jpg |
| Photos into a PDF | Pillow save(..., save_all=True) or img2pdf | deft image to-pdf a.jpg b.jpg -o album.pdf |
Documents and slides
| Job | Usual Python route | Deft |
| Markdown to PDF | A Markdown library to HTML, then a browser or WeasyPrint to PDF | deft md to-pdf notes.md -o notes.pdf |
| Markdown to Word | pandoc from a subprocess | deft md to-docx notes.md -o notes.docx |
| Word to Markdown | python-docx and your own mapping, or mammoth | deft doc to-md letter.docx -o letter.md |
| Slide text and notes | python-pptx: walk shapes and notes slides | deft slides to-text deck.pptx --notes -o deck.txt |
| Web page to Markdown | BeautifulSoup and markdownify | deft html to-md page.html -o page.md |
Spreadsheets
| Job | Usual Python route | Deft |
| CSV to Excel | pandas and openpyxl | deft sheet convert people.csv --to xlsx -o table.xlsx |
| Pivot table | pandas pivot_table | deft sheet pivot sales.csv --rows city --columns year --values amount -o pivot.csv |
What the difference is
- Nothing to install per job. Deft is one binary. A script needs the right library in the right environment.
- Fewer rounds. Real files break scripts in ways the first draft did not expect. Deft's commands are tested on real downloaded files, and an error comes with a code and a hint.
- Short output. A command prints one line, so an agent reads less.
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.