Skip to main content

UiForm official python library

Project description

uiform

UiForm Logo

The universal document processing API

Made with love by the team at UiForm.

Discord | UiForm website | Twitter

pip install uiform

First time here? Go to our quickstart guide


We currently support OpenAI, Anthropic, Gemini and xAI models.

You come with your own API key from your favorite AI provider, and we handle the rest.


UiForm is a modern, flexible, and AI-native document processing API that helps you:

  • Add AI-defined document processing capabilities to your app
  • Create prompts from JSON schemas and Pydantic models with zero boilerplate
  • Create annotated datasets to distill or finetune your models

We see it as building Stripe for document processing.

Our goal is to make the process of analyzing documents and unstructured data as easy and transparent as possible.

Many people haven't yet realized how powerful LLMs have become at document processing tasks - we're here to help unlock these capabilities.

Quickstart

Setup of the Python SDK

To get started, install the uiform package using pip:

pip install uiform

Then, create your API key on uiform.com and populate your env variables with your API keys:

OPENAI_API_KEY=YOUR-API-KEY # Your AI provider API key. Compatible with OpenAI, Anthropic, xAI.
UIFORM_API_KEY=sk_xxxxxxxxx # Create your API key on https://www.uiform.com

Summarize a document

Use the UiForm client to convert your documents into messages and use your favorite model to analyze your document:

from uiform import UiForm
from openai import OpenAI

uiclient = UiForm()
doc_msg = uiclient.documents.create_messages(
    document = "freight/booking_confirmation.jpg"
)

# Now you can use your favorite model to analyze your document
client = OpenAI()
completion = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=doc_msg.openai_messages + [
        {
            "role": "user",
            "content": "Summarize the document"
        }
    ]
)

Load a schema and extract data from a document

We use a standard JSON Schema with custom annotations (X-SystemPrompt, X-LLMDescription, and X-ReasoningDescription) as a prompt-engineering framework for the extraction process.

These annotations help guide the LLM's behavior and improve extraction accuracy. You can learn more about these in our JSON Schema documentation.

from uiform import UiForm
from openai import OpenAI
from pydantic import BaseModel, Field, ConfigDict

uiclient = UiForm()
doc_msg = uiclient.documents.create_messages(
    document = "document_1.xlsx"
)

class CalendarEvent(BaseModel):
    model_config = ConfigDict(json_schema_extra = {"X-SystemPrompt": "You are a useful assistant."})

    name: str = Field(...,
        description="The name of the calendar event.",
        json_schema_extra={"X-LLMDescription": "Provide a descriptive and concise name for the event."}
    )
    date: str = Field(...,
        description="The date of the calendar event in ISO 8601 format.",
        json_schema_extra={
            'X-ReasoningDescription': 'The user can mention it in any format, like **next week** or **tomorrow**. Infer the right date format from the user input.',
        }
    )

print("Equivalent JSON Schema:",CalendarEvent.model_json_schema())

schema_obj =Schema(
    pydantic_model = CalendarEvent
)

# Now you can use your favorite model to analyze your document
client = OpenAI()
completion = client.beta.chat.completions.parse(
    model="gpt-4o",
    messages=schema_obj.openai_messages + doc_msg.openai_messages,
    response_format=schema_obj.response_format_pydantic
)
print("Extracted data with the reasoning fields:", completion.choices[0].message.content)

# Validate the response against the original schema if you want to remove the reasoning fields
assert completion.choices[0].message.content is not None
extraction = schema_obj.pydantic_model.model_validate_json(
    completion.choices[0].message.content 
)

print("Extracted data without the reasoning fields:", extraction)

And that's it ! You can start processing documents at scale ! You have 1000 free requests to get started, and you can subscribe to the pro plan to get more.

But this minimalistic example is just the beginning. Continue reading to learn more about how to use UiForm to its full potential.


Go further


Jupyter Notebooks

You can view minimal notebooks that demonstrate how to use UiForm to process documents:


Community

Let's create the future of document processing together!

Join our discord community to share tips, discuss best practices, and showcase what you build. Or just tweet at us.

We can't wait to see how you'll use UiForm.

Roadmap

We publicly share our Roadmap with the community on github. Please open an issue or contact us on X if you have suggestions or ideas.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uiform-0.0.3.tar.gz (45.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uiform-0.0.3-py3-none-any.whl (63.6 kB view details)

Uploaded Python 3

File details

Details for the file uiform-0.0.3.tar.gz.

File metadata

  • Download URL: uiform-0.0.3.tar.gz
  • Upload date:
  • Size: 45.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for uiform-0.0.3.tar.gz
Algorithm Hash digest
SHA256 987686fe62288dd6a3e5e8166ef129faace68745546b2528c8530cf018037bd9
MD5 0a6828751d1a9bd2e6c3913c22370d1f
BLAKE2b-256 ccebc7979fc5352db44de1c492f1ac8c0973152d6c1d16cd40640176b5690ce7

See more details on using hashes here.

File details

Details for the file uiform-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: uiform-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 63.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for uiform-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c05fe18f3975782f0c93b8d3884ed8a290bbe9efd1789b8ba4e0cd8dd41859b8
MD5 f7b81c52828f4f59a43c6839b4e1e17f
BLAKE2b-256 cb9598023c2c2a8ebcaad809704cb3f949fb440999562376b8a0d19765733a08

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page