Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

polytext

polytext

PyPI - Version PyPI Build PyPI - Downloads PyPI Downloads PyPI - Python Version

Doc Utils

A Python package for document conversion and text extraction.

Features

  • Convert various document formats (DOCX, ODT, PPT, etc.) to PDF
  • Extract text from PDF, Markdown, IMAGE, and audio files
  • Support for both local files and S3/GCS cloud storage
  • Multiple PDF parsing backends (PyPDF, PyMuPDF)
  • Transcribe audio & video files (local or cloud) to text/markdown
  • Extract YouTube video transcripts
  • Extract text from URLs

Installation

# Library only – assumes system requirements are already present
pip install polytext

Heads-up: Polytext’s PDF generator relies on [WeasyPrint] under the hood.
The PyPI wheel contains only Python code; you still need WeasyPrint’s native libraries (Pango, Cairo, GDK-PixBuf, HarfBuzz, Fontconfig) installed at the OS level.

System requirements

Requirement Notes macOS (Homebrew) Ubuntu / Debian
Python Supported on 3.11 – 3.13
WeasyPrint still requires its native libraries
brew install python@3.11 sudo apt install python3.11
WeasyPrint – native stack installs Pango, Cairo, etc. brew install weasyprint sudo apt install weasyprint
LibreOffice used for Office → PDF conversion brew install --cask libreoffice sudo apt install libreoffice

Usage

Converting Documents to PDF

from polytext import convert_to_pdf, ConversionError

try:
    # Convert a document to PDF
    pdf_path = convert_to_pdf('input.docx', 'output.pdf')
    print(f"PDF saved to: {pdf_path}")
except ConversionError as e:
    print(f"Conversion failed: {e}")

Features that require the API key for Google Gemini are:

  • audio
  • video
  • image
  • youtube
from polytext.loader.base import BaseLoader

llm_api_key = "your_google_gemini_api_key"  # Set your Google Gemini API key here

# Instantiate the loader 
loader = BaseLoader(llm_api_key=llm_api_key)

Text or Markdown Extraction

from polytext.loader.base import BaseLoader

markdown_output = False # Change if you want to extract text as markdown
source = "local" # Change to "cloud" if you want to extract from cloud storage (s3 or GCS)

# Instantiate the loader (optionally set markdown_output, llm_api_key, etc.)
loader = BaseLoader(markdown_output=markdown_output, source=source)

# Extract text from a local file
result = loader.get_text(input_list=["/path/to/document.docx"])
print(result["text"])
# Extract text from cloud file
result = loader.get_text(input_list=["s3://your-bucket/path/to/document.docx"])
print(result["text"])

# Extract text from a markdown file (local)
result = loader.get_text(input_list=["/path/to/document.md"])
print(result["text"])
# Extract text from cloud file
result = loader.get_text(input_list=["s3://your-bucket/path/to/document.md"])
print(result["text"])

# Extract text from an audio file (local)
result = loader.get_text(input_list=["/path/to/audio.mp3"])
print(result["text"])
# Extract text from cloud file
result = loader.get_text(input_list=["s3://your-bucket/path/to/audio.mp3"])
print(result["text"])

# Extract text from a video file (local)
result = loader.get_text(input_list=["/path/to/video.mp4"])
print(result["text"])
# Extract text from cloud file
result = loader.get_text(input_list=["s3://your-bucket/path/to/video.mp4"])
print(result["text"])

# Extract text from Image (local)
result = loader.get_text(input_list=["/path/to/image.jpg"])
print(result["text"])
# Extract text from cloud file
result = loader.get_text(input_list=["s3://your-bucket/path/to/image.jpg"])
print(result["text"])

# Extract transcript from a YouTube video
result = loader.get_text(input_list=["https://www.youtube.com/watch?v=xxxx"])
print(result["text"])

# Extract text from a URL
result = loader.get_text(input_list=["https://www.domain-name.com/path"])
print(result["text"])

S3 authentication

By default, Polytext uses the standard boto3 credential chain when loading s3:// inputs (environment variables, AWS profiles, IAM roles, and other boto3-supported providers).

For runtimes that need to assume an AWS role through Google OIDC, STS web identity authentication can be enabled explicitly:

from polytext.loader.base import BaseLoader

loader = BaseLoader(
    aws_auth_mode="sts_web_identity",
    aws_role_arn="arn:aws:iam::111122223333:role/ExampleRole",
    aws_region="eu-central-1",
    aws_role_session_name="polytext-session",
    gcp_id_token_audience="example-gcp-audience",
)

The same configuration can also come from environment variables:

POLYTEXT_AWS_AUTH_MODE=sts_web_identity
AWS_ROLE_ARN=arn:aws:iam::111122223333:role/ExampleRole
AWS_REGION=eu-central-1
AWS_ROLE_SESSION_NAME=polytext-session
GCP_ID_TOKEN_AUDIENCE=example-gcp-audience
GOOGLE_APPLICATION_CREDENTIALS=/absolute/path/to/service_account.json

Polytext uses the temporary STS credentials only to create the S3 client. It does not export them to os.environ and does not reset boto3's global session.

License

MIT Licence

Metadata

Release files for polytext 0.2.8b4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polytext 0.2.8b4
File Size Uploaded Provenance Actions
polytext-0.2.8b4.tar.gz 137.0 kB Without provenance Details for polytext-0.2.8b4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for polytext 0.2.8b4
File Interpreter ABI Platform Actions
polytext-0.2.8b4-py3-none-any.whl Python 3 none any Details for polytext-0.2.8b4-py3-none-any.whl

Total release size: 252.5 kB

Release files / polytext-0.2.8b4.tar.gz

Download URL polytext-0.2.8b4.tar.gz
Size 137.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ef21bd42f01d222487fdf4b2a97e712f7bdd308fdc9539c0fff9548d42ef01e2
BLAKE2b-256 checksum
How to use checksums
c18db4b51334a7d1ef96ca96e867448533a877dd6faea9e6def6982016c3e37c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / polytext-0.2.8b4-py3-none-any.whl

Download URL polytext-0.2.8b4-py3-none-any.whl
Size 115.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c0470f637a83d0bf7dcd7dcd4601f143a2473f4cb35d61ab5f2f27229be23a9
BLAKE2b-256 checksum
How to use checksums
15fc9cf76fc585295e2770de764513a99bfc93bb75d4ac15064c8c52be303251
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for polytext 0.2.8b4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page