Giter Site home page Giter Site logo

extraxt's Introduction

Extraxt

Extraxt is a Python-based MuPDF library that enables parsing and extracting data from PDF documents.

Core Functionality

  • Nested JSON Output: Constructs nested JSON objects reflecting the document's content.
  • Subtitle and Field Matching: Define subtitles and corresponding data fields in snake case (e.g. first_name, address_line_one, income_(secondary)).
  • Sensitive Data Configuration: Enables sensitive data controls and configuration via the API (Coming soon).

Extraxt streamlines the extraction process, converting PDF content into structured JSON for easy data manipulation and integration.

Installation

Install Extraxt

pip install extraxt

Upgrade to new version of Extraxt

pip install --upgrade extraxt

Using Conda with Extraxt

conda create --name [YOUR_ENV] python=3.11 -y
conda activate [YOUR_ENV]
pip install extraxt

Usage

Extraxt is able to consume either an asynchronous byte stream or a buffer directly from disk.

Before you begin:

  • Matching something like Phone (Secondary) -> phone_(secondary) will require the usage of parenthesis as of 0.0.17. This will soon be opt in, where by default the parenthesis will be redacted.
  • As of 0.0.17, sensitive data is not configurable via the API, and instead "Date of birth" is parsed as "age" only.

Read file from disk

Reading from a Buffer stream can be done using with open as is standard in Python. From there you can invoke .read() on the binary and pass your fields specification. fields accepts an object of user-input key's (subtitles), where the value is a series of matches (snaked_cased) to that of the exact PDF text content within your document.

from extraxt import Extraxt

from .config import FIELDS

extraxt = Extraxt()


def main():
    with open("file.pdf", "rb") as buffer:
        stream = buffer.read()
        output = extraxt.read(stream, FIELDS)
        print(output)


if __name__ == "__main__":
    main()

Read file in asynchronous API

FastAPI

For cases using FastAPI, Extraxt is a synchronous package and will block the main thread. To perform non-blocking/asynchronous extraction, you will need to use asyncio and Futures.

import traceback
import json

from fastapi import File, HTTPException, JSONResponse
from extraxt import Extraxt

from .util import event_loop
from .config import FIELDS

extraxt = Extraxt()


async def process_file(file: File):
    try:
        content = file.read()
        if not content:
            raise HTTPException(500, "Failed to read file.")
        content = await event_loop(extraxt.read, content, FIELDS)

    except Exception as e:
        tb = traceback.format_exc()
        raise HTTPException(500, f"Failed to triage file {tb}")

    return JSONResponse({
        "content": json.loads(content),
    })

extraxt's People

Contributors

0mjs avatar

Stargazers

 avatar

Watchers

 avatar

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.