Inkspan › Guides › How to extract tables from a PDF in Python
Getting tabular data out of a PDF is where most document pipelines break, because the usual failure is not an error — it is a plausible-looking table with a column quietly shifted. The /v1/extract/tables endpoint returns detected tables as JSON rows together with a confidence score and a review_recommended flag.
Detection first looks for ruling lines. When a table has no borders, it falls back to reconstructing structure from word coordinates, which is robust to font and rendering differences. The confidence score reflects which path succeeded and how cleanly — so you can route low-confidence documents to a human instead of writing wrong data to your database.
import requests
files = {'file': open('input.pdf', 'rb')}
r = requests.post(
'https://api.inkspan.dev/v1/extract/tables',
headers={'X-API-Key': 'ink_live_...'},
files=files,
)
r.raise_for_status()
print(r.json())
| Name | Type | Required | Description |
|---|---|---|---|
file | file | yes | The PDF to extract tables from. |
Returns application/json:
{
"table_count": 1,
"tables": [
{
"page": 1,
"rows": [
[
"Item",
"Qty",
"Price"
],
[
"Widget",
"5",
"$10"
]
]
}
],
"confidence": 0.95,
"review_recommended": false
}
review_recommended. Ignoring it is how false-certain data reaches production.| Status | Meaning | Fix |
|---|---|---|
401 | Invalid or missing API key | Send your key in the X-API-Key header. |
402 | Monthly quota exceeded | The response reports used/quota. Upgrade at inkspan.dev/#pricing. |
422 | Missing or invalid parameter | Check required fields in the table above — the body names the offending field. |
Failed requests do not count against your quota; only successful ones are metered.
It reflects how cleanly table structure was recovered — ruled tables detected directly score highest, coordinate-reconstructed tables lower. Use review_recommended as the decision boundary rather than picking your own threshold.
Yes. When no ruling lines are found, structure is reconstructed from word positions, typically with a lower confidence score.
The response is JSON rows, which map directly onto a CSV writer in a couple of lines on your side.
Get a free API key →Related Extract guides: extract text from a PDF