From 74b3e0fa848ba3503348279ce8a593e9b2524c6d Mon Sep 17 00:00:00 2001 From: Hleb Albau Date: Mon, 3 Aug 2020 12:32:47 +0300 Subject: [PATCH 1/6] Enhance documentation --- README.md | 70 +++++++++++++++++++++++++++++++++++++++++--- example/Pipfile | 8 ----- example/Pipfile.lock | 11 ++----- example/README.md | 47 +++++++++++++++++++++++++++++ example/example.py | 4 +-- 5 files changed, 117 insertions(+), 23 deletions(-) create mode 100644 example/README.md diff --git a/README.md b/README.md index 0faeb15..5d2441c 100755 --- a/README.md +++ b/README.md @@ -1,12 +1,74 @@ -# Regula Document Reader web application python client +# Regula Document Reader web API Python 3.5+ client + +[![pypi](https://img.shields.io/pypi/v/regula.documentreader.webclient?style=flat-square)](https://support.regulaforensics.com/hc/en-us/articles/115000916306-Documentation) +[![documentation](https://img.shields.io/badge/docs-en-f6858d?style=flat-square)](https://support.regulaforensics.com/hc/en-us/articles/115000916306-Documentation) +[![OpenAPI](https://img.shields.io/badge/OpenAPI-defs-0a8c42?style=flat-square)](https://github.com/regulaforensics/DocumentReader-web-openapi) + +Documents recognition as easy as reading two bytes. + +If you have any problems with or questions about this client, please contact us +through a [GitHub issue](https://github.com/regulaforensics/DocumentReader-web-python-client/issues). +You are invited to contribute [new features, fixes, or updates](https://github.com/regulaforensics/DocumentReader-web-python-client/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22), large or small; We are always thrilled to receive pull requests, and do our best to process them as fast as we can. + +## Install package +`regula.documentreader.webclient` is on the Python Package Index (PyPI): + +```bash +pip install regula.documentreader.webclient +``` + +Or using `pipenv` +```bash +pipenv install regula.documentreader.webclient +``` + +## Example +Performing request: +```python +from regula.documentreader.webclient.ext.api import DocumentReaderApi +from regula.documentreader.webclient.ext.models import * +from regula.documentreader.webclient.gen.models import * + +with open("australia_passport.jpg", "rb") as f: + input_image = f.read() + +with DocumentReaderApi(host='http://localhost:8080') as api: + params = ProcessParams( + scenario=Scenario.FULL_PROCESS, + result_type_output=[Result.RAW_IMAGE, Result.STATUS, Result.TEXT, Result.IMAGES] + ) + request = RecognitionRequest(process_params=params, images=[input_image]) + response = api.process(request) +``` + +Parsing results: +```python +# status examples +response_status = response.status +doc_overall_status = "valid" if response_status.overall_status == CheckResult.OK else "not valid" + +# text fields example +doc_number_field = response.text.get_field(TextFieldType.DOCUMENT_NUMBER) +doc_number_mrz = doc_number_field.get_value() +doc_number_visual = doc_number_field.get_value(Source.VISUAL) +doc_number_visual_validity = doc_number_field.source_validity(Source.VISUAL) +doc_number_mrz_validity = doc_number_field.source_validity(Source.MRZ) +doc_number_mrz_visual_matching = doc_number_field.cross_source_comparison(Source.MRZ, Source.VISUAL) + +# images fields example +normalized_input_image = response.images.normalized_input_image() +portrait_field = response.images.get_field(GraphicFieldType.PORTRAIT) +portrait_from_visual = portrait_field.get_value(Source.VISUAL) +portrait_from_rfid = portrait_field.get_value(Source.RFID, original=True) +``` +You can find more detailed guide and run this sample in [example](./example) folder. ## Development -To regenerate models from openapi definition, -clone [latest open api definitions](https://github.com/regulaforensics/DocumentReader-api-openapi) +To regenerate models, clone [latest OpenAPI definitions](https://github.com/regulaforensics/DocumentReader-web-openapi) and set `DEFINITION_FOLDER` as path to cloned directory, for example: ```bash -DEFINITION_FOLDER="/home/user/projects/DocumentReader-api-openapi" +DEFINITION_FOLDER="/home/user/projects/DocumentReader-web-openapi" ``` Then use next command from the project root: ```bash diff --git a/example/Pipfile b/example/Pipfile index dcfc727..9ba71dd 100755 --- a/example/Pipfile +++ b/example/Pipfile @@ -3,13 +3,5 @@ url = "https://pypi.python.org/simple" verify_ssl = true name = "pypi" -[[source]] -url = "https://test.pypi.org/simple/" -verify_ssl = true -name = "test-pypi" - [packages] "regula.documentreader.webclient" = {editable = true,path = "./.."} - -[requires] -python_version = "3.5" diff --git a/example/Pipfile.lock b/example/Pipfile.lock index 00a2513..82f83e4 100755 --- a/example/Pipfile.lock +++ b/example/Pipfile.lock @@ -1,22 +1,15 @@ { "_meta": { "hash": { - "sha256": "5096dd2d4162b442dbae72ea134b4c170c06dcf6967c2dbc661f5be6e4cac554" + "sha256": "7083976f112492610b864f10c6c407b1adf3d0355cc0f767d83a14b7f08ca301" }, "pipfile-spec": 6, - "requires": { - "python_version": "3.5" - }, + "requires": {}, "sources": [ { "name": "pypi", "url": "https://pypi.python.org/simple", "verify_ssl": true - }, - { - "name": "test-pypi", - "url": "https://test.pypi.org/simple/", - "verify_ssl": true } ] }, diff --git a/example/README.md b/example/README.md new file mode 100644 index 0000000..41444e7 --- /dev/null +++ b/example/README.md @@ -0,0 +1,47 @@ +# Regula Document Reader web API Python 3.5+ client + +## Running example + +Requirements: +- installed python 3.5 or higher +- installed [pipenv](https://pypi.org/project/pipenv) +- running Regula Document Reader web application(todo link for docker run?) with trial license(todo edit desc here) + +Cloning example +```bash +git clone https://github.com/regulaforensics/DocumentReader-web-python-client.git +cd example +``` + +Setup project and download dependencies: +```bash +pipenv install +``` + +Run example: +```bash +pipenv run python example.py + +# If Regula Document Reader web API is running not on localhost, also specify host via env variable: +API_BASE_PATH="http://192.168.0.101:8080" pipenv run python example.py +``` + +This sample generate next text output: +```text + --------------------------------------------------------------------------- + Document Overall Status: not valid + Document Number Visual: U0996738 + Document Number MRZ: U0996738 + Validity Of Document Number Visual: 1 + Validity Of Document Number MRZ: 1 + MRZ-Visual values comparison: 1 + --------------------------------------------------------------------------- +``` +Also, it creates [portrait](portraitFromVisual.jpg) and [normalized input](normalizedInputImage.jpg) +pictures inside current folder. + +Edit on your own [example.py](./example.py), and re-run to see your results. + +## Detailed guide + +tbd diff --git a/example/example.py b/example/example.py index 58f97d5..815cdc6 100755 --- a/example/example.py +++ b/example/example.py @@ -27,8 +27,8 @@ # text fields example doc_number_field = response.text.get_field(TextFieldType.DOCUMENT_NUMBER) - doc_number_visual = doc_number_field.get_value() - doc_number_mrz = doc_number_field.get_value(Source.MRZ) + doc_number_mrz = doc_number_field.get_value() + doc_number_visual = doc_number_field.get_value(Source.VISUAL) doc_number_visual_validity = doc_number_field.source_validity(Source.VISUAL) doc_number_mrz_validity = doc_number_field.source_validity(Source.MRZ) doc_number_mrz_visual_matching = doc_number_field.cross_source_comparison(Source.MRZ, Source.VISUAL) From 78f3704c62907e18e52f4fd88910df0b55d64d48 Mon Sep 17 00:00:00 2001 From: Hleb Albau Date: Tue, 4 Aug 2020 11:58:29 +0300 Subject: [PATCH 2/6] Enhance documentation: fix comments - 1 --- README.md | 26 +++++++------------------- dev.md | 14 ++++++++++++++ example/README.md | 10 ++++++---- example/example.py | 6 +++--- 4 files changed, 30 insertions(+), 26 deletions(-) create mode 100644 dev.md diff --git a/README.md b/README.md index 5d2441c..a5ba5de 100755 --- a/README.md +++ b/README.md @@ -1,14 +1,17 @@ # Regula Document Reader web API Python 3.5+ client [![pypi](https://img.shields.io/pypi/v/regula.documentreader.webclient?style=flat-square)](https://support.regulaforensics.com/hc/en-us/articles/115000916306-Documentation) +[![OpenAPI](https://img.shields.io/badge/OpenAPI-defs-8c0a56?style=flat-square)](https://github.com/regulaforensics/DocumentReader-web-openapi) [![documentation](https://img.shields.io/badge/docs-en-f6858d?style=flat-square)](https://support.regulaforensics.com/hc/en-us/articles/115000916306-Documentation) -[![OpenAPI](https://img.shields.io/badge/OpenAPI-defs-0a8c42?style=flat-square)](https://github.com/regulaforensics/DocumentReader-web-openapi) +[![live](https://img.shields.io/badge/live-demo-0a8c42?style=flat-square)](https://api.regulaforensics.com/) Documents recognition as easy as reading two bytes. If you have any problems with or questions about this client, please contact us through a [GitHub issue](https://github.com/regulaforensics/DocumentReader-web-python-client/issues). -You are invited to contribute [new features, fixes, or updates](https://github.com/regulaforensics/DocumentReader-web-python-client/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22), large or small; We are always thrilled to receive pull requests, and do our best to process them as fast as we can. +You are invited to contribute [new features, fixes, or updates](https://github.com/regulaforensics/DocumentReader-web-python-client/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22), large or small; +We are always thrilled to receive pull requests, and do our best to process them as fast as we can. +See [dev guide](./dev.md) ## Install package `regula.documentreader.webclient` is on the Python Package Index (PyPI): @@ -35,7 +38,7 @@ with open("australia_passport.jpg", "rb") as f: with DocumentReaderApi(host='http://localhost:8080') as api: params = ProcessParams( scenario=Scenario.FULL_PROCESS, - result_type_output=[Result.RAW_IMAGE, Result.STATUS, Result.TEXT, Result.IMAGES] + result_type_output=[Result.DOCUMENT_IMAGE, Result.STATUS, Result.TEXT, Result.IMAGES] ) request = RecognitionRequest(process_params=params, images=[input_image]) response = api.process(request) @@ -56,24 +59,9 @@ doc_number_mrz_validity = doc_number_field.source_validity(Source.MRZ) doc_number_mrz_visual_matching = doc_number_field.cross_source_comparison(Source.MRZ, Source.VISUAL) # images fields example -normalized_input_image = response.images.normalized_input_image() +normalized_input_image = response.images.document_image() portrait_field = response.images.get_field(GraphicFieldType.PORTRAIT) portrait_from_visual = portrait_field.get_value(Source.VISUAL) portrait_from_rfid = portrait_field.get_value(Source.RFID, original=True) ``` You can find more detailed guide and run this sample in [example](./example) folder. - -## Development - -To regenerate models, clone [latest OpenAPI definitions](https://github.com/regulaforensics/DocumentReader-web-openapi) -and set `DEFINITION_FOLDER` as path to cloned directory, for example: -```bash -DEFINITION_FOLDER="/home/user/projects/DocumentReader-web-openapi" -``` -Then use next command from the project root: -```bash -docker run --rm -v "${PWD}:/client" -v "${DEFINITION_FOLDER}:/definitions" \ -openapitools/openapi-generator-cli generate -g python \ --i /definitions/index.yml -o /client -c /client/generator-config.json \ --t /client/generator-templates -``` diff --git a/dev.md b/dev.md new file mode 100644 index 0000000..60d766a --- /dev/null +++ b/dev.md @@ -0,0 +1,14 @@ +# Development + +To regenerate models, clone [latest OpenAPI definitions](https://github.com/regulaforensics/DocumentReader-web-openapi) +and set `DEFINITION_FOLDER` as path to cloned directory, for example: +```bash +DEFINITION_FOLDER="/home/user/projects/DocumentReader-web-openapi" +``` +Then use next command from the project root: +```bash +docker run --rm -v "${PWD}:/client" -v "${DEFINITION_FOLDER}:/definitions" \ +openapitools/openapi-generator-cli generate -g python \ +-i /definitions/index.yml -o /client -c /client/generator-config.json \ +-t /client/generator-templates +``` diff --git a/example/README.md b/example/README.md index 41444e7..2d1e55d 100644 --- a/example/README.md +++ b/example/README.md @@ -1,11 +1,13 @@ # Regula Document Reader web API Python 3.5+ client -## Running example +Before you start: if you just want to play with an online demo, visit our [playground](https://api.regulaforensics.com). + +## Running local example Requirements: - installed python 3.5 or higher - installed [pipenv](https://pypi.org/project/pipenv) -- running Regula Document Reader web application(todo link for docker run?) with trial license(todo edit desc here) +- running [Regula Document Reader web API with trial license](https://docs.regulaforensics.com/web/quick-start-guide) Cloning example ```bash @@ -26,7 +28,7 @@ pipenv run python example.py API_BASE_PATH="http://192.168.0.101:8080" pipenv run python example.py ``` -This sample generate next text output: +This sample generates next text output: ```text --------------------------------------------------------------------------- Document Overall Status: not valid @@ -37,7 +39,7 @@ This sample generate next text output: MRZ-Visual values comparison: 1 --------------------------------------------------------------------------- ``` -Also, it creates [portrait](portraitFromVisual.jpg) and [normalized input](normalizedInputImage.jpg) +Also, it creates [portrait](portrait.jpg) and [document image](document-image.jpg) pictures inside current folder. Edit on your own [example.py](./example.py), and re-run to see your results. diff --git a/example/example.py b/example/example.py index 815cdc6..0294755 100755 --- a/example/example.py +++ b/example/example.py @@ -35,9 +35,9 @@ # images fields example document_image = response.images.document_image() - portrait_Field = response.images.get_field(GraphicFieldType.PORTRAIT) - portrait_From_Visual = portrait_Field.get_value(Source.VISUAL) - with open('portrait.jpg', 'wb') as f: f.write(portrait_From_Visual) + portrait_field = response.images.get_field(GraphicFieldType.PORTRAIT) + portrait_from_visual = portrait_field.get_value(Source.VISUAL) + with open('portrait.jpg', 'wb') as f: f.write(portrait_from_visual) with open('document-image.jpg', 'wb') as f: f.write(document_image) # low-lvl(original) response From 9a1b05a5e9a603171f080a22c2a2932cafd4b76c Mon Sep 17 00:00:00 2001 From: Hleb Albau Date: Tue, 4 Aug 2020 12:42:47 +0300 Subject: [PATCH 3/6] Enhance documentation: fix comments - 2 --- example/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/example/README.md b/example/README.md index 2d1e55d..e68e386 100644 --- a/example/README.md +++ b/example/README.md @@ -12,6 +12,7 @@ Requirements: Cloning example ```bash git clone https://github.com/regulaforensics/DocumentReader-web-python-client.git +cd DocumentReader-web-python-client cd example ``` From e682c3416de7b07b5b058704ec19a44775149680 Mon Sep 17 00:00:00 2001 From: Hleb Albau Date: Tue, 4 Aug 2020 13:25:44 +0300 Subject: [PATCH 4/6] Use raw pip instead of pipenv for example running --- .github/workflows/run-smoke-test.yml | 6 +-- example/Pipfile | 7 ---- example/Pipfile.lock | 57 ---------------------------- example/README.md | 22 ++++++++--- 4 files changed, 18 insertions(+), 74 deletions(-) delete mode 100755 example/Pipfile delete mode 100755 example/Pipfile.lock diff --git a/.github/workflows/run-smoke-test.yml b/.github/workflows/run-smoke-test.yml index 58bf3db..4d81c8a 100755 --- a/.github/workflows/run-smoke-test.yml +++ b/.github/workflows/run-smoke-test.yml @@ -21,12 +21,10 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install --upgrade setuptools wheel - python -m pip install --upgrade pipenv==2018.11.26 - name: Install test dependencies - run: pipenv install --dev - working-directory: example + run: pip install -e ./ - name: Run smoke test - run: pipenv run python example.py + run: python example.py working-directory: example env: API_BASE_PATH: "http://test-api.regulaforensics.com" diff --git a/example/Pipfile b/example/Pipfile deleted file mode 100755 index 9ba71dd..0000000 --- a/example/Pipfile +++ /dev/null @@ -1,7 +0,0 @@ -[[source]] -url = "https://pypi.python.org/simple" -verify_ssl = true -name = "pypi" - -[packages] -"regula.documentreader.webclient" = {editable = true,path = "./.."} diff --git a/example/Pipfile.lock b/example/Pipfile.lock deleted file mode 100755 index 82f83e4..0000000 --- a/example/Pipfile.lock +++ /dev/null @@ -1,57 +0,0 @@ -{ - "_meta": { - "hash": { - "sha256": "7083976f112492610b864f10c6c407b1adf3d0355cc0f767d83a14b7f08ca301" - }, - "pipfile-spec": 6, - "requires": {}, - "sources": [ - { - "name": "pypi", - "url": "https://pypi.python.org/simple", - "verify_ssl": true - } - ] - }, - "default": { - "certifi": { - "hashes": [ - "sha256:5930595817496dd21bb8dc35dad090f1c2cd0adfaf21204bf6732ca5d8ee34d3", - "sha256:8fc0819f1f30ba15bdb34cceffb9ef04d99f420f68eb75d901e9560b8749fc41" - ], - "version": "==2020.6.20" - }, - "future": { - "hashes": [ - "sha256:b1bead90b70cf6ec3f0710ae53a525360fa360d306a86583adc6bf83a4db537d" - ], - "version": "==0.18.2" - }, - "python-dateutil": { - "hashes": [ - "sha256:73ebfe9dbf22e832286dafa60473e4cd239f8592f699aa5adaf10050e6e1823c", - "sha256:75bb3f31ea686f1197762692a9ee6a7550b59fc6ca3a1f4b5d7e32fb98e2da2a" - ], - "version": "==2.8.1" - }, - "regula.documentreader.webclient": { - "editable": true, - "path": "./.." - }, - "six": { - "hashes": [ - "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259", - "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced" - ], - "version": "==1.15.0" - }, - "urllib3": { - "hashes": [ - "sha256:91056c15fa70756691db97756772bb1eb9678fa585d9184f24534b100dc60f4a", - "sha256:e7983572181f5e1522d9c98453462384ee92a0be7fac5f1413a1e35c56cc0461" - ], - "version": "==1.25.10" - } - }, - "develop": {} -} diff --git a/example/README.md b/example/README.md index e68e386..223ed1e 100644 --- a/example/README.md +++ b/example/README.md @@ -4,29 +4,39 @@ Before you start: if you just want to play with an online demo, visit our [playg ## Running local example +NOTE: for some systems `python3` and `pip3` commands should be used, instead of `python` and `pip`. + Requirements: - installed python 3.5 or higher -- installed [pipenv](https://pypi.org/project/pipenv) +- installed [pip](https://pip.pypa.io/en/stable/installing/) - running [Regula Document Reader web API with trial license](https://docs.regulaforensics.com/web/quick-start-guide) -Cloning example +Verify Python and pip versions: +```bash +python --version +> Python 3.8.2 +pip --version +> pip 20.2.1 from /home/user/.local/lib/python3.8/site-packages/pip (python 3.8) +``` + +Cloning example: ```bash git clone https://github.com/regulaforensics/DocumentReader-web-python-client.git cd DocumentReader-web-python-client -cd example ``` Setup project and download dependencies: ```bash -pipenv install +pip install -e ./ ``` Run example: ```bash -pipenv run python example.py +cd example +python example.py # If Regula Document Reader web API is running not on localhost, also specify host via env variable: -API_BASE_PATH="http://192.168.0.101:8080" pipenv run python example.py +API_BASE_PATH="http://192.168.0.101:8080" python example.py ``` This sample generates next text output: From a77b2e8a8c58163d253fdf42b4ec34d29c2183a8 Mon Sep 17 00:00:00 2001 From: Hleb Albau Date: Tue, 4 Aug 2020 15:16:07 +0300 Subject: [PATCH 5/6] add option to run example with local license --- .gitignore | 1 + example/README.md | 34 +++++++++++-------- example/example.py | 8 ++++- .../webclient/ext/api/document_reader_api.py | 14 ++++++-- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index d89e878..5b82fb4 100755 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea example/portrait.jpg example/document-image.jpg +example/regula.license # Byte-compiled / optimized / DLL files diff --git a/example/README.md b/example/README.md index 223ed1e..172e692 100644 --- a/example/README.md +++ b/example/README.md @@ -1,15 +1,12 @@ # Regula Document Reader web API Python 3.5+ client -Before you start: if you just want to play with an online demo, visit our [playground](https://api.regulaforensics.com). +:bulb: Before you start: if you just want to play with an online demo, visit our [playground](https://api.regulaforensics.com). -## Running local example - -NOTE: for some systems `python3` and `pip3` commands should be used, instead of `python` and `pip`. +:warning: NOTE: for some systems `python3` and `pip3` commands should be used, instead of `python` and `pip`. Requirements: - installed python 3.5 or higher - installed [pip](https://pip.pypa.io/en/stable/installing/) -- running [Regula Document Reader web API with trial license](https://docs.regulaforensics.com/web/quick-start-guide) Verify Python and pip versions: ```bash @@ -30,15 +27,30 @@ Setup project and download dependencies: pip install -e ./ ``` -Run example: +### Running with local Regula Document Reader web API installation + +Follow [the instructions](https://docs.regulaforensics.com/web/quick-start-guide) to run Regula Document Reader web API. +Assuming you have successfully launched instance, use next line command to run example: ```bash cd example python example.py -# If Regula Document Reader web API is running not on localhost, also specify host via env variable: +# If Regula Document Reader web API is running not on localhost, specify host via env variable: API_BASE_PATH="http://192.168.0.101:8080" python example.py ``` +### Running using Regula Document Reader web API test SaaS + +Get your [free trial here](https://mobile.regulaforensics.com/). You should obtain `regula.license` file. +Copy it to **example** folder. You are ready for running! + +Execute example: +```bash +cd example +API_BASE_PATH="https://test-api.regulaforensics.com" python example.py +``` + +### Output This sample generates next text output: ```text --------------------------------------------------------------------------- @@ -50,11 +62,5 @@ This sample generates next text output: MRZ-Visual values comparison: 1 --------------------------------------------------------------------------- ``` -Also, it creates [portrait](portrait.jpg) and [document image](document-image.jpg) -pictures inside current folder. - +Also, it creates [portrait](portrait.jpg) and [document image](document-image.jpg) pictures inside current folder. Edit on your own [example.py](./example.py), and re-run to see your results. - -## Detailed guide - -tbd diff --git a/example/example.py b/example/example.py index 0294755..6f7f831 100755 --- a/example/example.py +++ b/example/example.py @@ -8,11 +8,17 @@ host = os.getenv("API_BASE_PATH", "http://localhost:8080") license = os.getenv("TEST_LICENSE", None) # optional, used here only for smoke test purposes +# read optional local license file +if os.path.isfile('regula.license') and os.access('regula.license', os.R_OK): + with open("regula.license", "rb") as f: + print("Found local license file. Using it for performing request...") + license = f.read() + with open("australia_passport.jpg", "rb") as f: input_image = f.read() with DocumentReaderApi(host) as api: - api.license = license # used here only for smoke test purposes, most clients will attach license on server side + api.license = license params = ProcessParams( scenario=Scenario.FULL_PROCESS, diff --git a/regula/documentreader/webclient/ext/api/document_reader_api.py b/regula/documentreader/webclient/ext/api/document_reader_api.py index 9cdf95c..fa4daa4 100755 --- a/regula/documentreader/webclient/ext/api/document_reader_api.py +++ b/regula/documentreader/webclient/ext/api/document_reader_api.py @@ -1,8 +1,13 @@ +import base64 +from typing import Union + from regula.documentreader.webclient.ext.models.recognition_response import RecognitionResponse from regula.documentreader.webclient.gen import ApiClient, Configuration from regula.documentreader.webclient.gen.api import DefaultApi from regula.documentreader.webclient.gen.models import ProcessRequest +Base64String = str + class DocumentReaderApi(DefaultApi): @@ -24,12 +29,15 @@ def __exit__(self, exc_type, exc_val, exc_tb): self.api_client.close() @property - def license(self) -> str: + def license(self) -> Base64String: return self.__license @license.setter - def license(self, value: str): - self.__license = value + def license(self, value: Union[Base64String, bytes]): + if isinstance(value, bytes): + self.__license = base64.b64encode(value).decode("utf-8") + else: + self.__license = value def process(self, process_request: ProcessRequest) -> RecognitionResponse: process_request.system_info.license = self.license From 7804a88d830fa4295f2b98b972b51f6df293d0fd Mon Sep 17 00:00:00 2001 From: Hleb Albau Date: Tue, 4 Aug 2020 16:32:30 +0300 Subject: [PATCH 6/6] remove warnings from example --- example/example.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/example/example.py b/example/example.py index 6f7f831..2b4bb76 100755 --- a/example/example.py +++ b/example/example.py @@ -6,19 +6,19 @@ CheckResult, GraphicFieldType host = os.getenv("API_BASE_PATH", "http://localhost:8080") -license = os.getenv("TEST_LICENSE", None) # optional, used here only for smoke test purposes +regula_license = os.getenv("TEST_LICENSE", None) # optional, used here only for smoke test purposes # read optional local license file if os.path.isfile('regula.license') and os.access('regula.license', os.R_OK): with open("regula.license", "rb") as f: print("Found local license file. Using it for performing request...") - license = f.read() + regula_license = f.read() with open("australia_passport.jpg", "rb") as f: input_image = f.read() with DocumentReaderApi(host) as api: - api.license = license + api.license = regula_license params = ProcessParams( scenario=Scenario.FULL_PROCESS, @@ -43,11 +43,10 @@ document_image = response.images.document_image() portrait_field = response.images.get_field(GraphicFieldType.PORTRAIT) portrait_from_visual = portrait_field.get_value(Source.VISUAL) - with open('portrait.jpg', 'wb') as f: f.write(portrait_from_visual) - with open('document-image.jpg', 'wb') as f: f.write(document_image) - - # low-lvl(original) response - response.low_lvl_response + with open('portrait.jpg', 'wb') as f: + f.write(portrait_from_visual) + with open('document-image.jpg', 'wb') as f: + f.write(document_image) print(""" ---------------------------------------------------------------------------