Web API Barcode Reader - Python SDK
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore Update 2 May 29, 2015
1d.pdf
2d.pdf Initial commit May 27, 2015
LICENSE Initial commit May 27, 2015
README.md
sample_code.py
test.py Initial commit May 27, 2015
wabr.py Initial commit May 27, 2015

README.md

wabr-python

Web API Barcode Reader Server  (WABR) offers a REST API for the Inlite Research ClearImage Barcode Recognition technology.
This wabr-python SDK simplifies the WABR client-side Python development.
Place wabr.py from this repository into any folder in PYTHON_PATH.
Use sample code from test.py and sample_code.py This SDK requires Python 2.6 or higher version.

Create a Reader

from wabr import  WAUtils, WABarcodeReader, WABarcode
WAUtils.SetStdoutUTF8()  # optionally enable non-ASCII barcode text and file names

reader = WABarcodeReader(serverUrl, authorization)

Where

  • serverURL is the WABR server URL
    • It is the URL of your hosted server
    • To interact with the Inlite-hosted Test Server use the empty string to send HTTP Request to wabr.inliteresearch.com.
  • authorization is a value set in Authorization field of the HTTP Request header. If authorization is an empty string, then the value is set from the WABR_AUTH environmental variable (if present).
    • For your hosted server: Use the empty string if no authentication is required, otherwise use the value expected by your IIS Authentication handler
    • For the Inlite-hosted Test Server: Use the Authorization Code supplied by Inlite. Without a valid authorization value, the Test Server returns partial results, which could be sufficient for testing the operation of your client-side code. To obtain an Authorization Code contact Inlite at sales@inliteresearch.com.

Read barcodes

Use the Read() method to obtain barcode values as an Array of WABarcode objects

try:
   barcodes = reader.Read(image_source, types, directions, tbr_code)
   # Process barcode reading results
except:
   exc_type, exc_value, exc_traceback = sys.exc_info()
   WAUtils.printUTF8 ("EXCEPTION: " +  str(exc_value))  

Parameters

  • image_source is a required parameter that points to the image(s) that the WABR server will read. The following formats are accepted.
    • URL of Internet-based file. The name should start with http:// , https:// or file://. Examples:
    https://wabr.inliteresearch.com/SampleImages/1d.pdf
    ttp://upload.wikimedia.org/wikipedia/commons/0/07/Better_Sample_PDF417.png
    
- *Path* of a file located on or accessible from the client.     Examples: 
```
c:/image_folder/some_image_file.tif
\\COMPUTER_NAME\another_folder\another_file.pdf
```
- *Base64-encoded* string representing content of an image file.    Format:
```
[ data:[<MIME-type>][;base64],]<content>[:::<filename>]
```
Example: 
```
data:application/pdf;base64,WTTVKM3OWFKFMERCMT5... :::IMAGE_FILE.PDF
```

The values in [ ] are optional. The values in < > are variables. NOTE: Neither [ ] nor < > should be included in image_source string.
content is the only required value. It is an image file content encoded as base64.
filename is a value assigned to WABarcode.File property of each barcode. Default is an empty string.
MIME-type identifies file format. e.g. application/pdf or image/tiff. The value is only for compatibility with data URI scheme. The Barcode reader will automatically identify file format based on content.


Most popular image formats are acceptable as image_source, including *PDF*, *TIF*, *JPEG* etc. Multi-page *PDF* and *TIF* files are supported
To specify several image sources in a single request separate them with the ` | ` character. + `types` is an optional string parameter (*not case-sensitive*) that contains *comma-separated* barcode types to read. An empty string is the same as `1d,2d`. The list of valid type is available in the `WABarcodeReader.validtypes` variable. Barcodes in this list are:
`1d` - same as `Code39, Code128, Code93, Ucc128, Codabar, Interleaved2of5, Upca, Upce, Ean8, Ean13`<br>
`Code39` - Code 39 Full ASCII<br>
`Code128` - Code 128<br>
`Code93` - Code 93<br>
`Codabar` - Codabar<br>
`Ucc128` - GS1-128<br>
`Interleaved2of5` - Inteleaved 2 of 5<br>
`Ean13` - EAN-13<br>
`Ean8` - EAN-8<br>
`Upca` - UPC-A<br>
`Upce` - UPC-E<br>
`2d` - same as `Pdf417, DatMatrix, QR`<br>
`Pdf417` - PDF417 code<br>
`DataMatrix` - DataMatrix code<br>
`QR` - QR code<br>
`DrvLic` - Driver License, ID Cards and military CAC ID<br>
`postal` - same as `imb, bpo, aust, sing, postnet`<br>
`imb` - US Post Intelligent Mail Barcode<br>
`bpo` - UK Royal Mail barcode (RM4SCC)<br>
`aust` - Australia Post barcode<br>
`sing` - Singapore Post barcode <br>
`postnet` - Postnet, Planet<br>
`Code39basic` - Code 93 Basic<br>
`Patch` - Patch code<br>
  • directions is an optional string parameter, which limits the barcode recognition only to barcodes with the specified orientation. This limitation can reduce recognition time. Valid values are:

    an empty string (default) - read barcode in any direction and skew angle.
    horz - read only horizontal barcodes.
    vert - read only vertical barcodes.
    horz, vert - read only horizontal and vertical barcodes.

  • tbr_code is an optional integer parameter supplied by Inlite to addresses customer-specific requirements for barcode recognition. Read more about Targeted Barcode Reader (TBR). The default value is 0, meaning TBR is disabled.

Use barcode reading results

The following examples demonstrate processing of an Array of WABarcode objects returned by Read() method.
Examples use WAUtils.printUTF8 to correctly represent UTF8 character on stdout.

Print each barcode text value, type and file name:

for n in range(0, len(barcodes)):
   barcode = barcodes[n]
   WAUtils.printUTF8("Barcode Type:" + barcode.Type + "  File:" + barcode.File)
   WAUtils.printUTF8(barcode.Text)

Decode Values of a Driver License, ID Card or Military CAC Card. To obtain these values include DrvLic in the types parameter of the Read() call.

for key in barcode.Values:
    WAUtils.printUTF8 (key + ' : ' + barcode.Values[key])

WABarcode properties

Text - barcode text value (ASCII or UTF-8 if enabled) [string]
Data - binary data encoded in Pdf417, DataMatrix or QR barcodes [array of bytes]
Type - barcode type [string]
Page - page in multi-page PDF and TIF file [integer]
Top - top coordinate in pixels [integer]
Left - left coordinate in pixels [integer]
Right - right coordinate in pixels [integer]
Bottom - bottom coordinate in pixels [integer]
File - file name of image file. Depending on image_source type it is
            a URL value, base-name of Path, filename of Base64-encoded string (if present) [string]
Rotation - rotation of barcode on a page. Values: none, upsideDown, left, right or diagonal [string]
Meta - XML formatted string representing barcode meta-data [string]
Values - Driver License fields, such as last name, date of birth etc. [dictionary: key-field name string as key, value - field value string]

UTF8 barcode Text and File values

Pdf417, DataMatrix or QR barcodes can contain language specific text. In such cases, the Text variable contains UTF8 string. Also, the Read() method accepts image_source as UTF8 string, and the resulting File variable may also be UTF8 encoded.
To represent UTF8 string on stdout use helper methods:

  • WAUtils.SetStdoutUTF8() should be called once in your application.
  • WAUtils.printUTF8(string) should be used to print UTF8 strings to stdout