├── .coverage ├── .github ├── FUNDING.yml └── workflows │ └── documentation.yml ├── .gitignore ├── .travis.yml ├── LICENSE.txt ├── MANIFEST.IN ├── README.md ├── docs ├── Makefile ├── make.bat └── source │ ├── conf.py │ ├── index.rst │ ├── modules.rst │ ├── readme.rst │ ├── setup.rst │ ├── tika.rst │ └── tika.tests.rst ├── requirements.txt ├── setup.py └── tika ├── __init__.py ├── config.py ├── detector.py ├── language.py ├── parser.py ├── pdf.py ├── tests ├── __init__.py ├── arguments │ ├── test_remote_content.csv │ ├── test_remote_metadata.csv │ └── test_unsupported.csv ├── files │ └── rwservlet.pdf ├── memory_benchmark.py ├── test_benchmark.py ├── test_from_file_service.py ├── test_prep.txt ├── test_ssl_link.py ├── test_tika.py ├── tests_params.py ├── tests_unpack.py └── utils.py ├── tika.py ├── translate.py └── unpack.py /.coverage: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: chrismattmann 4 | custom: ["https://www.paypal.me/MattmannAI", "https://venmo.com/Chris-Mattmann"] 5 | -------------------------------------------------------------------------------- /.github/workflows/documentation.yml: -------------------------------------------------------------------------------- 1 | # Simple workflow for deploying static content to GitHub Pages 2 | name: Generate and deploy documentation 3 | 4 | on: 5 | # Runs on pushes targeting the default branch 6 | push: 7 | branches: ["main", "master", "add-automated-documentation"] 8 | 9 | # Allows you to run this workflow manually from the Actions tab 10 | workflow_dispatch: 11 | 12 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages 13 | permissions: 14 | contents: write 15 | pages: write 16 | id-token: write 17 | 18 | # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. 19 | # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. 20 | concurrency: 21 | group: "pages" 22 | cancel-in-progress: false 23 | 24 | jobs: 25 | # Single deploy job since we're just deploying 26 | deploy: 27 | environment: 28 | name: github-pages 29 | url: ${{ steps.deployment.outputs.page_url }} 30 | runs-on: ubuntu-latest 31 | steps: 32 | - name: Checkout 33 | uses: actions/checkout@v4 34 | - name: Install dependencies 35 | run: | 36 | pip install sphinx furo myst-parser 37 | - name: Sphinx APIDoc 38 | run: | 39 | sphinx-apidoc -f -o docs/source/ . 40 | - name: Sphinx build 41 | run: | 42 | sphinx-build -b html docs/source/ docs/build/html 43 | - name: Setup Pages 44 | uses: actions/configure-pages@v5 45 | - name: Upload artifact 46 | uses: actions/upload-pages-artifact@v3 47 | with: 48 | # Upload entire repository 49 | path: './docs/build/html' 50 | - name: Deploy to GitHub Pages 51 | id: deployment 52 | uses: actions/deploy-pages@v4 53 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.project 2 | /.pydevproject 3 | /tika.egg-info 4 | /build 5 | /dist 6 | *.log 7 | /.settings/ 8 | /tika/*.pyc 9 | /tika/*/*.pyc 10 | .DS_Store 11 | /setup.cfg 12 | .idea 13 | 14 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | python: 4 | - "2.7" 5 | - "3.4" 6 | - "3.5" 7 | - "3.7" 8 | 9 | install: 10 | - "travis_retry pip install -r requirements.txt" 11 | - "travis_retry pip install -e .[all]" 12 | 13 | script: py.test --cov=tika 14 | 15 | after_success: coveralls 16 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /MANIFEST.IN: -------------------------------------------------------------------------------- 1 | include LICENSE.txt 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Build Status](https://travis-ci.org/chrismattmann/tika-python.svg?branch=master)](https://travis-ci.org/chrismattmann/tika-python) 2 | [![Coverage Status](https://coveralls.io/repos/github/chrismattmann/tika-python/badge.svg?branch=master)](https://coveralls.io/github/chrismattmann/tika-python?branch=master) 3 | 4 | tika-python 5 | =========== 6 | A Python port of the [Apache Tika](http://tika.apache.org/) 7 | library that makes Tika available using the 8 | [Tika REST Server](https://cwiki.apache.org/confluence/display/TIKA/TikaServer). 9 | 10 | This makes Apache Tika available as a Python library, 11 | installable via Setuptools, Pip and Easy Install. 12 | 13 | To use this library, you need to have Java 11+ installed on your 14 | system as tika-python starts up the Tika REST server in the 15 | background. 16 | 17 | Inspired by [Aptivate Tika](https://github.com/aptivate/python-tika). 18 | 19 | Installation (with pip) 20 | ----------------------- 21 | 1. `pip install tika` 22 | 23 | Installation (without pip) 24 | -------------------------- 25 | 1. `python setup.py build` 26 | 2. `python setup.py install` 27 | 28 | Airgap Environment Setup 29 | ------------------------ 30 | To get this working in a disconnected environment, download a tika server file (both tika-server.jar and tika-server.jar.md5, which can be found [here](https://repo1.maven.org/maven2/org/apache/tika/tika-server-standard/)) and set the TIKA_SERVER_JAR environment variable to TIKA_SERVER_JAR="file:////tika-server-standard.jar" which successfully tells `python-tika` to "download" this file and move it to `/tmp/tika-server-standard.jar` and run as background process. 31 | 32 | This is the only way to run `python-tika` without internet access. Without this set, the default is to check the tika version and pull latest every time from Apache. 33 | 34 | Environment Variables 35 | --------------------- 36 | These are read once, when tika/tika.py is initially loaded and used throughout after that. 37 | 38 | 1. `TIKA_VERSION` - set to the version string, e.g., 1.12 or default to current Tika version. 39 | 2. `TIKA_SERVER_JAR` - set to the full URL to the remote Tika server jar to download and cache. 40 | 3. `TIKA_SERVER_ENDPOINT` - set to the host (local or remote) for the running Tika server jar. 41 | 4. `TIKA_CLIENT_ONLY` - if set to True, then `TIKA_SERVER_JAR` is ignored, and relies on the value for `TIKA_SERVER_ENDPOINT` and treats Tika like a REST client. 42 | 3. `TIKA_JAR_HASH_ALGO` - set to `sha1` when running on FIPS-compliant systems; default value is `md5`. 43 | 4. `TIKA_SERVER_ENDPOINT` - set to the host (local or remote) for the running Tika server jar. 44 | 5. `TIKA_CLIENT_ONLY` - if set to True, then `TIKA_SERVER_JAR` is ignored, and relies on the value for `TIKA_SERVER_ENDPOINT` and treats Tika like a REST client. 45 | 6. `TIKA_TRANSLATOR` - set to the fully qualified class name (defaults to Lingo24) for the Tika translator implementation. 46 | 7. `TIKA_SERVER_CLASSPATH` - set to a string (delimited by ':' for each additional path) to prepend to the Tika server jar path. 47 | 8. `TIKA_LOG_PATH` - set to a directory with write permissions and the `tika.log` and `tika-server.log` files will be placed in this directory. 48 | 9. `TIKA_PATH` - set to a directory with write permissions and the `tika_server.jar` file will be placed in this directory. 49 | 10. `TIKA_JAVA` - set the Java runtime name, e.g., `java` or `java9` 50 | 11. `TIKA_STARTUP_SLEEP` - number of seconds (`float`) to wait per check if Tika server is launched at runtime 51 | 12. `TIKA_STARTUP_MAX_RETRY` - number of checks (`int`) to attempt for Tika server startup if launched at runtime 52 | 13. `TIKA_JAVA_ARGS` - set java runtime arguments, e.g, `-Xmx4g` 53 | 14. `TIKA_LOG_FILE` - set the filename for the log file. default: `tika.log`. if it is an empty string (`''`), no log file is created. 54 | 55 | Testing it out 56 | ============== 57 | 58 | Parser Interface (backwards compat prior to REST) 59 | ------------------------------------------------- 60 | ```python 61 | #!/usr/bin/env python 62 | import tika 63 | tika.initVM() 64 | from tika import parser 65 | parsed = parser.from_file('/path/to/file') 66 | print(parsed["metadata"]) 67 | print(parsed["content"]) 68 | ``` 69 | 70 | Parser Interface 71 | ---------------------- 72 | The parser interface extracts text and metadata using the /rmeta 73 | interface. This is one of the better ways to get the internal XHTML 74 | content extracted. 75 | 76 | Note: 77 | ![Alert Icon](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon28.png "Alert") 78 | The parser interface needs the following environment variable set on the console for printing of the extracted content. 79 | ```export PYTHONIOENCODING=utf8``` 80 | 81 | ```python 82 | #!/usr/bin/env python 83 | import tika 84 | from tika import parser 85 | parsed = parser.from_file('/path/to/file') 86 | print(parsed["metadata"]) 87 | print(parsed["content"]) 88 | ``` 89 | 90 | Optionally, you can pass Tika server URL along with the call 91 | what's useful for multi-instance execution or when Tika is dockerzed/linked. 92 | 93 | ```python 94 | parsed = parser.from_file('/path/to/file', 'http://tika:9998/tika') 95 | string_parsed = parser.from_buffer('Good evening, Dave', 'http://tika:9998/tika') 96 | ``` 97 | 98 | You can also pass a binary stream 99 | ``` 100 | with open(file, 'rb') as file_obj: 101 | response = tika.parser.from_file(file_obj) 102 | ``` 103 | 104 | Gzip compression 105 | --------------------- 106 | Since Tika 1.24.1 gzip compression of input and output streams is allowed. 107 | 108 | Input compression can be achieved with gzip or zlib: 109 | ``` 110 | import zlib 111 | 112 | with open(file, 'rb') as file_obj: 113 | return tika.parser.from_buffer(zlib.compress(file_obj.read())) 114 | 115 | ... 116 | 117 | import gzip 118 | 119 | with open(file, 'rb') as file_obj: 120 | return tika.parser.from_buffer(gzip.compress(file_obj.read())) 121 | ``` 122 | 123 | And output with the header: 124 | ``` 125 | with open(file, 'rb') as file_obj: 126 | return tika.parser.from_file(file_obj, headers={'Accept-Encoding': 'gzip, deflate'}) 127 | ``` 128 | 129 | Specify Output Format To XHTML 130 | --------------------- 131 | The parser interface is optionally able to output the content as XHTML rather than plain text. 132 | 133 | Note: 134 | ![Alert Icon](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon28.png "Alert") 135 | The parser interface needs the following environment variable set on the console for printing of the extracted content. 136 | ```export PYTHONIOENCODING=utf8``` 137 | 138 | ```python 139 | #!/usr/bin/env python 140 | import tika 141 | from tika import parser 142 | parsed = parser.from_file('/path/to/file', xmlContent=True) 143 | print(parsed["metadata"]) 144 | print(parsed["content"]) 145 | 146 | # Note: This is also available when parsing from the buffer. 147 | ``` 148 | 149 | Unpack Interface 150 | ---------------- 151 | The unpack interface handles both metadata and text extraction in a single 152 | call and internally returns back a tarball of metadata and text entries that 153 | is internally unpacked, reducing the wire load for extraction. 154 | 155 | ```python 156 | #!/usr/bin/env python 157 | import tika 158 | from tika import unpack 159 | parsed = unpack.from_file('/path/to/file') 160 | ``` 161 | 162 | Detect Interface 163 | ---------------------- 164 | The detect interface provides a IANA MIME type classification for the 165 | provided file. 166 | 167 | ```python 168 | #!/usr/bin/env python 169 | import tika 170 | from tika import detector 171 | print(detector.from_file('/path/to/file')) 172 | ``` 173 | 174 | Config Interface 175 | ---------------------- 176 | The config interface allows you to inspect the Tika Server environment's 177 | configuration including what parsers, mime types, and detectors the 178 | server has been configured with. 179 | 180 | ```python 181 | #!/usr/bin/env python 182 | import tika 183 | from tika import config 184 | print(config.getParsers()) 185 | print(config.getMimeTypes()) 186 | print(config.getDetectors()) 187 | ``` 188 | 189 | Language Detection Interface 190 | --------------------------------- 191 | The language detection interface provides a 2 character language 192 | code texted based on the text in provided file. 193 | 194 | ```python 195 | #!/usr/bin/env python 196 | from tika import language 197 | print(language.from_file('/path/to/file')) 198 | ``` 199 | 200 | Translate Interface 201 | ------------------------ 202 | The translate interface translates the text automatically extracted 203 | by Tika from the source language to the destination language. 204 | 205 | ```python 206 | #!/usr/bin/env python 207 | from tika import translate 208 | print(translate.from_file('/path/to/spanish', 'es', 'en')) 209 | ``` 210 | 211 | Using a Buffer 212 | -------------- 213 | Note you can also use a Parser and Detector 214 | .from_buffer(string|BufferedIOBase) method to dynamically parser 215 | a string or bytes buffer in Python and/or detect its MIME 216 | type. This is useful if you've already loaded 217 | the content into memory. 218 | ```python 219 | string_parsed = parser.from_buffer('Good evening, Dave') 220 | byte_data: bytes = b'B\xc3\xa4ume' 221 | parsed = parser.from_buffer(io.BytesIO(byte_data)) 222 | ``` 223 | 224 | Using Client Only Mode 225 | ---------------------- 226 | You can set Tika to use Client only mode by setting 227 | ```python 228 | import tika from tika 229 | tika.TikaClientOnly = True 230 | ``` 231 | 232 | Then you can run any of the methods and it will fully 233 | omit the check to see if the service on localhost is 234 | running and omit printing the check messages. 235 | 236 | Changing the Tika Classpath 237 | --------------------------- 238 | You can update the classpath that Tika server uses by 239 | setting the classpath as a set of ':' delimited strings. 240 | For example if you want to get Tika-Python working with 241 | [GeoTopicParsing](https://cwiki.apache.org/confluence/display/TIKA/GeoTopicParser), 242 | you can do this, replace paths below with your own paths, as 243 | identified [here](https://cwiki.apache.org/confluence/display/TIKA/GeoTopicParser) 244 | and make sure that you have done this: 245 | 246 | kill Tika server (if already running): 247 | 248 | ```bash 249 | ps aux | grep java | grep Tika 250 | kill -9 PID 251 | ``` 252 | 253 | ```python 254 | import tika.tika 255 | import os 256 | from tika import parser 257 | home = os.getenv('HOME') 258 | tika.tika.TikaServerClasspath = home + '/git/geotopicparser-utils/mime:'+home+'/git/geotopicparser-utils/models/polar' 259 | parsed = parser.from_file(home + '/git/geotopicparser-utils/geotopics/polar.geot') 260 | print parsed["metadata"] 261 | ``` 262 | 263 | Customizing the Tika Server Request 264 | --------------------------- 265 | You may customize the outgoing HTTP request to Tika server by setting `requestOptions` on the `.from_file` and `.from_buffer` methods (Parser, Unpack , Detect, Config, Language, Translate). It should be a dictionary of arguments that will be passed to the request method. The [request method documentation](https://requests.kennethreitz.org/en/master/api/#requests.request) specifies valid arguments. This will override any defaults except for `url` and `params `/`data`. 266 | 267 | ```python 268 | from tika import parser 269 | parsed = parser.from_file('/path/to/file', requestOptions={'timeout': 120}) 270 | ``` 271 | 272 | New Command Line Client Tool 273 | ============================ 274 | When you install Tika-Python you also get a new command 275 | line client tool, `tika-python` installed in your /path/to/python/bin 276 | directory. 277 | 278 | The options and help for the command line tool can be seen by typing 279 | `tika-python` without any arguments. This will also download a copy of 280 | the tika-server jar and start it if you haven't done so already. 281 | 282 | ```bash 283 | tika.py [-v] [-o ] [--server ] [--install ] [--port ]