From c0c5eb7e0e678a601a1cb4e1773a509504192945 Mon Sep 17 00:00:00 2001 From: Kostas <62603039+kostas-baltsoft@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:53:42 +0300 Subject: [PATCH 01/12] Create GETTING-STARTED.md Getting Started page for ConvertAPI web rendering --- GETTING-STARTED.md | 131 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 GETTING-STARTED.md diff --git a/GETTING-STARTED.md b/GETTING-STARTED.md new file mode 100644 index 0000000..d8651a3 --- /dev/null +++ b/GETTING-STARTED.md @@ -0,0 +1,131 @@ +[![PyPI version](https://badge.fury.io/py/convertapi.svg)](https://badge.fury.io/py/convertapi) +[![Build Status](https://github.com/ConvertAPI/convertapi-python/actions/workflows/main.yml/badge.svg)](https://github.com/ConvertAPI/convertapi-python/actions) +[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) + +## Convert your files with our online file conversion API + +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. + +## Installation + +Install with [pip](https://pypi.org/project/pip/): + + pip install --upgrade convertapi + +Install from source with: + + python setup.py install + +### Requirements + +* Python 3.3+ + +## Usage + +### Configuration + +You can get your secret at https://www.convertapi.com/a + +```python +import convertapi + +convertapi.api_secret = 'your-api-secret' +``` + +#### Proxy configuration + +If you need to use a proxy, you can specify it using `HTTPS_PROXY` environment variable when running your script. + +Example: + +``` +CONVERT_API_SECRET=secret HTTPS_PROXY=https://user:pass@127.0.0.1:9000/ python convert_word_to_pdf_and_png.py +``` + +### File conversion + +Convert a file to PDF example. All supported file formats and options can be found +[here](https://www.convertapi.com/conversions). + +```python +result = convertapi.convert('pdf', { 'File': '/path/to/my_file.docx' }) + +# save to file +result.file.save('/path/to/save/file.pdf') +``` + +Other result operations: + +```python +# save all result files to folder +result.save_files('/path/to/save/files') + +# get conversion cost +conversion_cost = result.conversion_cost +``` + +#### Convert file url + +```python +result = convertapi.convert('pdf', { 'File': 'https://website/my_file.docx' }) +``` + +#### Specifying from format + +```python +result = convertapi.convert( + 'pdf', + { 'File': '/path/to/my_file' }, + from_format = 'docx' +) +``` + +#### Additional conversion parameters + +ConvertAPI accepts additional conversion parameters depending on selected formats. All conversion +parameters and explanations can be found [here](https://www.convertapi.com/conversions). + +```python +result = convertapi.convert( + 'pdf', + { + 'File': '/path/to/my_file.docx', + 'PageRange': '1-10', + 'PdfResolution': '150', + } +) +``` + +### User information + +You can always check your remaining seconds amount programatically by fetching [user information](https://www.convertapi.com/doc/user). + +```python +user_info = convertapi.user() + +print(user_info['SecondsLeft']) +``` + +### Alternative domain + +Set `base_uri` parameter to use other service domains. Dedicated to the region [domain list](https://www.convertapi.com/doc/servers-location). + +```python +convertapi.base_uri = 'https://eu-v2.convertapi.com/' +``` + +### More examples + +Find more advanced examples in the [/examples](https://github.com/ConvertAPI/convertapi-python/tree/master/examples) folder. + +## Development + +Execute `CONVERT_API_SECRET=your_secret nosetests --nocapture` to run the tests. + +## Contributing + +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. + +## License + +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). From f751be715bf2413363ff2f68ca99fdaa55d09d49 Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Tue, 22 Aug 2023 14:47:31 +0300 Subject: [PATCH 02/12] Delete GETTING-STARTED.md --- GETTING-STARTED.md | 131 --------------------------------------------- 1 file changed, 131 deletions(-) delete mode 100644 GETTING-STARTED.md diff --git a/GETTING-STARTED.md b/GETTING-STARTED.md deleted file mode 100644 index d8651a3..0000000 --- a/GETTING-STARTED.md +++ /dev/null @@ -1,131 +0,0 @@ -[![PyPI version](https://badge.fury.io/py/convertapi.svg)](https://badge.fury.io/py/convertapi) -[![Build Status](https://github.com/ConvertAPI/convertapi-python/actions/workflows/main.yml/badge.svg)](https://github.com/ConvertAPI/convertapi-python/actions) -[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) - -## Convert your files with our online file conversion API - -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. - -## Installation - -Install with [pip](https://pypi.org/project/pip/): - - pip install --upgrade convertapi - -Install from source with: - - python setup.py install - -### Requirements - -* Python 3.3+ - -## Usage - -### Configuration - -You can get your secret at https://www.convertapi.com/a - -```python -import convertapi - -convertapi.api_secret = 'your-api-secret' -``` - -#### Proxy configuration - -If you need to use a proxy, you can specify it using `HTTPS_PROXY` environment variable when running your script. - -Example: - -``` -CONVERT_API_SECRET=secret HTTPS_PROXY=https://user:pass@127.0.0.1:9000/ python convert_word_to_pdf_and_png.py -``` - -### File conversion - -Convert a file to PDF example. All supported file formats and options can be found -[here](https://www.convertapi.com/conversions). - -```python -result = convertapi.convert('pdf', { 'File': '/path/to/my_file.docx' }) - -# save to file -result.file.save('/path/to/save/file.pdf') -``` - -Other result operations: - -```python -# save all result files to folder -result.save_files('/path/to/save/files') - -# get conversion cost -conversion_cost = result.conversion_cost -``` - -#### Convert file url - -```python -result = convertapi.convert('pdf', { 'File': 'https://website/my_file.docx' }) -``` - -#### Specifying from format - -```python -result = convertapi.convert( - 'pdf', - { 'File': '/path/to/my_file' }, - from_format = 'docx' -) -``` - -#### Additional conversion parameters - -ConvertAPI accepts additional conversion parameters depending on selected formats. All conversion -parameters and explanations can be found [here](https://www.convertapi.com/conversions). - -```python -result = convertapi.convert( - 'pdf', - { - 'File': '/path/to/my_file.docx', - 'PageRange': '1-10', - 'PdfResolution': '150', - } -) -``` - -### User information - -You can always check your remaining seconds amount programatically by fetching [user information](https://www.convertapi.com/doc/user). - -```python -user_info = convertapi.user() - -print(user_info['SecondsLeft']) -``` - -### Alternative domain - -Set `base_uri` parameter to use other service domains. Dedicated to the region [domain list](https://www.convertapi.com/doc/servers-location). - -```python -convertapi.base_uri = 'https://eu-v2.convertapi.com/' -``` - -### More examples - -Find more advanced examples in the [/examples](https://github.com/ConvertAPI/convertapi-python/tree/master/examples) folder. - -## Development - -Execute `CONVERT_API_SECRET=your_secret nosetests --nocapture` to run the tests. - -## Contributing - -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. - -## License - -The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). From 7abf8a97057390736bbe8076e3cd894fa3621530 Mon Sep 17 00:00:00 2001 From: laurynas-convertapi <38224044+laurynas-convertapi@users.noreply.github.com> Date: Tue, 2 Apr 2024 18:52:58 +0300 Subject: [PATCH 03/12] Add token auth support (#44) * Add token auth support * Remove nose-setenv * Update readme --------- Co-authored-by: Laurynas Butkus --- README.md | 11 +++++++++++ convertapi/__init__.py | 2 ++ convertapi/client.py | 6 ++++++ test-requirements.txt | 2 +- tests/test_convertapi.py | 18 ++++++++++++++++++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 13de2b6..a1aaad7 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,17 @@ import convertapi convertapi.api_secret = 'your-api-secret' ``` +If you prefer to use [token and API key](https://www.convertapi.com/doc/auth#token), you can configure like this: + +```python +import convertapi + +convertapi.api_token = 'your-api-token' +convertapi.api_key = 000000 # your api key +``` + +If both API secret and token are configured, token will be used. + #### Proxy configuration If you need to use a proxy, you can specify it using `HTTPS_PROXY` environment variable when running your script. diff --git a/convertapi/__init__.py b/convertapi/__init__.py index 094eb44..4c8f2b2 100644 --- a/convertapi/__init__.py +++ b/convertapi/__init__.py @@ -8,6 +8,8 @@ # configuration api_secret = None +api_key = None +api_token = None base_uri = 'https://v2.convertapi.com/' user_agent = 'ConvertAPI-Python/' + __version__ timeout = 1800 diff --git a/convertapi/client.py b/convertapi/client.py index 77ce152..b0d0d9a 100644 --- a/convertapi/client.py +++ b/convertapi/client.py @@ -54,6 +54,12 @@ def __handle_response(self, r): return r.json() def __url(self, path): + if convertapi.api_token != None and convertapi.api_key != None: + return "%s%s?Token=%s&ApiKey=%d" % (convertapi.base_uri, path, convertapi.api_token, convertapi.api_key) + + if convertapi.api_token != None: + return "%s%s?Token=%s" % (convertapi.base_uri, path, convertapi.api_token) + return "%s%s?Secret=%s" % (convertapi.base_uri, path, convertapi.api_secret) def __session(self): diff --git a/test-requirements.txt b/test-requirements.txt index 8a35f17..5ac06ed 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,3 @@ nose -nose-setenv mock +responses diff --git a/tests/test_convertapi.py b/tests/test_convertapi.py index e66fc49..21c1a63 100644 --- a/tests/test_convertapi.py +++ b/tests/test_convertapi.py @@ -3,6 +3,7 @@ import io import tempfile import requests +import responses from . import utils from nose.tools import * @@ -10,6 +11,8 @@ class TestConvertapi(utils.TestCase): def setUp(self): convertapi.api_secret = os.environ['CONVERT_API_SECRET'] + convertapi.api_key = None + convertapi.api_token = None convertapi.max_parallel_uploads = 10 def test_defaults(self): @@ -79,3 +82,18 @@ def test_api_error(self): def test_user_info(self): user_info = convertapi.user() assert user_info['Active'] + + @responses.activate + def test_with_token(self): + convertapi.api_token = 'TEST' + responses.add(responses.POST, 'https://v2.convertapi.com/convert/web/to/pdf?Token=TEST', json = { 'ConversionCost': 123 }) + result = convertapi.convert('pdf', { 'Url': 'dummyurl' }) + assert result.conversion_cost == 123 + + @responses.activate + def test_with_token_and_api_key(self): + convertapi.api_token = 'TEST' + convertapi.api_key = 1 + responses.add(responses.POST, 'https://v2.convertapi.com/convert/web/to/pdf?Token=TEST&ApiKey=1', json = { 'ConversionCost': 123 }) + result = convertapi.convert('pdf', { 'Url': 'dummyurl' }) + assert result.conversion_cost == 123 From baa07f6ab7fe3d5f165a8119f94eef322739d2fe Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Tue, 2 Apr 2024 19:07:48 +0300 Subject: [PATCH 04/12] Enable github publishing --- .github/workflows/publish.yml | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..791962a --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,51 @@ +name: Publish Python 🐍 distribution 📦 to PyPI + +on: + release: + types: [published] + +jobs: + build: + name: Build distribution 📦 + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.x" + - name: Install pypa/build + run: >- + python3 -m + pip install + build + --user + - name: Build a binary wheel and a source tarball + run: python3 -m build + - name: Store the distribution packages + uses: actions/upload-artifact@v3 + with: + name: python-package-distributions + path: dist/ + + publish-to-pypi: + name: >- + Publish Python 🐍 distribution 📦 to PyPI + needs: + - build + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/convertapi + permissions: + id-token: write # IMPORTANT: mandatory for trusted publishing + + steps: + - name: Download all the dists + uses: actions/download-artifact@v3 + with: + name: python-package-distributions + path: dist/ + - name: Publish distribution 📦 to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 From ac78774cff6c082f6d8417281f7f0154f9c631d6 Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Tue, 2 Apr 2024 19:09:50 +0300 Subject: [PATCH 05/12] Bump version --- convertapi/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convertapi/__init__.py b/convertapi/__init__.py index 4c8f2b2..aeef32b 100644 --- a/convertapi/__init__.py +++ b/convertapi/__init__.py @@ -1,4 +1,4 @@ -__version__ = '1.7.0' +__version__ = '1.8.0' from .exceptions import * from .client import Client From fbef47a56caa109ab90765c70f614d9e1ce6e625 Mon Sep 17 00:00:00 2001 From: laurynas-convertapi <38224044+laurynas-convertapi@users.noreply.github.com> Date: Sat, 14 Sep 2024 08:56:35 +0300 Subject: [PATCH 06/12] Remove alternative converter support (#49) Co-authored-by: Laurynas Butkus --- convertapi/task.py | 11 ----------- examples/alternative_converter.py | 15 --------------- tests/test_convertapi.py | 5 ----- 3 files changed, 31 deletions(-) delete mode 100644 examples/alternative_converter.py diff --git a/convertapi/task.py b/convertapi/task.py index af15fc6..261a5bc 100644 --- a/convertapi/task.py +++ b/convertapi/task.py @@ -21,12 +21,8 @@ def run(self): params = self.__normalize_params() from_format = self.from_format or self.__detect_format() timeout = self.timeout + convertapi.conversion_timeout_delta if self.timeout else None - converter = self.__detect_converter() path = "convert/%s/to/%s" % (from_format, self.to_format) - if converter != None: - path += "/converter/%s" % (converter) - response = convertapi.client.post(path, params, timeout = timeout) return Result(response) @@ -62,10 +58,3 @@ def __detect_format(self): if 'Files' in self.params: return format_detector.detect(self.params['Files'][0]) - - def __detect_converter(self): - for k, v in self.params.items(): - if k.lower() == 'converter': - return v - - return None diff --git a/examples/alternative_converter.py b/examples/alternative_converter.py deleted file mode 100644 index 02a2fd1..0000000 --- a/examples/alternative_converter.py +++ /dev/null @@ -1,15 +0,0 @@ -import convertapi -import os -import tempfile - -convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret - -# Example of saving Word docx to PDF using OpenOffice converter -# https://www.convertapi.com/doc-to-pdf/openoffice - -upload_io = convertapi.UploadIO(open('files/test.docx', 'rb')) -params = { 'File': upload_io, 'converter': 'openoffice' } - -saved_files = convertapi.convert('pdf', params).save_files(tempfile.gettempdir()) - -print("The PDF saved to %s" % saved_files) diff --git a/tests/test_convertapi.py b/tests/test_convertapi.py index 21c1a63..28cc6a2 100644 --- a/tests/test_convertapi.py +++ b/tests/test_convertapi.py @@ -32,11 +32,6 @@ def test_convert_file_no_parallelizm(self): result = convertapi.convert('pdf', { 'File': 'examples/files/test.docx' }) assert result.save_files(tempfile.gettempdir()) - def test_convert_file_alternative(self): - result = convertapi.convert('pdf', { 'File': 'examples/files/test.docx', 'Converter': 'openoffice' }) - assert result.save_files(tempfile.gettempdir()) - assert result.conversion_cost > 0 - def test_convert_file_url(self): result = convertapi.convert('pdf', { 'File': 'https://cdn.convertapi.com/cara/testfiles/document.docx?test=1' }) assert result.conversion_cost > 0 From 0f56a877495b4fc18820c5a324011e0b9026e4da Mon Sep 17 00:00:00 2001 From: laurynas-convertapi <38224044+laurynas-convertapi@users.noreply.github.com> Date: Sat, 14 Sep 2024 11:02:13 +0300 Subject: [PATCH 07/12] Update user information example (#52) --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a1aaad7..1277ffc 100644 --- a/README.md +++ b/README.md @@ -111,12 +111,13 @@ result = convertapi.convert( ### User information -You can always check your remaining seconds amount programatically by fetching [user information](https://www.convertapi.com/doc/user). +You can always check your usage by fetching [user information](https://www.convertapi.com/doc/user). ```python user_info = convertapi.user() -print(user_info['SecondsLeft']) +print(user_info['ConversionsTotal']) +print(user_info['ConversionsConsumed']) ``` ### Alternative domain From fcb55387b5c7a97b772cc0531a51f46ec0106993 Mon Sep 17 00:00:00 2001 From: laurynas-convertapi <38224044+laurynas-convertapi@users.noreply.github.com> Date: Sat, 14 Sep 2024 11:21:32 +0300 Subject: [PATCH 08/12] Change default upload and download timeouts to None (#51) --- convertapi/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/convertapi/__init__.py b/convertapi/__init__.py index aeef32b..61886ba 100644 --- a/convertapi/__init__.py +++ b/convertapi/__init__.py @@ -15,8 +15,8 @@ timeout = 1800 conversion_timeout = None conversion_timeout_delta = 10 -upload_timeout = 1800 -download_timeout = 1800 +upload_timeout = None +download_timeout = None max_parallel_uploads = 10 verify_ssl = True From fb9cc7d106f02227de59296381274f5c0db4f0c6 Mon Sep 17 00:00:00 2001 From: laurynas-convertapi <38224044+laurynas-convertapi@users.noreply.github.com> Date: Sat, 14 Sep 2024 11:23:07 +0300 Subject: [PATCH 09/12] Switch to authorization header (#50) --- README.md | 15 ++------------- convertapi/__init__.py | 4 +--- convertapi/client.py | 9 ++------- examples/conversions_chaining.py | 2 +- examples/convert_stream.py | 2 +- examples/convert_url_to_pdf.py | 2 +- examples/convert_word_to_pdf_and_png.py | 2 +- examples/create_pdf_thumbnail.py | 2 +- examples/retrieve_user_information.py | 2 +- examples/split_and_merge_pdf.py | 2 +- tests/test_convertapi.py | 25 ++++--------------------- 11 files changed, 16 insertions(+), 51 deletions(-) diff --git a/README.md b/README.md index 1277ffc..c05b919 100644 --- a/README.md +++ b/README.md @@ -26,25 +26,14 @@ Install from source with: ### Configuration -You can get your secret at https://www.convertapi.com/a +You can get your API credentials at https://www.convertapi.com/a ```python import convertapi -convertapi.api_secret = 'your-api-secret' +convertapi.api_credentials = 'your-api-secret-or-token' ``` -If you prefer to use [token and API key](https://www.convertapi.com/doc/auth#token), you can configure like this: - -```python -import convertapi - -convertapi.api_token = 'your-api-token' -convertapi.api_key = 000000 # your api key -``` - -If both API secret and token are configured, token will be used. - #### Proxy configuration If you need to use a proxy, you can specify it using `HTTPS_PROXY` environment variable when running your script. diff --git a/convertapi/__init__.py b/convertapi/__init__.py index 61886ba..e0c4b24 100644 --- a/convertapi/__init__.py +++ b/convertapi/__init__.py @@ -7,9 +7,7 @@ # configuration -api_secret = None -api_key = None -api_token = None +api_credentials = None base_uri = 'https://v2.convertapi.com/' user_agent = 'ConvertAPI-Python/' + __version__ timeout = 1800 diff --git a/convertapi/client.py b/convertapi/client.py index b0d0d9a..206b10b 100644 --- a/convertapi/client.py +++ b/convertapi/client.py @@ -54,17 +54,12 @@ def __handle_response(self, r): return r.json() def __url(self, path): - if convertapi.api_token != None and convertapi.api_key != None: - return "%s%s?Token=%s&ApiKey=%d" % (convertapi.base_uri, path, convertapi.api_token, convertapi.api_key) - - if convertapi.api_token != None: - return "%s%s?Token=%s" % (convertapi.base_uri, path, convertapi.api_token) - - return "%s%s?Secret=%s" % (convertapi.base_uri, path, convertapi.api_secret) + return convertapi.base_uri + path def __session(self): s = requests.Session() s.headers.update({ 'User-Agent': convertapi.user_agent }) + s.headers.update({ 'Authorization': 'Bearer ' + convertapi.api_credentials }) s.verify = convertapi.verify_ssl return s diff --git a/examples/conversions_chaining.py b/examples/conversions_chaining.py index 6cf632b..fff7aa7 100644 --- a/examples/conversions_chaining.py +++ b/examples/conversions_chaining.py @@ -2,7 +2,7 @@ import os import tempfile -convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret +convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token # Short example of conversions chaining, the PDF pages extracted and saved as separated JPGs and then ZIP'ed # https://www.convertapi.com/doc/chaining diff --git a/examples/convert_stream.py b/examples/convert_stream.py index 1cc8c55..5ff2ba3 100644 --- a/examples/convert_stream.py +++ b/examples/convert_stream.py @@ -3,7 +3,7 @@ import io import tempfile -convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret +convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token # Example of using content stream to convert to pdf # https://www.convertapi.com/txt-to-pdf diff --git a/examples/convert_url_to_pdf.py b/examples/convert_url_to_pdf.py index b850b03..7f9c57b 100644 --- a/examples/convert_url_to_pdf.py +++ b/examples/convert_url_to_pdf.py @@ -2,7 +2,7 @@ import os import tempfile -convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret +convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token # Example of converting Web Page URL to PDF file # https://www.convertapi.com/web-to-pdf diff --git a/examples/convert_word_to_pdf_and_png.py b/examples/convert_word_to_pdf_and_png.py index 8645f26..a406119 100644 --- a/examples/convert_word_to_pdf_and_png.py +++ b/examples/convert_word_to_pdf_and_png.py @@ -2,7 +2,7 @@ import os import tempfile -convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret +convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token # Example of saving Word docx to PDF and to PNG # https://www.convertapi.com/docx-to-pdf diff --git a/examples/create_pdf_thumbnail.py b/examples/create_pdf_thumbnail.py index b864b6f..6e548c1 100644 --- a/examples/create_pdf_thumbnail.py +++ b/examples/create_pdf_thumbnail.py @@ -2,7 +2,7 @@ import os import tempfile -convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret +convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token # Example of extracting first page from PDF and then chaining conversion PDF page to JPG. # https://www.convertapi.com/pdf-to-extract diff --git a/examples/retrieve_user_information.py b/examples/retrieve_user_information.py index 6c65935..b488244 100644 --- a/examples/retrieve_user_information.py +++ b/examples/retrieve_user_information.py @@ -1,7 +1,7 @@ import convertapi import os -convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret +convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token # Retrieve user information # https://www.convertapi.com/doc/user diff --git a/examples/split_and_merge_pdf.py b/examples/split_and_merge_pdf.py index 679d3e8..e4c8d9a 100644 --- a/examples/split_and_merge_pdf.py +++ b/examples/split_and_merge_pdf.py @@ -2,7 +2,7 @@ import os import tempfile -convertapi.api_secret = os.environ['CONVERT_API_SECRET'] # your api secret +convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token # Example of extracting first and last pages from PDF and then merging them back to new PDF. # https://www.convertapi.com/pdf-to-split diff --git a/tests/test_convertapi.py b/tests/test_convertapi.py index 28cc6a2..bd47e9c 100644 --- a/tests/test_convertapi.py +++ b/tests/test_convertapi.py @@ -10,17 +10,15 @@ class TestConvertapi(utils.TestCase): def setUp(self): - convertapi.api_secret = os.environ['CONVERT_API_SECRET'] - convertapi.api_key = None - convertapi.api_token = None + convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] convertapi.max_parallel_uploads = 10 def test_defaults(self): eq_('https://v2.convertapi.com/', convertapi.base_uri) def test_configuration(self): - convertapi.api_secret = 'TEST' - eq_('TEST', convertapi.api_secret) + convertapi.api_credentials = 'TEST' + eq_('TEST', convertapi.api_credentials) def test_convert_file(self): result = convertapi.convert('pdf', { 'File': 'examples/files/test.docx' }) @@ -71,24 +69,9 @@ def test_compare_files(self): @raises(convertapi.ApiError) def test_api_error(self): - convertapi.api_secret = 'TEST' + convertapi.api_credentials = 'TEST' convertapi.convert('pdf', { 'Url': 'https://www.w3.org/TR/PNG/iso_8859-1.txt' }) def test_user_info(self): user_info = convertapi.user() assert user_info['Active'] - - @responses.activate - def test_with_token(self): - convertapi.api_token = 'TEST' - responses.add(responses.POST, 'https://v2.convertapi.com/convert/web/to/pdf?Token=TEST', json = { 'ConversionCost': 123 }) - result = convertapi.convert('pdf', { 'Url': 'dummyurl' }) - assert result.conversion_cost == 123 - - @responses.activate - def test_with_token_and_api_key(self): - convertapi.api_token = 'TEST' - convertapi.api_key = 1 - responses.add(responses.POST, 'https://v2.convertapi.com/convert/web/to/pdf?Token=TEST&ApiKey=1', json = { 'ConversionCost': 123 }) - result = convertapi.convert('pdf', { 'Url': 'dummyurl' }) - assert result.conversion_cost == 123 From 12b961ce1d5d7d457e9935c53bb3f3b0ca7f3e7a Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Sat, 14 Sep 2024 12:01:02 +0300 Subject: [PATCH 10/12] Bump version --- convertapi/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convertapi/__init__.py b/convertapi/__init__.py index e0c4b24..1f5ce61 100644 --- a/convertapi/__init__.py +++ b/convertapi/__init__.py @@ -1,4 +1,4 @@ -__version__ = '1.8.0' +__version__ = '2.0.0' from .exceptions import * from .client import Client From 4a98d3ad107e9baa7ad67af357dbe8577ef7f672 Mon Sep 17 00:00:00 2001 From: Laurynas Butkus Date: Sat, 14 Sep 2024 12:09:48 +0300 Subject: [PATCH 11/12] Update repository url --- LICENSE.txt | 2 +- README.md | 6 +++--- setup.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index eea94d3..37cd8bc 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -3,7 +3,7 @@ https://www.convertapi.com (c) 2011-2018 Baltsoft ConvertAPI.Python -https://github.com/ConvertAPI/convertapi-python +https://github.com/ConvertAPI/convertapi-library-python Copyright (c) 2018 Tomas Rutkauskas The MIT License diff --git a/README.md b/README.md index c05b919..7999b2f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # ConvertAPI Python Client [![PyPI version](https://badge.fury.io/py/convertapi.svg)](https://badge.fury.io/py/convertapi) -[![Build Status](https://github.com/ConvertAPI/convertapi-python/actions/workflows/main.yml/badge.svg)](https://github.com/ConvertAPI/convertapi-python/actions) +[![Build Status](https://github.com/ConvertAPI/convertapi-library-python/actions/workflows/main.yml/badge.svg)](https://github.com/ConvertAPI/convertapi-library-python/actions) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) ## Convert your files with our online file conversion API @@ -119,7 +119,7 @@ convertapi.base_uri = 'https://eu-v2.convertapi.com/' ### More examples -Find more advanced examples in the [/examples](https://github.com/ConvertAPI/convertapi-python/tree/master/examples) folder. +Find more advanced examples in the [/examples](https://github.com/ConvertAPI/convertapi-library-python/tree/master/examples) folder. ## Development @@ -127,7 +127,7 @@ Execute `CONVERT_API_SECRET=your_secret nosetests --nocapture` to run the tests. ## Contributing -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. +Bug reports and pull requests are welcome on GitHub at https://github.com/ConvertAPI/convertapi-library-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. ## License diff --git a/setup.py b/setup.py index a848eaa..9d0b508 100644 --- a/setup.py +++ b/setup.py @@ -11,8 +11,8 @@ long_description = 'Convert various files like MS Word, Excel, PowerPoint, Images to PDF and Images. Create PDF and Images from url and raw HTML. Extract and create PowerPoint presentation from PDF. Merge, Encrypt, Split, Repair and Decrypt PDF files. All supported files conversions and manipulations can be found at https://www.convertapi.com/doc/supported-formats', author = 'Tomas Rutkauskas', author_email = 'support@convertapi.com', - url = 'https://github.com/ConvertAPI/convertapi-python', - download_url = 'https://github.com/ConvertAPI/convertapi-python', + url = 'https://github.com/ConvertAPI/convertapi-library-python', + download_url = 'https://github.com/ConvertAPI/convertapi-library-python', keywords = ['convert', 'api', 'client', 'conversion'], install_requires= ['requests>=2.4.2'], classifiers = [], From 67f66832ca2c641fba18f420c2a3a44ce4316d38 Mon Sep 17 00:00:00 2001 From: Jonas Jasas Date: Tue, 3 Jun 2025 10:31:34 +0300 Subject: [PATCH 12/12] Remove all references to Secret and ApiKey #55 --- README.md | 6 +++--- examples/conversions_chaining.py | 2 +- examples/convert_stream.py | 2 +- examples/convert_url_to_pdf.py | 2 +- examples/convert_word_to_pdf_and_png.py | 2 +- examples/create_pdf_thumbnail.py | 2 +- examples/retrieve_user_information.py | 2 +- examples/split_and_merge_pdf.py | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7999b2f..28204fe 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ You can get your API credentials at https://www.convertapi.com/a ```python import convertapi -convertapi.api_credentials = 'your-api-secret-or-token' +convertapi.api_credentials = 'api-token' ``` #### Proxy configuration @@ -41,7 +41,7 @@ If you need to use a proxy, you can specify it using `HTTPS_PROXY` environment v Example: ``` -CONVERT_API_SECRET=secret HTTPS_PROXY=https://user:pass@127.0.0.1:9000/ python convert_word_to_pdf_and_png.py +API_TOKEN=api-token HTTPS_PROXY=https://user:pass@127.0.0.1:9000/ python convert_word_to_pdf_and_png.py ``` ### File conversion @@ -123,7 +123,7 @@ Find more advanced examples in the [/examples](https://github.com/ConvertAPI/con ## Development -Execute `CONVERT_API_SECRET=your_secret nosetests --nocapture` to run the tests. +Execute `API_TOKEN=api-token nosetests --nocapture` to run the tests. ## Contributing diff --git a/examples/conversions_chaining.py b/examples/conversions_chaining.py index fff7aa7..9e61a36 100644 --- a/examples/conversions_chaining.py +++ b/examples/conversions_chaining.py @@ -2,7 +2,7 @@ import os import tempfile -convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token +convertapi.api_credentials = os.environ['API_TOKEN'] # your api token # Short example of conversions chaining, the PDF pages extracted and saved as separated JPGs and then ZIP'ed # https://www.convertapi.com/doc/chaining diff --git a/examples/convert_stream.py b/examples/convert_stream.py index 5ff2ba3..dd21280 100644 --- a/examples/convert_stream.py +++ b/examples/convert_stream.py @@ -3,7 +3,7 @@ import io import tempfile -convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token +convertapi.api_credentials = os.environ['API_TOKEN'] # your api token # Example of using content stream to convert to pdf # https://www.convertapi.com/txt-to-pdf diff --git a/examples/convert_url_to_pdf.py b/examples/convert_url_to_pdf.py index 7f9c57b..8e44273 100644 --- a/examples/convert_url_to_pdf.py +++ b/examples/convert_url_to_pdf.py @@ -2,7 +2,7 @@ import os import tempfile -convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token +convertapi.api_credentials = os.environ['API_TOKEN'] # your api token # Example of converting Web Page URL to PDF file # https://www.convertapi.com/web-to-pdf diff --git a/examples/convert_word_to_pdf_and_png.py b/examples/convert_word_to_pdf_and_png.py index a406119..670cd40 100644 --- a/examples/convert_word_to_pdf_and_png.py +++ b/examples/convert_word_to_pdf_and_png.py @@ -2,7 +2,7 @@ import os import tempfile -convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token +convertapi.api_credentials = os.environ['API_TOKEN'] # your api token # Example of saving Word docx to PDF and to PNG # https://www.convertapi.com/docx-to-pdf diff --git a/examples/create_pdf_thumbnail.py b/examples/create_pdf_thumbnail.py index 6e548c1..43a7956 100644 --- a/examples/create_pdf_thumbnail.py +++ b/examples/create_pdf_thumbnail.py @@ -2,7 +2,7 @@ import os import tempfile -convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token +convertapi.api_credentials = os.environ['API_TOKEN'] # your api token # Example of extracting first page from PDF and then chaining conversion PDF page to JPG. # https://www.convertapi.com/pdf-to-extract diff --git a/examples/retrieve_user_information.py b/examples/retrieve_user_information.py index b488244..f835c11 100644 --- a/examples/retrieve_user_information.py +++ b/examples/retrieve_user_information.py @@ -1,7 +1,7 @@ import convertapi import os -convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token +convertapi.api_credentials = os.environ['API_TOKEN'] # your api token # Retrieve user information # https://www.convertapi.com/doc/user diff --git a/examples/split_and_merge_pdf.py b/examples/split_and_merge_pdf.py index e4c8d9a..c5da9b5 100644 --- a/examples/split_and_merge_pdf.py +++ b/examples/split_and_merge_pdf.py @@ -2,7 +2,7 @@ import os import tempfile -convertapi.api_credentials = os.environ['CONVERT_API_SECRET'] # your api secret or token +convertapi.api_credentials = os.environ['API_TOKEN'] # your api token # Example of extracting first and last pages from PDF and then merging them back to new PDF. # https://www.convertapi.com/pdf-to-split