|
| 1 | +[](https://badge.fury.io/py/convertapi) |
| 2 | +[](https://github.com/ConvertAPI/convertapi-python/actions) |
| 3 | +[](https://opensource.org/licenses/MIT) |
| 4 | + |
| 5 | +## Convert your files with our online file conversion API |
| 6 | + |
| 7 | +ConvertAPI helps to convert various file formats. Creating PDFs 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 other manipulations. You can integrate it into your application in just a few minutes and use it easily. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +Install with [pip](https://pypi.org/project/pip/): |
| 12 | + |
| 13 | + pip install --upgrade convertapi |
| 14 | + |
| 15 | +Install from source with: |
| 16 | + |
| 17 | + python setup.py install |
| 18 | + |
| 19 | +### Requirements |
| 20 | + |
| 21 | +* Python 3.3+ |
| 22 | + |
| 23 | +## Usage |
| 24 | + |
| 25 | +### Configuration |
| 26 | + |
| 27 | +You can get your secret at https://www.convertapi.com/a |
| 28 | + |
| 29 | +```python |
| 30 | +import convertapi |
| 31 | + |
| 32 | +convertapi.api_secret = 'your-api-secret' |
| 33 | +``` |
| 34 | + |
| 35 | +#### Proxy configuration |
| 36 | + |
| 37 | +If you need to use a proxy, you can specify it using `HTTPS_PROXY` environment variable when running your script. |
| 38 | + |
| 39 | +Example: |
| 40 | + |
| 41 | +``` |
| 42 | +CONVERT_API_SECRET=secret HTTPS_PROXY=https://user:[email protected]:9000/ python convert_word_to_pdf_and_png.py |
| 43 | +``` |
| 44 | + |
| 45 | +### File conversion |
| 46 | + |
| 47 | +Convert a file to PDF example. All supported file formats and options can be found |
| 48 | +[here](https://www.convertapi.com/conversions). |
| 49 | + |
| 50 | +```python |
| 51 | +result = convertapi.convert('pdf', { 'File': '/path/to/my_file.docx' }) |
| 52 | + |
| 53 | +# save to file |
| 54 | +result.file.save('/path/to/save/file.pdf') |
| 55 | +``` |
| 56 | + |
| 57 | +Other result operations: |
| 58 | + |
| 59 | +```python |
| 60 | +# save all result files to folder |
| 61 | +result.save_files('/path/to/save/files') |
| 62 | + |
| 63 | +# get conversion cost |
| 64 | +conversion_cost = result.conversion_cost |
| 65 | +``` |
| 66 | + |
| 67 | +#### Convert file url |
| 68 | + |
| 69 | +```python |
| 70 | +result = convertapi.convert('pdf', { 'File': 'https://website/my_file.docx' }) |
| 71 | +``` |
| 72 | + |
| 73 | +#### Specifying from format |
| 74 | + |
| 75 | +```python |
| 76 | +result = convertapi.convert( |
| 77 | + 'pdf', |
| 78 | + { 'File': '/path/to/my_file' }, |
| 79 | + from_format = 'docx' |
| 80 | +) |
| 81 | +``` |
| 82 | + |
| 83 | +#### Additional conversion parameters |
| 84 | + |
| 85 | +ConvertAPI accepts additional conversion parameters depending on selected formats. All conversion |
| 86 | +parameters and explanations can be found [here](https://www.convertapi.com/conversions). |
| 87 | + |
| 88 | +```python |
| 89 | +result = convertapi.convert( |
| 90 | + 'pdf', |
| 91 | + { |
| 92 | + 'File': '/path/to/my_file.docx', |
| 93 | + 'PageRange': '1-10', |
| 94 | + 'PdfResolution': '150', |
| 95 | + } |
| 96 | +) |
| 97 | +``` |
| 98 | + |
| 99 | +### User information |
| 100 | + |
| 101 | +You can always check your remaining seconds amount programatically by fetching [user information](https://www.convertapi.com/doc/user). |
| 102 | + |
| 103 | +```python |
| 104 | +user_info = convertapi.user() |
| 105 | + |
| 106 | +print(user_info['SecondsLeft']) |
| 107 | +``` |
| 108 | + |
| 109 | +### Alternative domain |
| 110 | + |
| 111 | +Set `base_uri` parameter to use other service domains. Dedicated to the region [domain list](https://www.convertapi.com/doc/servers-location). |
| 112 | + |
| 113 | +```python |
| 114 | +convertapi.base_uri = 'https://eu-v2.convertapi.com/' |
| 115 | +``` |
| 116 | + |
| 117 | +### More examples |
| 118 | + |
| 119 | +Find more advanced examples in the [/examples](https://github.com/ConvertAPI/convertapi-python/tree/master/examples) folder. |
| 120 | + |
| 121 | +## Development |
| 122 | + |
| 123 | +Execute `CONVERT_API_SECRET=your_secret nosetests --nocapture` to run the tests. |
| 124 | + |
| 125 | +## Contributing |
| 126 | + |
| 127 | +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. |
| 128 | + |
| 129 | +## License |
| 130 | + |
| 131 | +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). |
0 commit comments