Python SDK for Lucidtech AI Services
Project description
# Python SDK for Lucidtech AI Services API
## Documentation
[Link to docs](https://docs.lucidtech.ai/python/index.html)
## Installation
```bash
$ pip install lucidtech-las
```
## Usage
### Preconditions
- Documents must be in upright position
- Only one receipt or invoice per document is supported
- Supported file formats are: jpeg, png, gif, bmp, pdf
### Scan Receipt
```python
from las import Client, Receipt
api_key = '...'
client = Client(api_key)
# With URL
receipt = Receipt(url='https://example.com/img.jpeg')
# With file object
with open('img.jpeg', 'rb') as fp:
receipt = Receipt(fp=fp)
# With filename
receipt = Receipt(filename='img.jpeg')
response = client.scan_receipt(receipt)
print(response.detections)
# [{'label': 'total', 'value': '157.00', 'confidence': '0.968395300'} ...]
```
### Scan Invoice
#### Preconditions
- Accurate results only provided for Norwegian invoices
```python
from las import Client, Invoice
api_key = '...'
client = Client(api_key)
# With URL
invoice = Invoice(url='https://example.com/img.jpeg')
# With file object
with open('img.jpeg', 'rb') as fp:
invoice = Invoice(fp=fp)
# With filename
invoice = Invoice(filename='img.jpeg')
response = client.scan_invoice(invoice)
print(response.detections)
# [{'label': 'total_amount', 'value': '256.00', 'confidence': '0.98485885'} ...]
```
### Match Receipts
#### Preconditions
- The number of receipts per request is limited to 15
- The number of transactions per request is limited to 100
- The 'date' field must be on ISO 8601 yyyy-mm-dd form
```python
from las import Client, Receipt
api_key = '...'
client = Client(api_key)
transactions = {
'transaction_1': {'total': '100.00', 'date': '2017-08-21'},
'transaction_2': {'total': '340.90', 'date': '2016-03-08'},
'transaction_3': {'total': '90.37', 'date': '2017-02-17'}
}
receipts = {
'receipt_1': Receipt(url='https://example.com/receipt1.jpeg'),
'receipt_2': Receipt(url='https://example.com/receipt2.jpeg'),
'receipt_3': Receipt(filename='receipt3.jpeg')
}
matching_fields = [
'total',
'date'
]
# Optionally specify a matching strategy for respective fields.
matching_strategy = {
'total': {
'maximumDeviation': 5.0, # Total amount might differ up to 5.0
'maximum': 1000.00 # Total amount cannot be larger than 1000.00
},
'date': {
'maximumDeviation': 2, # Date might differ up to 2 days
'minimum': '2017-10-23', # Date must be minimum 2017-10-23
'maximum': '2017-12-23' # Date must be maximum 2017-12-23
}
}
response = client.match_receipts(
transactions=transactions,
receipts=receipts,
matching_fields=matching_fields,
matching_strategy=matching_strategy
)
print(response.matched_transactions)
# {'transaction_1': 'receipt_2', 'transaction_3': 'receipt_1'}
print(response.unmatched_transactions)
# ['transaction_2']
```
## Documentation
[Link to docs](https://docs.lucidtech.ai/python/index.html)
## Installation
```bash
$ pip install lucidtech-las
```
## Usage
### Preconditions
- Documents must be in upright position
- Only one receipt or invoice per document is supported
- Supported file formats are: jpeg, png, gif, bmp, pdf
### Scan Receipt
```python
from las import Client, Receipt
api_key = '...'
client = Client(api_key)
# With URL
receipt = Receipt(url='https://example.com/img.jpeg')
# With file object
with open('img.jpeg', 'rb') as fp:
receipt = Receipt(fp=fp)
# With filename
receipt = Receipt(filename='img.jpeg')
response = client.scan_receipt(receipt)
print(response.detections)
# [{'label': 'total', 'value': '157.00', 'confidence': '0.968395300'} ...]
```
### Scan Invoice
#### Preconditions
- Accurate results only provided for Norwegian invoices
```python
from las import Client, Invoice
api_key = '...'
client = Client(api_key)
# With URL
invoice = Invoice(url='https://example.com/img.jpeg')
# With file object
with open('img.jpeg', 'rb') as fp:
invoice = Invoice(fp=fp)
# With filename
invoice = Invoice(filename='img.jpeg')
response = client.scan_invoice(invoice)
print(response.detections)
# [{'label': 'total_amount', 'value': '256.00', 'confidence': '0.98485885'} ...]
```
### Match Receipts
#### Preconditions
- The number of receipts per request is limited to 15
- The number of transactions per request is limited to 100
- The 'date' field must be on ISO 8601 yyyy-mm-dd form
```python
from las import Client, Receipt
api_key = '...'
client = Client(api_key)
transactions = {
'transaction_1': {'total': '100.00', 'date': '2017-08-21'},
'transaction_2': {'total': '340.90', 'date': '2016-03-08'},
'transaction_3': {'total': '90.37', 'date': '2017-02-17'}
}
receipts = {
'receipt_1': Receipt(url='https://example.com/receipt1.jpeg'),
'receipt_2': Receipt(url='https://example.com/receipt2.jpeg'),
'receipt_3': Receipt(filename='receipt3.jpeg')
}
matching_fields = [
'total',
'date'
]
# Optionally specify a matching strategy for respective fields.
matching_strategy = {
'total': {
'maximumDeviation': 5.0, # Total amount might differ up to 5.0
'maximum': 1000.00 # Total amount cannot be larger than 1000.00
},
'date': {
'maximumDeviation': 2, # Date might differ up to 2 days
'minimum': '2017-10-23', # Date must be minimum 2017-10-23
'maximum': '2017-12-23' # Date must be maximum 2017-12-23
}
}
response = client.match_receipts(
transactions=transactions,
receipts=receipts,
matching_fields=matching_fields,
matching_strategy=matching_strategy
)
print(response.matched_transactions)
# {'transaction_1': 'receipt_2', 'transaction_3': 'receipt_1'}
print(response.unmatched_transactions)
# ['transaction_2']
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lucidtech-las-0.1.11.tar.gz
(9.9 kB
view details)
File details
Details for the file lucidtech-las-0.1.11.tar.gz
.
File metadata
- Download URL: lucidtech-las-0.1.11.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Python-urllib/3.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6767267c78ed2cca08e3f23213a81c25b3049108a7433b1c6b676e61ff34df6d |
|
MD5 | 9234b5f97f116d4b0a8637624ca467ef |
|
BLAKE2b-256 | b63d579d2cf7cadc8c5715d0d44ee80cbacae490c8edcd5bc35f5fca0d798965 |