Mindee API Helper Library for Ruby
Quickly and easily connect to Mindee's API services using Ruby.
Requirements
The following Ruby versions are tested and supported: 2.6, 2.7, 3.0, 3.1, 3.2
Quick Start
Here's the TL;DR of getting started.
First, get an API Key
Install by adding this line to your application's Gemfile:
gem 'mindee'
And then execute:
bundle install
Finally, Ruby away!
Environment Variables
This library offers customizable features through environment variables. While there may be instances where you need to rely on them, it's crucial to exercise caution when modifying them to avoid unintended consequences.
If you're unsure whether you need to adjust these variables, it's advisable to refrain from doing so unless you have a specific reason. Accidentally overwriting them can lead to unexpected behavior.
Before making any changes, we recommend reviewing the following information to understand the purpose and potential impact of each environment variable:
-
MINDEE_API_KEY
:- Description: Your personal Mindee API Key as shown on the platform. Be careful not to show this publicly!
-
Default Value:
nil
-
MINDEE_BASE_URL
:- Description: The default base URL of the API endpoint. Use this variable to specify the root URL for API requests. Modify as needed for proxy configurations or changes in API endpoint location.
-
Default Value:
https://api.mindee.net/v1
-
MINDEE_REQUEST_TIMEOUT
:- Description: The default timeout for HTTP requests (in seconds).
-
Default Value:
120
Loading a File and Parsing It
Global Documents
require 'mindee'
# Init a new client
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
# Load a file from disk
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
result = mindee_client.parse(
input_source,
Mindee::Product::Invoice::InvoiceV4
)
# Print a full summary of the parsed data in RST format
puts result.document
Note: Files can also be loaded from:
A URL (https
):
input_source = mindee_client.source_from_url("https://my-url")
A bytes input stream:
input_source = mindee_client.source_from_bytes('/path/to/the/file.ext', "name-of-my-file.ext")
A base64 encoded string:
input_source = mindee_client.source_from_b64string('/path/to/the/file.ext', "name-of-my-file.ext")
A ruby file
object:
input_source = mindee_client.source_from_file(input_file, "name-of-my-file.ext")
Region-Specific Documents
require 'mindee'
# Init a new client
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
# Load a file from disk
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
result = mindee_client.parse(
input_source,
Mindee::Product::EU::LicensePlate::LicensePlateV1
)
# Print a full summary of the parsed data in RST format
puts result.document
Custom Documents (docTI & Custom APIs)
require 'mindee'
# Init a new client and configure your custom document
mindee_client = Mindee::Client.new(api_key: 'my-api-key')
endpoint = mindee_client.create_endpoint(
endpoint_name: 'my-endpoint',
account_name: 'my-account'
)
# Load a file from disk
input_source = mindee_client.source_from_path('/path/to/the/file.ext')
result = mindee_client.enqueue_and_parse(
input_source,
Mindee::Product::Generated::GeneratedV1,
endpoint: endpoint
)
# Print a full summary of the parsed data in RST format
puts result.document
# Looping over all prediction values
result.document.inference.prediction.fields.each do |field_name, field_data|
puts field_name
puts field_data.values
puts field_data.to_s
end
CLI Tool
A command-line interface tool is available to quickly test documents:
ruby ./bin/mindee.rb invoice path/to/your/file.ext
Using the ruby bundler:
bundle exec ruby ./bin/mindee.rb invoice path/to/your/file.ext
Further Reading
There's more to it than that for those that need more features, or want to customize the experience.
- Ruby Overview
- Custom OCR Ruby (Deprecated)
- Generated API Ruby
- Invoice OCR Ruby
- International Id OCR Ruby
- Financial Document OCR Ruby
- Passport OCR Ruby
- Proof of Address OCR Ruby
- Receipt OCR Ruby
- Resume OCR Ruby
- EU License Plate OCR Ruby
- EU Driver License OCR Ruby
- FR Bank Account Details OCR Ruby
- FR Bank Statement OCR Ruby
- FR Health Card OCR Ruby
- FR ID Card OCR Ruby
- US Bank Check OCR Ruby
- US Driver License OCR Ruby
- US W9 API Ruby
- Barcode Reader API Ruby
- Cropper API Ruby
- Invoice Splitter API Ruby
- Multi Receipts Detector API Ruby
You can also take a look at the Reference Documentation.
License
Copyright © Mindee, SA
Available as open source under the terms of the MIT License.