|
| 1 | +# [Conversion Tools](https://conversiontools.io) API Python Client |
| 2 | + |
| 3 | +[Conversion Tools](https://conversiontools.io) is an online service that offers a fast and easy way to convert documents between different formats, like XML, Excel, PDF, Word, Text, CSV and others. |
| 4 | + |
| 5 | +This Client allows to integrate the conversion of the files into Python applications. |
| 6 | + |
| 7 | +To convert the files Python Client uses the public [Conversion Tools REST API](https://conversiontools.io/api-documentation). |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +```bash |
| 12 | +pip install --upgrade conversiontools |
| 13 | +``` |
| 14 | + |
| 15 | +or when building from the sources: |
| 16 | + |
| 17 | +```bash |
| 18 | +python setup.py install |
| 19 | +``` |
| 20 | + |
| 21 | +## Examples |
| 22 | + |
| 23 | +To use REST API - get API Token from the Profile page at https://conversiontools.io/profile. |
| 24 | + |
| 25 | +See example `test.py` in the `./examples/` folder. |
| 26 | + |
| 27 | +```python |
| 28 | +from conversiontools import ConversionClient |
| 29 | + |
| 30 | +# put token here from your Profile page at https://conversiontools.io/profile |
| 31 | +token = '' |
| 32 | + |
| 33 | +# files |
| 34 | +fileInput = 'test.xml' |
| 35 | +fileOutput = 'test.csv' |
| 36 | + |
| 37 | +client = ConversionClient(token) |
| 38 | +try: |
| 39 | + client.convert('convert.xml_to_csv', fileInput, fileOutput, { 'delimiter': 'tabulation' }) |
| 40 | +except Exception as error: |
| 41 | + print(error) |
| 42 | +``` |
| 43 | + |
| 44 | +## API |
| 45 | + |
| 46 | +### Create `ConversionClient` instance with a token. |
| 47 | +```python |
| 48 | +from conversiontools import ConversionClient |
| 49 | +client = ConversionClient('<token>') |
| 50 | +``` |
| 51 | + |
| 52 | +Where `<token>` is API token from the account's Profile page https://conversiontools.io/profile. |
| 53 | + |
| 54 | +### Convert input file and download the result |
| 55 | +```python |
| 56 | +try: |
| 57 | + client.convert('<conversion type>', fileInput, fileOutput, '<options>') |
| 58 | +except Exception as error: |
| 59 | + print(error) |
| 60 | +``` |
| 61 | + |
| 62 | +Where |
| 63 | +- `<conversion type>` is a specific type of conversion, from [API Documentation](https://conversiontools.io/api-documentation). |
| 64 | +- `<options>` is a Python dict with options for a corresponding converter, for example: |
| 65 | +```python |
| 66 | +options = { 'delimiter': 'tabulation' } |
| 67 | +``` |
| 68 | + |
| 69 | +## Documentation |
| 70 | + |
| 71 | +List of available Conversion Types and corresponding conversion options can be found on the [Conversion Tools API Documentation](https://conversiontools.io/api-documentation) page. |
| 72 | + |
| 73 | +## License |
| 74 | + |
| 75 | +Licensed under [MIT](./LICENSE). |
| 76 | + |
| 77 | +Copyright (c) 2020 [Conversion Tools](https://conversiontools.io) |
0 commit comments