Skip to main content

Python wrapper for the Ethos document evidence CLI.

Project description

Ethos Python Package

This directory contains the ethos-pdf Python package source for Ethos.

The package exposes a public semver API beginning at 0.1.0 for Python >=3.8. Patch releases must not break public function signatures, exception classes, or documented return shapes. Minor releases may add backward-compatible API, and major releases may break API after a release-scope decision.

Public API:

  • EthosCli
  • EthosPythonSurfaceError
  • EthosNotFoundError
  • EthosTimeoutError
  • EthosCommandError
  • PdfiumNotFoundError
  • InvalidPdfError
  • CorruptPdfError
  • ParseTimeoutError
  • EthosOutputError
  • parse_pdf_json
  • parse_pdf_markdown
  • parse_pdf_text
  • crop_element

The current module is intentionally thin: it shells out to a caller-provided local ethos CLI binary and returns ethos doc parse output or source-bound ethos crop_element JSON. It can pass caller-provided source PDF and crop artifact directory arguments for rendered crop artifacts. It does not bundle PDFium, does not publish hosted surfaces, and does not expand parser behavior. The Rust CLI remains the source of truth.

PDFium-backed parse and crop paths require caller-provided PDFium through ETHOS_PDFIUM_LIBRARY_PATH. Importing ethos_pdf does not require PDFium. If PDFium is missing, the wrapper raises PdfiumNotFoundError and preserves the underlying CLI stderr so callers can show the setup guidance from QUICKSTART.md or docs/pdfium-manual-setup.md.

Exceptions

All wrapper-owned exceptions inherit from EthosPythonSurfaceError.

Subprocess failures inherit from EthosCommandError and expose command, returncode, stdout, and stderr. When the CLI emits its stable JSON error envelope on stderr, the wrapper maps by error.code; otherwise it falls back to the documented exit code:

CLI condition Exit Python exception
missing caller-provided PDFium any non-zero exit with PDFium setup stderr PdfiumNotFoundError
invalid_pdf 3 InvalidPdfError
corrupt_pdf 4 CorruptPdfError
parse_timeout 10 ParseTimeoutError
any other non-zero CLI exit other EthosCommandError

Wrapper-side timeouts raised by subprocess.run(..., timeout=...) use EthosTimeoutError. Missing input files raise Python FileNotFoundError before invoking the CLI.

Run the focused tests with:

make python-surface-test

The tests use a fake local command, so they do not require PDFium.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ethos_pdf-0.1.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file ethos_pdf-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ethos_pdf-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ethos_pdf-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e0292276e711e75d4f7e1bb8c2c6137c6e89d4c343dd308943eb9b22094ea451
MD5 102f3bdf4c3311f35ac4692f33779d7b
BLAKE2b-256 3dc2406c298e37fca7617c97ff9d74a30ab0a017a22f6025c8f2b74c25b5b39c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page