Skip to main content

A modern REST client for Apache Tika server

Project description

Tika Rest Client

PyPI - Version PyPI - Python Version codecov


Table of Contents

Features

  • Simplified: No need to worry about XML or JSON responses, downloading a Tika jar file or Python 2
  • Support for Tika 2+ only
  • Based on the modern httpx library
  • Full support for type hinting
  • Nearly full test coverage run against an actual Tika server for multiple Python and PyPy versions
  • Uses HTTP multipart/form-data to stream files to the server (instead of reading into memory)
  • Optional compression for parsing from a file content already in a buffer (as opposed to a file)

Installation

pip3 install tika-client

Usage

from pathlib import Path
from tika_client import TikaClient

test_file = Path("sample.docx")


with TikaClient("http://localhost:9998") as client

    # Extract a document's metadata
    metadata = client.metadata.from_file(test_file)

    # Get the content of a document as HTML
    data = client.tika.as_html.from_file(test_file)

    # Or as plain text
    text = client.tika.as_text.from_file(test_file)

    # Content and metadata combined
    data = client.rmeta.as_text.from_file(test_file)

    # The mime type can also be given
    # This allows Content-Type to be set most accurately
    text = client.tika.as_text.from_file(test_file,
                                         "application/vnd.openxmlformats-officedocument.wordprocessingml.document")

The Tika REST API documentation can be found here. At the moment, only the metadata, tika and recursive metadata endpoints are implemented.

Unfortunately, the set of possible return values of the Tika API are not very well documented. The library makes a best effort to extract relevant fields into type properties where it understands more about the mime type of the document (as returned by Tika). This includes information like created/modified information as time zone aware datetime objects. The full JSON response is always available to the user under the .data attribute.

When a particular key is not present in the response, all properties will return None instead.

Why

Only one other library for interfacing with Tika exists that I know of. I find it too complicated, trying to handle a lot of differing uses.

The biggest issue I have with the library is its downloading and running of a jar file if needed. To me, an API client should only interface to the API and not try to provide functionality to start the API as well. The user is responsible for providing the server with the Tika version they desire.

The library also provides a lot of knobs to turn, but I argue most developers will not want to configure XML as the response type, they just want the data, already parsed to the maximum extend possible.

This library attempts to provide a simpler interface, minimal lines of code and typing of the parsed response.

License

tika-client is distributed under the terms of the Mozilla Public License 2.0 license.

Project details


Download files

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

Source Distribution

tika_client-0.7.0.tar.gz (2.2 MB view details)

Uploaded Source

Built Distribution

tika_client-0.7.0-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file tika_client-0.7.0.tar.gz.

File metadata

  • Download URL: tika_client-0.7.0.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for tika_client-0.7.0.tar.gz
Algorithm Hash digest
SHA256 be6cb0377eb5f03809c6bc059b43a6404b3357819dcff25d83b3d564c25a19aa
MD5 61a662e652001992004c400008d85121
BLAKE2b-256 0ec3c037a15612245f3e930af0ed6445703446ba89141b3f61581d4df1f896b7

See more details on using hashes here.

File details

Details for the file tika_client-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: tika_client-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for tika_client-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 734fdbdcdca33e65de7fd6aa50870271bc6cd41b5decce5f098469a2b63bff15
MD5 cabee3d12db7a960f2532486d9b7f1bd
BLAKE2b-256 ef553b8c7eb9f6a54100e1f101267a0ef43a749c272f23bd3957ce7167e973ce

See more details on using hashes here.

Supported by

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