How to Extract Tables in Images / PDF with Python in 5min?
Tags: tableextraction, python, ai, api
Published: 2023-01-11 13:34:25

_In this tutorial, you will learn how to use OCR Table API in 5 minutes using Python and Eden AI OCR Table API. Eden AI provides an easy and developer-friendly API that allows you to extract tables in your files._

## **What is OCR Table API?**

Table OCR lets you extract tabular data from PDFs and images in one shot. It uses a combination of [Optical Character Recognition (OCR)](https://www.edenai.co/technologies/ocr-document-parsing?referral=how-to-extract-tables-python) and machine learning models that allow you to select and extract whole tables from images for later analysis, making it a valuable tool for businesses that handle large volumes of documents. Other document types like [receipts](https://www.edenai.co/feature/ocr-receipt?referral=how-to-extract-tables-python), [invoices](https://www.edenai.co/feature/ocr-invoice?referral=how-to-extract-tables-python), [resumes](https://www.edenai.co/feature/ocr-resume?referral=how-to-extract-tables-python), IDs, etc., also follow the same layout and benefit from Table OCR's capabilities.

## **Getting Started with OCR and Table Extraction API**

The first step to getting started with OCR Table is to install Python's requests package, that will allow you to call Eden AI API.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7ys4r4t7siqgpipuxmyo.png)

Next, you'll need to install Python's JSON package to be able to read and print the result of the API request.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tih4xe48vxw12p4luh9u.png)

## **How to extract table in a PDF or an image with Python**

You are now ready to process your file into Eden AI OCR Table API. You can process files in .pdf, .jpg, .png or .jpeg and [documents in many languages](https://docs.edenai.co/reference/audio_speech_to_text_async_create?referral=how-to-extract-tables-python).


### **1. Get an OCR Table API Key on Eden AI**

To perform OCR Table, you'll need to create an account on [Eden AI](https://app.edenai.run/user/register?referral=how-to-extract-tables-python) for free. Then, you will be able to get your **API key** direclty from the homepage with free credits offered by Eden AI.

![Eden AI platform - Get your API key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2v3htcmq397l3gwum9jw.png)

**[Get your API for FREE](https://app.edenai.run/user/register?referral=how-to-extract-tables-python)**

### **2. Let’s Extract Tables with OCR**

Now that you have imported packages on Python and got your API key, you will be able to extract text in your file. With Eden AI, you can choose from a wide range of different engines you want for OCR Table. You can see OCR Table providers available on Eden AI on our documentation [here](https://docs.edenai.co/reference/ocr_ocr_tables_async_create?referral=how-to-extract-tables-python).

Here is the Python script you need to write on your notebook:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3x4yh1scfsde8ics0sjg.png)
For example, we called two different OCR Table engines. Eden AI API will then return in its JSON response results of those providers.

Eden AI OCR Table API is an asynchronous API. It means that you will get in response an ID:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d3gj7d5hoa4u4rzosh81.png)
Then you will need to perform a GET request to check the status of the API request (success, processing, failed):
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ninf2lyy5q74c11m0jae.png)
You will first get this response:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kdxe95mf2rspuveuqitc.png)
Once the request is done (status : finished), you will be able to get the result with this print:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tf1u5piig4spbeicndlj.png)
Here is an example of a result for OCR Table task:
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tt1juyq84hrxmhxxbfkl.png)

## Benefits of using OCR Table API with Eden AI
Using Table Extraction with Eden AI API is quick and easy.

![Multiple AIs in one API - Eden AI](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/58tk12fgupcc50u8rh19.gif)
### Save time and cost

We offer a unified API for all providers: simple and standard to use, with a quick switch between providers and an access to the specificic features of each provider

### Easy to integrate

The JSON output format is the same for all suppliers thanks to Eden AI's standardisation work. The response elements are also standardised thanks to Eden AI's powerful matching algorithms.

### Customization

With Eden AI you have the possibility to integrate a third party platform: we can quickly develop connectors. To go further and customize your OCR Table request with specific parameters, check out our [documentation](https://docs.edenai.co/reference/ocr_ocr_tables_async_create?referral=how-to-extract-tables-python).

**[Create your Account on Eden AI](https://app.edenai.run/user/register?referral=how-to-extract-tables-python)**