Metadata-Version: 2.1
Name: pptx2txt2
Version: 1.1.0
Summary: Extract text from .pptx and .odp files to strings in pure python.
Author-email: Toby Devlin <toby@tobydevlin.com>
Maintainer-email: Toby Devlin <toby@tobydevlin.com>
License: MIT License
        
        Copyright (c) 2024 Toby Devlin
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Repository, https://github.com/GitToby/pptx2txt2.git
Project-URL: Bug Tracker, https://github.com/GitToby/pptx2txt2/issues
Keywords: word,pptx,odp,extract,text,images
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Provides-Extra: dev
Requires-Dist: pytest >=8.1.1 ; extra == 'dev'
Requires-Dist: black >=24.2.0 ; extra == 'dev'
Requires-Dist: ruff >=0.3.2 ; extra == 'dev'
Requires-Dist: mypy >=1.9.0 ; extra == 'dev'
Requires-Dist: pytest-cov >=4.1.0 ; extra == 'dev'
Requires-Dist: pre-commit >=3.5.0 ; extra == 'dev'
Requires-Dist: pytest-benchmark >=4.0.0 ; extra == 'dev'
Requires-Dist: build >=1.1.1 ; extra == 'dev'
Requires-Dist: setuptools-scm >=8.0.4 ; extra == 'dev'

# pptx2txt2

> Extract text from .pptx and .odp files to strings in pure python.

[![codecov](https://codecov.io/gh/GitToby/pptx2txt2/graph/badge.svg?token=OW9957N278)](https://codecov.io/gh/GitToby/pptx2txt2)
[![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/GitToby/pptx2txt2/lint-and-test.yaml)](https://github.com/GitToby/pptx2txt2/actions/workflows/lint-and-test.yaml)
[![GitHub file size in bytes](https://img.shields.io/github/size/GitToby/pptx2txt2/src%2Fpptx2txt2%2F__init__.py)](https://github.com/GitToby/pptx2txt2/blob/master/src/pptx2txt2/__init__.py)
[![PyPI - License](https://img.shields.io/pypi/l/pptx2txt2)](https://github.com/GitToby/pptx2txt2/blob/master/LICENSE.txt)
[![PyPI - Version](https://img.shields.io/pypi/v/pptx2txt2)](https://pypi.org/project/pptx2txt2/)
[![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2FGitToby%2Fpptx2txt2%2Fmaster%2Fpyproject.toml)](https://pypi.org/project/pptx2txt2/)

My personal replacement for [pptx2txt](https://github.com/shakiyam/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`](https://docs.python.org/3/library/os.html#os.PathLike) object, like a filepath or IO stream.

There are 3 methods
- `extract_text_per_slide` returns a `dict[int, str]` of per slide content & notes
- `extract_text` utility to join all slide content
- `extract_images` copy images over to another dir

```python
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 "<number>" 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](https://pytest-benchmark.readthedocs.io) 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](https://github.com/GitToby/docx2txt2) for docx conversion
