|
| 1 | +# ConvertAPI Python Client |
1 | 2 |
|
| 3 | +[](https://badge.fury.io/py/convertapi) |
| 4 | +[](http://travis-ci.org/ConvertAPI/convertapi-python) |
| 5 | + |
| 6 | +## Convert your files with our online file conversion API |
| 7 | + |
| 8 | +The ConvertAPI helps converting various file formats. Creating PDF and Images from various sources like Word, Excel, Powerpoint, images, web pages or raw HTML codes. Merge, Encrypt, Split, Repair and Decrypt PDF files. And many others files manipulations. In just few minutes you can integrate it into your application and use it easily. |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +Install with [pip](https://pypi.org/project/pip/): |
| 13 | + |
| 14 | + pip install --upgrade convertapi |
| 15 | + |
| 16 | +Install from source with: |
| 17 | + |
| 18 | + python setup.py install |
| 19 | + |
| 20 | +### Requirements |
| 21 | + |
| 22 | +* Python 2.7+ or Python 3.3+ |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +### Configuration |
| 27 | + |
| 28 | +You can get your secret at https://www.convertapi.com/a |
| 29 | + |
| 30 | +```python |
| 31 | +import convertapi |
| 32 | + |
| 33 | +convertapi.api_secret = 'your api secret' |
| 34 | +``` |
| 35 | + |
| 36 | +### File conversion |
| 37 | + |
| 38 | +Example to convert file to PDF. All supported formats and options can be found |
| 39 | +[here](https://www.convertapi.com). |
| 40 | + |
| 41 | +```python |
| 42 | +result = convertapi.convert('pdf', { 'File': '/path/to/my_file.docx' }) |
| 43 | + |
| 44 | +# save to file |
| 45 | +result.file.save('/path/to/save/file.pdf') |
| 46 | +``` |
| 47 | + |
| 48 | +Other result operations: |
| 49 | + |
| 50 | +```python |
| 51 | +# save all result files to folder |
| 52 | +result.save_files('/path/to/save/files') |
| 53 | + |
| 54 | +# get conversion cost |
| 55 | +conversion_cost = result.conversion_cost |
| 56 | +``` |
| 57 | + |
| 58 | +#### Convert file url |
| 59 | + |
| 60 | +```python |
| 61 | +result = convertapi.convert('pdf', { 'File': 'https://website/my_file.docx' }) |
| 62 | +``` |
| 63 | + |
| 64 | +#### Specifying from format |
| 65 | + |
| 66 | +```python |
| 67 | +result = convertapi.convert( |
| 68 | + 'pdf', |
| 69 | + { 'File': '/path/to/my_file' }, |
| 70 | + from_format = 'docx' |
| 71 | +) |
| 72 | +``` |
| 73 | + |
| 74 | +#### Additional conversion parameters |
| 75 | + |
| 76 | +ConvertAPI accepts extra conversion parameters depending on converted formats. All conversion |
| 77 | +parameters and explanations can be found [here](https://www.convertapi.com). |
| 78 | + |
| 79 | +```python |
| 80 | +result = convertapi.convert( |
| 81 | + 'pdf', |
| 82 | + { |
| 83 | + 'File': '/path/to/my_file.docx', |
| 84 | + 'PageRange': '1-10', |
| 85 | + 'PdfResolution': '150', |
| 86 | + } |
| 87 | +) |
| 88 | +``` |
| 89 | + |
| 90 | +### User information |
| 91 | + |
| 92 | +You can always check remaining seconds amount by fetching [user information](https://www.convertapi.com/doc/user). |
| 93 | + |
| 94 | +```python |
| 95 | +user_info = convertapi.user() |
| 96 | + |
| 97 | +print(user_info['SecondsLeft']) |
| 98 | +``` |
| 99 | + |
| 100 | +### More examples |
| 101 | + |
| 102 | +You can find more advanced examples in the [examples/](examples) folder. |
| 103 | + |
| 104 | +## Development |
| 105 | + |
| 106 | +Execute `CONVERT_API_SECRET=your_secret nosetests --nocapture` to run the tests. |
| 107 | + |
| 108 | +## Contributing |
| 109 | + |
| 110 | +Bug reports and pull requests are welcome on GitHub at https://github.com/ConvertAPI/convertapi-python. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. |
| 111 | + |
| 112 | +## License |
| 113 | + |
| 114 | +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
0 commit comments