NuMind SDK
Python SDK to interact with NuMind's models API: NuExtract and NuMarkdown.
Installation
pip install numind
Usage and code examples
Create a client
You must first get an API key on the NuExtract platform.
import os
from numind import NuMind
# Create a client object to interact with the API
# Providing the `api_key` is not required if the `NUMIND_API_KEY` environment variable
# is already set.
client = NuMind(api_key=os.environ["NUMIND_API_KEY"])
You can create an async client by using the NuMindAsync class.
The methods and their usages are the same as for the sync NuMind client.
Extract structured data
If you want to extract structured information without a project, provide the template directly to extract_structured_data:
template = {
"destination": {
"name": "verbatim-string",
"zip_code": "string",
"country": "country",
},
"accommodation": "verbatim-string",
"activities": ["verbatim-string"],
"duration": "duration",
}
input_file_path = Path("to", "file.pdf")
response = client.extract_structured_data(
template=template,
input_file=input_file_path,
)
print(response.result)
{
"destination": {
"name": "Tahiti",
"zip_code": "98730",
"country": "FR"
},
"accommodation": "overwater bungalow in Bora Bora",
"activities": [
"snorkeling",
"paddleboarding",
"basking",
"explore lush rainforests, hidden waterfalls, and the rich Polynesian culture"
],
"duration": null
}
Create a good template
NuExtract uses JSON extraction templates which specify the information to retrieve and their types:
- string: a text, whose value can be abstract, i.e. totally free and can be deduced from calculations, reasoning, external knowledge;
- verbatim-string: a purely extractive text whose value must be present in the document. Some flexibility might be allowed on the formatting, e.g. new lines and escaped characters (e.g.
\n) in a documents might be represented with a space; - integer: an integer number;
- number: any number, that may be a floating point number or an integer;
- boolean: a boolean whose value should be either true or false;
- date-time: a date or time whose value should follow the ISO 8601 standard (
YYYY-MM-DDThh:mm:ss). It may feature "reduced" accuracy, i.e. omitting certain date or time components not useful in specific cases. For examples, if the extracted value is a date,YYYY-MM-DDis a valid value format. The same applies to times with thehh:mm:ssformat (without omitting the leadingTsymbol). Additionally, the "least significant" component might be omitted if it is not required or specified. For example, a specific month and year can be specified asYYYY-MMwhile omitting the day componentDD. A specific hour can be specified ashhwhile omitting the minutes and seconds components. When combining dates and time, only the least significant time components can be omitted, e.g.YYYY-MM-DDThh:mmwhich is omitting the seconds.
Additionally, the value of a field can be:
- a nested dictionary, i.e. another branch, describing elements associated to their parent node (key);
- an array of items of the form
["type"], whose values are elements of a given "type", which can also be a dictionary of unspecified depth; - an enum, i.e. a list of elements to choose from of the form
["choice1", "choice2", ...]. For values of this type, just set the value of the item to choose, e.g. "choice1", and do not set the value as an array containing the item such as["choice1"]; - a multi-enum, i.e. a list from which multiple elements can be picked, of the form
[["choice1", "choice2", ...]](double square brackets).
Converting JSON schema / Pydantic models to NuExtract template
The SDK offers a method to convert JSON schemas to NuExtract templates:
from typing import Literal
from pydantic import Field, BaseModel
from numind.nuextract_utils import convert_json_schema_to_nuextract_template
class HotelBooking(BaseModel):
city: str
check_in_date: str = Field(description="date")
check_out_date: str = Field(description="date")
number_of_guests: int
room_type: Literal["single", "double", "suite"]
conversion = convert_json_schema_to_nuextract_template(
HotelBooking.model_json_schema(),
)
template = conversion["template"]
incompatibilities = conversion["incompatibilities"]
# {'check_in_date': 'date', 'check_out_date': 'date', 'city': 'string', 'number_of_guests': 'integer', 'room_type': ['single', 'double', 'suite']}
When an instance is provided, instance_status reports whether it is valid for
both the source JSON Schema and converted template. adapted_instance contains the
original value or a deterministically corrected value only when it is valid for both;
otherwise it is None, and incompatibilities identifies the affected locations.
Inferring a template
Template generation is asynchronous. Submit a natural-language description, poll the job status, and retrieve the generated template once complete.
import time
from numind.models import TemplateRequest
description = "Create a template that extracts key information from an order confirmation email. The template should be able to pull details like the order ID, customer ID, date and time of the order, status, total amount, currency, item details (product ID, quantity, and unit price), shipping address, any customer requests or delivery preferences, and the estimated delivery date."
job_id = client.post_api_template_generation_jobs_text(
TemplateRequest(description=description)
).job_id
job_status = client.get_api_jobs_jobid_status(job_id)
while job_status.completed_at is None:
time.sleep(4)
job_status = client.get_api_jobs_jobid_status(job_id)
if job_status.status != "completed":
raise RuntimeError(f"Template generation failed with status {job_status.status}")
template = client.get_api_template_generation_jobs_templatejobid(job_id).result
Create a project
A project allows to define an information extraction task from a template and examples.
from numind.models import CreateStructuredProjectRequest
project_id = client.post_api_structured_extraction(
CreateStructuredProjectRequest(
name="vacation",
description="Extraction of locations and activities",
template=template,
instructions="",
)
).id
The project_id can also be found in the "API" tab of a project on the NuExtract website.
Add examples to a project to teach NuExtract via ICL (In-Context Learning)
from pathlib import Path
# Prepare examples, here a text and a file
example_1_input = "This is a text example"
example_1_expected_output = {
"destination": {"name": None, "zip_code": None, "country": None}
}
example_2_input = Path("example_2.odt")
example_2_expected_output = {
"destination": {"name": None, "zip_code": None, "country": None}
}
examples = [
(example_1_input, example_1_expected_output),
(example_2_input, example_2_expected_output),
]
# Add the examples to the project
client.add_examples_to_structured_extraction_project(project_id, examples)
Convert a document to a RAG-ready Markdown
from pathlib import Path
file_path = Path("document.pdf")
response = client.extract_content(file_path, job_status_polling_delay=2.0)
print(response.result)
extract_structured_data and extract_content poll job status every four seconds by
default. Use job_status_polling_delay to select a different interval in seconds.
Failed jobs raise RuntimeError by default. Set raise_on_job_fail=False to return a
FailedJobStatusResponse containing the complete job status and its failure reason.
Documentation
Extracting Information from Documents
Once your structured extraction project is ready, submit a document to the endpoint:
https://nuextract.ai/api/structured-extraction/{structuredProjectId}/jobs
To use it, you need:
- To create an API key in the Account section
- To replace
{structuredProjectId}by the project ID found in the API tab of the structured extraction project
This endpoint creates an asynchronous extraction job. Use the returned jobId to retrieve the result from:
https://nuextract.ai/api/structured-extraction/jobs/{structuredExtractionJobId}
You can test your extraction endpoint in your terminal using this command-line example with curl (make sure that you replace values of STRUCTURED_PROJECT_ID and NUEXTRACT_API_KEY):
NUEXTRACT_API_KEY=\"_your_api_key_here_\"; \\
STRUCTURED_PROJECT_ID=\"a24fd84a-44ab-4fd4-95a9-bebd46e4768b\"; \\
JOB_ID=$(curl \"https://nuextract.ai/api/structured-extraction/${STRUCTURED_PROJECT_ID}/jobs\" \\
-X POST \\
-H \"Authorization: Bearer ${NUEXTRACT_API_KEY}\" \\
-F \"file=@${FILE_NAME}\" | jq -r '.jobId')
curl \"https://nuextract.ai/api/structured-extraction/jobs/${JOB_ID}\" \\
-H \"Authorization: Bearer ${NUEXTRACT_API_KEY}\"
You can also use the Python SDK, by replacing the
project_id, api_key and request values in the following code:
import asyncio
from numind import NuMindAsync
client = NuMindAsync(api_key=api_key)
requests = [{}]
async def main():
return [
await client.extract_structured_data(project_id, **request_kwargs)
for request_kwargs in requests
]
responses = asyncio.run(main())
Using the Platform via API
Everything you can do on the web platform can be done via API - check the user guide to learn about how the platform works. This can be useful to create projects automatically, or to make your production more robust for example.
Main resources
- Structured Extraction Project - user project for structured extraction, identified by
structuredProjectId - Content Extraction Project - user project for content extraction, identified by
contentProjectId - File - uploaded file, identified by
fileId, stored up to two weeks if not tied to an Example - Document - internal representation of a document, identified by
documentId, created from a File, stored up to two weeks if not tied to an Example - Example - document-extraction pair given to teach NuExtract, identified by
structuredExampleId, created from a Document - Job - asynchronous extraction task, identified by
structuredExtractionJobId
Most common API operations
Structured extraction
- Creating a Structured Extraction Project via
POST /api/structured-extraction - Changing the template of a Structured Extraction Project via
PATCH /api/structured-extraction/{structuredProjectId} - Changing settings of a Structured Extraction Project via
PATCH /api/structured-extraction/{structuredProjectId}/settings - Uploading a file to a File via
POST /api/files(up to 2 weeks storage) - Starting a structured extraction Job via
POST /api/structured-extraction/{structuredProjectId}/jobs - Reading a structured extraction Job result via
GET /api/structured-extraction/jobs/{structuredExtractionJobId} - Adding an Example to a Structured Extraction Project via
POST /api/structured-extraction/{structuredProjectId}/examples
Content extraction
- Creating a Content Extraction Project via
POST /api/content-extraction - Changing settings of a Content Extraction Project via
PATCH /api/content-extraction/{contentProjectId}/settings - Uploading a file to a File via
POST /api/files(up to 2 weeks storage) - Starting a content extraction Job via
POST /api/content-extraction/jobs - Reading a content extraction Job result via
GET /api/content-extraction/jobs/{contentExtractionJobId}
This Python package is automatically generated by the OpenAPI Generator project:
- API version:
- Package version: 1.0.0
- Generator version: 7.25.0
- Build package: org.openapitools.codegen.languages.PythonClientCodegen
Documentation for API Endpoints
All URIs are relative to https://nuextract.ai
| Class | Method | HTTP request | Description |
|---|---|---|---|
| ContentExtractionApi | get_api_content_extraction_jobs_contentextractionjobid | GET /api/content-extraction/jobs/{contentExtractionJobId} | |
| ContentExtractionApi | post_api_content_extraction_jobs | POST /api/content-extraction/jobs | |
| ContentExtractionProjectManagementApi | delete_api_content_extraction_contentprojectid | DELETE /api/content-extraction/{contentProjectId} | |
| ContentExtractionProjectManagementApi | get_api_content_extraction | GET /api/content-extraction | |
| ContentExtractionProjectManagementApi | patch_api_content_extraction_contentprojectid | PATCH /api/content-extraction/{contentProjectId} | |
| ContentExtractionProjectManagementApi | patch_api_content_extraction_contentprojectid_settings | PATCH /api/content-extraction/{contentProjectId}/settings | |
| ContentExtractionProjectManagementApi | post_api_content_extraction | POST /api/content-extraction | |
| ContentExtractionProjectManagementApi | post_api_content_extraction_contentprojectid_reset_settings | POST /api/content-extraction/{contentProjectId}/reset-settings | |
| DefaultApi | get_api_debug_status_code | GET /api/debug/status/{code} | |
| DefaultApi | get_api_health | GET /api/health | |
| DefaultApi | get_api_inference_status | GET /api/inference-status | |
| DefaultApi | get_api_ping | GET /api/ping | |
| DefaultApi | get_api_version | GET /api/version | |
| DocumentsApi | get_api_documents_documentid | GET /api/documents/{documentId} | |
| DocumentsApi | get_api_documents_documentid_parts_partindex_image | GET /api/documents/{documentId}/parts/{partIndex}/image | |
| DocumentsApi | post_api_documents_documentid_new_owner | POST /api/documents/{documentId}/new-owner | |
| DocumentsApi | post_api_documents_text | POST /api/documents/text | |
| FilesApi | get_api_files_fileid | GET /api/files/{fileId} | |
| FilesApi | get_api_files_fileid_content | GET /api/files/{fileId}/content | |
| FilesApi | post_api_files | POST /api/files | |
| FilesApi | post_api_files_fileid_convert_to_document | POST /api/files/{fileId}/convert-to-document | |
| InferenceApi | post_api_content_extraction_contentprojectid_jobs_document_documentid | POST /api/content-extraction/{contentProjectId}/jobs/document/{documentId} | |
| InferenceApi | post_api_structured_extraction_structuredprojectid_jobs_document_documentid | POST /api/structured-extraction/{structuredProjectId}/jobs/document/{documentId} | |
| InferenceApi | post_api_template_generation_jobs_document_documentid | POST /api/template-generation/jobs/document/{documentId} | |
| JobsApi | get_api_jobs | GET /api/jobs | |
| JobsApi | get_api_jobs_jobid_status | GET /api/jobs/{jobId}/status | |
| JobsApi | get_api_jobs_jobid_stream | GET /api/jobs/{jobId}/stream | |
| JobsApi | post_api_jobs_jobid_cancel | POST /api/jobs/{jobId}/cancel | |
| ProjectImportExportApi | get_api_extraction_projectkind_projectid_export | GET /api/extraction/{projectKind}/{projectId}/export | |
| ProjectImportExportApi | post_api_extraction_import | POST /api/extraction/import | |
| StructuredDataExtractionApi | get_api_structured_extraction_jobs_structuredextractionjobid | GET /api/structured-extraction/jobs/{structuredExtractionJobId} | |
| StructuredDataExtractionApi | post_api_structured_extraction_jobs | POST /api/structured-extraction/jobs | |
| StructuredDataExtractionApi | post_api_structured_extraction_structuredprojectid_jobs | POST /api/structured-extraction/{structuredProjectId}/jobs | |
| StructuredDataExtractionApi | post_api_structured_extraction_structuredprojectid_jobs_text | POST /api/structured-extraction/{structuredProjectId}/jobs/text | |
| StructuredExtractionExamplesApi | delete_api_structured_extraction_structuredprojectid_examples_structuredexampleid | DELETE /api/structured-extraction/{structuredProjectId}/examples/{structuredExampleId} | |
| StructuredExtractionExamplesApi | get_api_structured_extraction_structuredprojectid_examples | GET /api/structured-extraction/{structuredProjectId}/examples | |
| StructuredExtractionExamplesApi | get_api_structured_extraction_structuredprojectid_examples_structuredexampleid | GET /api/structured-extraction/{structuredProjectId}/examples/{structuredExampleId} | |
| StructuredExtractionExamplesApi | post_api_structured_extraction_structuredprojectid_examples | POST /api/structured-extraction/{structuredProjectId}/examples | |
| StructuredExtractionExamplesApi | put_api_structured_extraction_structuredprojectid_examples_structuredexampleid | PUT /api/structured-extraction/{structuredProjectId}/examples/{structuredExampleId} | |
| StructuredExtractionProjectManagementApi | delete_api_structured_extraction_structuredprojectid | DELETE /api/structured-extraction/{structuredProjectId} | |
| StructuredExtractionProjectManagementApi | get_api_structured_extraction | GET /api/structured-extraction | |
| StructuredExtractionProjectManagementApi | get_api_structured_extraction_structuredprojectid | GET /api/structured-extraction/{structuredProjectId} | |
| StructuredExtractionProjectManagementApi | get_api_structured_extraction_structuredprojectid_thumbnail | GET /api/structured-extraction/{structuredProjectId}/thumbnail | |
| StructuredExtractionProjectManagementApi | patch_api_structured_extraction_structuredprojectid | PATCH /api/structured-extraction/{structuredProjectId} | |
| StructuredExtractionProjectManagementApi | patch_api_structured_extraction_structuredprojectid_settings | PATCH /api/structured-extraction/{structuredProjectId}/settings | |
| StructuredExtractionProjectManagementApi | post_api_structured_extraction | POST /api/structured-extraction | |
| StructuredExtractionProjectManagementApi | post_api_structured_extraction_structuredprojectid_duplicate | POST /api/structured-extraction/{structuredProjectId}/duplicate | |
| StructuredExtractionProjectManagementApi | post_api_structured_extraction_structuredprojectid_lock | POST /api/structured-extraction/{structuredProjectId}/lock | |
| StructuredExtractionProjectManagementApi | post_api_structured_extraction_structuredprojectid_reset_settings | POST /api/structured-extraction/{structuredProjectId}/reset-settings | |
| StructuredExtractionProjectManagementApi | post_api_structured_extraction_structuredprojectid_share | POST /api/structured-extraction/{structuredProjectId}/share | |
| StructuredExtractionProjectManagementApi | post_api_structured_extraction_structuredprojectid_unlock | POST /api/structured-extraction/{structuredProjectId}/unlock | |
| StructuredExtractionProjectManagementApi | post_api_structured_extraction_structuredprojectid_unshare | POST /api/structured-extraction/{structuredProjectId}/unshare | |
| TemplateGenerationApi | get_api_template_generation_jobs_templatejobid | GET /api/template-generation/jobs/{templateJobId} | |
| TemplateGenerationApi | post_api_template_generation_jobs | POST /api/template-generation/jobs | |
| TemplateGenerationApi | post_api_template_generation_jobs_text | POST /api/template-generation/jobs/text |
Documentation For Models
- Content
- ContentExtractionResponse
- ContentProjectResponse
- ContentProjectSettingsResponse
- ConvertRequest
- CreateContentProjectRequest
- CreateOrUpdateStructuredExampleRequest
- CreateStructuredProjectRequest
- DocumentInfo
- DocumentResponse
- Error
- FileResponse
- HealthResponse
- ImageInfo
- ImportProjectResponse
- InferenceStatus
- InferenceValidationError
- InformationResponse
- InvalidInformation
- JobIdResponse
- JobStatusResponse
- PaginatedResponseT
- ServiceStatus
- Structured
- StructuredExampleResponse
- StructuredExtractionResponse
- StructuredInferenceExample
- StructuredProjectResponse
- StructuredProjectSettingsResponse
- TemplateRequest
- TemplateResponse
- TextInfo
- TextRequest
- UpdateContentProjectRequest
- UpdateContentProjectSettingsRequest
- UpdateStructuredProjectRequest
- UpdateStructuredProjectSettingsRequest
- ValidInformation
- VersionResponse
Documentation For Authorization
Authentication schemes defined for the API:
oauth2Auth
- Type: OAuth
- Flow: accessCode
- Authorization URL: https://users.numind.ai/realms/extract-platform/protocol/openid-connect/auth
- Scopes:
- openid: OpenID connect
- profile: view profile
- email: view email
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file numind-0.4.0.tar.gz.
File metadata
- Download URL: numind-0.4.0.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a81d906a70f54e5d8a4918d923a5bff1969fbbf513540bc8398a91229fcab8bd
|
|
| MD5 |
d7968ed02c26c9fdd2efbe0b9bcad01b
|
|
| BLAKE2b-256 |
ca5b4adac9307997f15be3c446b2a2044fc13ed41059591a62eba921ca06489d
|
Provenance
The following attestation bundles were made for numind-0.4.0.tar.gz:
Publisher:
publish-pypi.yml on numindai/nuextract-platform-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
numind-0.4.0.tar.gz -
Subject digest:
a81d906a70f54e5d8a4918d923a5bff1969fbbf513540bc8398a91229fcab8bd - Sigstore transparency entry: 2757471202
- Sigstore integration time:
-
Permalink:
numindai/nuextract-platform-sdk@3ac8908c49224c667c576132c2b9414504908642 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/numindai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3ac8908c49224c667c576132c2b9414504908642 -
Trigger Event:
release
-
Statement type:
File details
Details for the file numind-0.4.0-py3-none-any.whl.
File metadata
- Download URL: numind-0.4.0-py3-none-any.whl
- Upload date:
- Size: 932.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
528121ad700c460b80cceb572efabe5f4af0e0dc64fe4800ab75656a2c9d07ed
|
|
| MD5 |
9d9338122a75aa271cd473e0cb5bbed0
|
|
| BLAKE2b-256 |
d1637ab6749716eb06173d2f18fa3bdae6ce223187530452688320c04741878b
|
Provenance
The following attestation bundles were made for numind-0.4.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on numindai/nuextract-platform-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
numind-0.4.0-py3-none-any.whl -
Subject digest:
528121ad700c460b80cceb572efabe5f4af0e0dc64fe4800ab75656a2c9d07ed - Sigstore transparency entry: 2757471267
- Sigstore integration time:
-
Permalink:
numindai/nuextract-platform-sdk@3ac8908c49224c667c576132c2b9414504908642 -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/numindai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3ac8908c49224c667c576132c2b9414504908642 -
Trigger Event:
release
-
Statement type: