Skip to content

Commit a77b2e8

Browse files
committed
add option to run example with local license
1 parent e682c34 commit a77b2e8

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.idea
22
example/portrait.jpg
33
example/document-image.jpg
4+
example/regula.license
45

56

67
# Byte-compiled / optimized / DLL files

example/README.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
# Regula Document Reader web API Python 3.5+ client
22

3-
Before you start: if you just want to play with an online demo, visit our [playground](https://api.regulaforensics.com).
3+
:bulb: Before you start: if you just want to play with an online demo, visit our [playground](https://api.regulaforensics.com).
44

5-
## Running local example
6-
7-
NOTE: for some systems `python3` and `pip3` commands should be used, instead of `python` and `pip`.
5+
:warning: NOTE: for some systems `python3` and `pip3` commands should be used, instead of `python` and `pip`.
86

97
Requirements:
108
- installed python 3.5 or higher
119
- installed [pip](https://pip.pypa.io/en/stable/installing/)
12-
- running [Regula Document Reader web API with trial license](https://docs.regulaforensics.com/web/quick-start-guide)
1310

1411
Verify Python and pip versions:
1512
```bash
@@ -30,15 +27,30 @@ Setup project and download dependencies:
3027
pip install -e ./
3128
```
3229

33-
Run example:
30+
### Running with local Regula Document Reader web API installation
31+
32+
Follow [the instructions](https://docs.regulaforensics.com/web/quick-start-guide) to run Regula Document Reader web API.
33+
Assuming you have successfully launched instance, use next line command to run example:
3434
```bash
3535
cd example
3636
python example.py
3737

38-
# If Regula Document Reader web API is running not on localhost, also specify host via env variable:
38+
# If Regula Document Reader web API is running not on localhost, specify host via env variable:
3939
API_BASE_PATH="http://192.168.0.101:8080" python example.py
4040
```
4141

42+
### Running using Regula Document Reader web API test SaaS
43+
44+
Get your [free trial here](https://mobile.regulaforensics.com/). You should obtain `regula.license` file.
45+
Copy it to **example** folder. You are ready for running!
46+
47+
Execute example:
48+
```bash
49+
cd example
50+
API_BASE_PATH="https://test-api.regulaforensics.com" python example.py
51+
```
52+
53+
### Output
4254
This sample generates next text output:
4355
```text
4456
---------------------------------------------------------------------------
@@ -50,11 +62,5 @@ This sample generates next text output:
5062
MRZ-Visual values comparison: 1
5163
---------------------------------------------------------------------------
5264
```
53-
Also, it creates [portrait](portrait.jpg) and [document image](document-image.jpg)
54-
pictures inside current folder.
55-
65+
Also, it creates [portrait](portrait.jpg) and [document image](document-image.jpg) pictures inside current folder.
5666
Edit on your own [example.py](./example.py), and re-run to see your results.
57-
58-
## Detailed guide
59-
60-
tbd

example/example.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
host = os.getenv("API_BASE_PATH", "http://localhost:8080")
99
license = os.getenv("TEST_LICENSE", None) # optional, used here only for smoke test purposes
1010

11+
# read optional local license file
12+
if os.path.isfile('regula.license') and os.access('regula.license', os.R_OK):
13+
with open("regula.license", "rb") as f:
14+
print("Found local license file. Using it for performing request...")
15+
license = f.read()
16+
1117
with open("australia_passport.jpg", "rb") as f:
1218
input_image = f.read()
1319

1420
with DocumentReaderApi(host) as api:
15-
api.license = license # used here only for smoke test purposes, most clients will attach license on server side
21+
api.license = license
1622

1723
params = ProcessParams(
1824
scenario=Scenario.FULL_PROCESS,

regula/documentreader/webclient/ext/api/document_reader_api.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import base64
2+
from typing import Union
3+
14
from regula.documentreader.webclient.ext.models.recognition_response import RecognitionResponse
25
from regula.documentreader.webclient.gen import ApiClient, Configuration
36
from regula.documentreader.webclient.gen.api import DefaultApi
47
from regula.documentreader.webclient.gen.models import ProcessRequest
58

9+
Base64String = str
10+
611

712
class DocumentReaderApi(DefaultApi):
813

@@ -24,12 +29,15 @@ def __exit__(self, exc_type, exc_val, exc_tb):
2429
self.api_client.close()
2530

2631
@property
27-
def license(self) -> str:
32+
def license(self) -> Base64String:
2833
return self.__license
2934

3035
@license.setter
31-
def license(self, value: str):
32-
self.__license = value
36+
def license(self, value: Union[Base64String, bytes]):
37+
if isinstance(value, bytes):
38+
self.__license = base64.b64encode(value).decode("utf-8")
39+
else:
40+
self.__license = value
3341

3442
def process(self, process_request: ProcessRequest) -> RecognitionResponse:
3543
process_request.system_info.license = self.license

0 commit comments

Comments
 (0)