Skip to main content

Parse any file to Markdown and JSON

Project description

 █████╗ ███╗   ██╗██╗   ██╗██████╗  █████╗ ██████╗ ███████╗███████╗
██╔══██╗████╗  ██║╚██╗ ██╔╝██╔══██╗██╔══██╗██╔══██╗██╔════╝██╔════╝
███████║██╔██╗ ██║ ╚████╔╝ ██████╔╝███████║██████╔╝███████╗█████╗  
██╔══██║██║╚██╗██║  ╚██╔╝  ██╔═══╝ ██╔══██║██╔══██╗╚════██║██╔══╝  
██║  ██║██║ ╚████║   ██║   ██║     ██║  ██║██║  ██║███████║███████╗
╚═╝  ╚═╝╚═╝  ╚═══╝   ╚═╝   ╚═╝     ╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝

Static Badge

English | 简体中文

AnyParse

AnyParse is a powerful multimodal document parsing and understanding engine designed to seamlessly convert complex files into structured Markdown and JSON formats. Whether it's basic text processing, professional document conversion, or advanced Vision-Language Models (VLM) and OCR recognition, AnyParse provides a comprehensive, one-stop solution.

Core Capabilities

  • Multimodal Document Understanding: Supports cross-modal parsing of images and documents. By combining OCR and VLM technologies, it accurately extracts unstructured data.
  • Comprehensive Format Coverage: Easily parses office documents, web pages, spreadsheets, e-books, and emails with a single tool.
  • Structured Output: Transforms complex files into standardized Markdown and JSON, streamlining downstream data processing and Large Language Model (LLM) applications.

Key Features

  • Documents & Layouts: PDF, DOCX, PPTX, XLSX, EPUB, IPYNB
  • Text & Markup: TXT, MD, RST, HTML/XHTML/HTM/SHTML
  • Spreadsheets & Data: CSV, TSV
  • Images & Multimedia: PNG, JPEG/JPG
  • Others: EML (Emails)
  • Built-in CLI, FastAPI
  • Supports running in a pure CPU environment, and also supports GPU
  • Output text in human reading order, suitable for single-column, multi-column and complex layouts
  • Retain the original document structure, including titles, paragraphs, lists, etc.
  • Extract images, image descriptions, tables, table titles and footnotes
  • Automatically identify and convert formulas in documents to LaTeX format
  • Automatically identify and convert tables in documents to HTML format

Insduction

Installation

pip install anyparse

# or

pip install -e .

Usage

please download config/config.yaml into your project directory.

Download Models

# use modelscope (default)
export ANYPARSE_MODEL_MIRROR="modelscope"

# use huggingface
export ANYPARSE_MODEL_MIRROR="huggingface"

# download models
anyparse-cli download --config config/config.yaml --model

Models Hub

Python

# Sync
from anyparse import AnyParser

model = AnyParser(config="config/config.yaml")
res = model.invoke(file = "/path/to/your_file")



# or Async
from anyparse import AsyncAnyParser

model = AsyncAnyParser(config="config/config.yaml")
res = await model.ainvoke(file = "/path/to/your_file")

CLI

# help

anyparse-cli --help

# parse file
anyparse-cli parse --config config/config.yaml --file /path/to/your_file

# start api server
anyparse-cli api --config config/config.yaml

# see allowed file types
anyparse-cli allow --config config/config.yaml

# see commands help
anyparse-cli [COMMAND] --help

API

  • start api server
# start fastapi server and openai proxy
## use restful api or openai client call
anyparse-cli api --config config/config.yaml --host 0.0.0.0 --port 18007 --seckey 'your_custom_secret_key'
  • call api
# openai
from openai import OpenAI

client = OpenAI(
    base_url = "http://localhost:18007/anyparse/openai/v1",
    api_key = "your_custom_secret_key",
)
## get model id and allowed file types
print(client.models.list())



## parse file
import base64

with open("1.pdf", "r", encoding="utf-8") as f:
    text_content = f.read()

encoded_bytes = base64.b64encode(text_content.encode('utf-8'))
base64_str = encoded_bytes.decode('utf-8')

response = client.chat.completions.create(
    model="anyparse",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "file",
                    "file": {
                        "file_data": f"data:application/pdf;base64,{base64_str}"
                    }
                }
            ]
        }
    ],  # data:application/pdf;base64 prefix follow: client.models.list().data[0].allow_mimetypes
    # extra_body={
    #     "runtimes_args": {
    #         "use_doc_layout": True
    #     }
    # }
)

print(response.choices[0].message.content)



# or restful
import requests as rq

headers = {
    "Authorization": "Bearer your_custom_secret_key"
}

url = "http://localhost:18007/anyparse/invoke/v1"

args = {
    "use_doc_cls": False,
    "use_doc_rectifier": False,
    "use_doc_layout": True
}

file = '/path/to/your_file'

files = {
    'file': open(file,'rb')
}

res = rq.post(url, files = files, data = args, headers = headers)
print(res.json())

Details and Documentation see docs

TODO LIST

  • audio transcription
  • video transcription

All Thanks To Our Contributors

License Information

This repository is licensed under the AnyParse Open Source License, based on Apache 2.0 with additional conditions.

Acknowledgments

Star History

Star History Chart

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

anyparse_python-1.1.2.tar.gz (264.0 kB view details)

Uploaded Source

Built Distribution

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

anyparse_python-1.1.2-py3-none-any.whl (305.0 kB view details)

Uploaded Python 3

File details

Details for the file anyparse_python-1.1.2.tar.gz.

File metadata

  • Download URL: anyparse_python-1.1.2.tar.gz
  • Upload date:
  • Size: 264.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for anyparse_python-1.1.2.tar.gz
Algorithm Hash digest
SHA256 34c3f93fe91f17dab9e584f12b6420b1a1a7fd37401c185ac2bd963420639720
MD5 4059b33360704c3cbf5ba697b73e012f
BLAKE2b-256 1dcfe166a9a04a06ce9f1441e1842c0d24ae7504781f77e4d9b43b07ba1ca495

See more details on using hashes here.

File details

Details for the file anyparse_python-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: anyparse_python-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 305.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for anyparse_python-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 019cb39c9d4e4bc531a26dd201b78f540eb4ff08064ba797f1bf88430c37c59d
MD5 aee9db1feea939587ed4654d6e86a934
BLAKE2b-256 70f7f2d33f7b656a1548100a53a33077314251fd62638a80e9920745accffd8b

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