Giter Site home page Giter Site logo

mindee-api-ruby's Introduction

License: MIT GitHub Workflow Status Gem Version Downloads

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 Document (API Builder)

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.parse(
  input_source,
  Mindee::Product::Custom::CustomV1,
  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.

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.

Questions?

Join our Slack

mindee-api-ruby's People

Contributors

ianardee avatar sebastianmindee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

oriolgual

mindee-api-ruby's Issues

Warning `already initialized constant MRZ::TD3Parser::FORMAT_ONE`

Hi there,

I juste add mindee gem to my Rails app, and I got those warnings when launching a console

/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/mindee-2.1.0/lib/mindee/parsing/prediction/passport/passport_v1.rb:15: warning: already initialized constant MRZ::TD3Parser::FORMAT_ONE
/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/mrz-0.2.0/lib/mrz/td3_parser.rb:3: warning: previous definition of FORMAT_ONE was here

Any idea on how to solve this ?
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.