pptx2txt2
Extract text from .pptx and .odp files to strings in pure python.
My personal replacement for pptx2txt.
It's intended to be very simple and provide some utilities to extract content similar to the original lib.
Usage
Install with your fave package manager (anything that pulls from pypi will work. pip, poetry, pdm, etx)
pip install pptx2txt2
Use with any PathLike object, like a filepath or IO stream.
There are 3 methods
extract_text_per_slidereturns adict[int, str]of per slide content & notesextract_textutility to join all slide contentextract_imagescopy images over to another dir
import io
from pathlib import Path
import pptx2txt2
# path
text = pptx2txt2.extract_text("path/to/my.pptx")
text_per_slide = pptx2txt2.extract_text_per_slide("path/to/my.pptx")
image_paths = pptx2txt2.extract_images("path/to/my.pptx", "path/to/images/out")
# actual Paths
pptx_path = Path(__file__).parent / "my.pptx"
image_out = Path(__file__).parent / "my" / "images"
image_out.mkdir(parents=True)
text2 = pptx2txt2.extract_text(pptx_path)
text_per_slide2 = pptx2txt2.extract_text_per_slide(pptx_path)
image_paths2 = pptx2txt2.extract_images(pptx_path, image_out)
# bytestreams
pptx_bytes = b"..."
bytes_io = io.BytesIO(pptx_bytes)
text3 = pptx2txt2.extract_text(bytes_io)
text_per_slide3 = pptx2txt2.extract_text_per_slide(bytes_io)
image_paths3 = pptx2txt2.extract_images(bytes_io, "path/to/images/out")
Considerations
- Doesn't preserve whitespace or styling like the original; new slides, tabs and the like are now just spaces.
- headers and footers contain "<#>" of "" where there would be a number, unlike the original which removed them
- pptx files have a UUID in text where images were.
Benchmarks
Basic benchmarking using pytest-benchmark with a basic test document on my M1 macbook and on GithubActions.
Macbook:
------------------------------------------------ benchmark: 1 tests -----------------------------------------------
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
-------------------------------------------------------------------------------------------------------------------
test_benchmark_pptx2txt2 2.4470 7.1815 2.5762 0.4344 2.4987 0.1050 2;7 388.1666 122 1
-------------------------------------------------------------------------------------------------------------------
GitHub Actions, python 3.12:
------------------------------------------------ benchmark: 1 tests ------------------------------------------------
Name (time in ms) Min Max Mean StdDev Median IQR Outliers OPS Rounds Iterations
--------------------------------------------------------------------------------------------------------------------
test_benchmark_pptx2txt2 4.0548 11.4523 4.2387 0.8312 4.1343 0.0484 3;11 235.9197 217 1
--------------------------------------------------------------------------------------------------------------------
Also See
- docx2txt2 for docx conversion
Metadata
Release files for pptx2txt2 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pptx2txt2-1.1.0.tar.gz | 6.7 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pptx2txt2-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.7 MB
Release files / pptx2txt2-1.1.0.tar.gz
| Download URL | pptx2txt2-1.1.0.tar.gz |
|---|---|
| Size | 6.7 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa71cf0799c60266c3ffa415bfb5b8c61364cb4814a92a4ce7e96901f7aecfcc
|
|
BLAKE2b-256 checksum How to use checksums |
2012fe9375794a8287fe7d477711fc1b4cea5941f869ed077f6809fccb36a8e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / pptx2txt2-1.1.0-py3-none-any.whl
| Download URL | pptx2txt2-1.1.0-py3-none-any.whl |
|---|---|
| Size | 6.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0041b57f814039399b317367b5e0e54ca7d3ca5800b170fb906788116f834141
|
|
BLAKE2b-256 checksum How to use checksums |
090e8d810dd84b90381ee4f29110a742e523609a35d8bb255c163d14322349b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|