Skip to main content

文件解析器 (File Parser)

一个基于 Dify 项目文件处理功能抽离的通用文件解析器,支持多种文件格式转换为 AI 可识别的文本。

功能特性

  • 📄 支持多种文件格式:PDF、Word、Excel、PowerPoint、图片、文本等
  • 🔍 集成 OCR 技术,支持图片文字识别
  • 🚀 高性能异步处理
  • 🔧 模块化设计,易于扩展
  • 📝 统一的文本输出格式
  • 🛡️ 错误处理和日志记录

支持的文件格式

格式 扩展名 状态 说明
PDF .pdf ✅ 支持文本提取和 OCR
Word .docx, .doc ✅ 支持文档内容提取
Excel .xlsx, .xls ✅ 支持表格数据提取
PowerPoint .pptx, .ppt ✅ 支持幻灯片内容提取
图片 .jpg, .jpeg, .png, .bmp, .tiff ✅ 支持 OCR 文字识别
文本 .txt, .md ✅ 直接文本读取
CSV .csv ✅ 表格数据解析

快速开始

安装依赖

pip install -r requirements.txt

基本使用

from file_parser import FileParser

# 创建解析器实例
parser = FileParser()

# 解析单个文件
result = await parser.parse_file("document.pdf")
print(result.text)

# 批量解析文件
files = ["doc1.pdf", "doc2.docx", "image.png"]
results = await parser.parse_files(files)
for result in results:
    print(f"文件: {result.filename}")
    print(f"内容: {result.text[:100]}...")

项目结构

file-parser/
├── file_parser/           # 核心模块
│   ├── __init__.py
│   ├── base.py           # 基础解析器类
│   ├── parsers/          # 具体解析器实现
│   │   ├── __init__.py
│   │   ├── pdf_parser.py
│   │   ├── word_parser.py
│   │   ├── excel_parser.py
│   │   ├── ppt_parser.py
│   │   ├── image_parser.py
│   │   └── text_parser.py
│   ├── ocr/              # OCR 相关功能
│   │   ├── __init__.py
│   │   └── tesseract_ocr.py
│   └── utils/            # 工具函数
│       ├── __init__.py
│       └── file_utils.py
├── tests/                # 测试文件
├── examples/             # 示例代码
├── requirements.txt      # 依赖列表
└── README.md

许可证

MIT License

Metadata

Release files for dify-file-parser 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dify-file-parser 1.0.0
File Size Uploaded Provenance
dify_file_parser-1.0.0.tar.gz 8.5 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dify-file-parser 1.0.0
File Interpreter ABI Platform
dify_file_parser-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.6 MB

Release files / dify_file_parser-1.0.0.tar.gz

Download URL dify_file_parser-1.0.0.tar.gz
Size 8.5 MB
Tags Source
SHA-256 checksum
How to use checksums
996c20a02a0e2b547cc548502070124ebf4697408cecdc7d709826e59add59a4
BLAKE2b-256 checksum
How to use checksums
0ec7d3169183d90c38c09ae5213013a0a1666ab0cf917e58a3ac324ee672a059
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / dify_file_parser-1.0.0-py3-none-any.whl

Download URL dify_file_parser-1.0.0-py3-none-any.whl
Size 38.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
93a89fcb90f5b0d15eb65f16edb73e751cb8f0f6362068590e045e46ec63e09b
BLAKE2b-256 checksum
How to use checksums
348e6b87e8d6cc33e9ea42baa25686738ff43b02d13708e54a6034ce080fc9e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Security for dify-file-parser 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page