Skip to main content

一个用于解析财务报表的 Python 包

Project description

Financial Report Parser

一个用于解析财务报表的 Python 包,支持从 PDF 文件中提取和分析财务数据。

功能特性

  • 📄 PDF 解析: 使用 pdfplumber 解析财务报表 PDF 文件
  • 📊 表格识别: 自动识别资产负债表、利润表、现金流量表
  • 🔍 数据提取: 提取关键财务指标和数值
  • 数据校验: 提供字段完整性检查
  • 📈 JSON 输出: 将解析结果输出为结构化 JSON 数据
  • 🖥️ 命令行工具: 提供便捷的命令行接口

安装

pip install financial-report-parser

快速开始

命令行使用

# 解析 PDF 文件
financial-parser parse financial_report.pdf

# 输出到 JSON 文件
financial-parser parse financial_report.pdf --output result.json

Python API 使用

from financial_report_parser import FinancialReportParser, read_pdf_file

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

# 读取 PDF 文件
pdf_content = read_pdf_file("financial_report.pdf")

# 解析财务数据
result = parser.parse_pdf(pdf_content)

# 查看解析结果
print(result)

支持的财务表格

资产负债表

  • 货币资金
  • 应收账款
  • 存货
  • 固定资产
  • 应付账款
  • 股本
  • 未分配利润
  • 盈余公积

利润表

  • 营业收入
  • 营业成本
  • 营业利润
  • 利润总额
  • 净利润

现金流量表

  • 经营活动现金流量净额
  • 投资活动现金流量净额
  • 筹资活动现金流量净额
  • 现金及现金等价物净增加额

输出格式

解析结果包含以下信息:

{
    "content_size": 1096757,
    "file_type": "PDF",
    "status": "success",
    "total_pages": 161,
    "pages": [
        {
            "page_number": 1,
            "text": "财务报表内容...",
            "tables": [...],
            "width": 595.3,
            "height": 841.9
        }
    ],
    "report_json": {
        "balance_sheet": {...},
        "profit_statement": {...},
        "cash_flow_statement": {...}
    }
}

数据校验

包内置数据校验功能,检查:

  • 字段完整性
  • 数据质量评分
  • 校验结果包含错误和警告信息

系统要求

  • Python >= 3.9
  • pdfplumber >= 0.11.7

开发

安装开发依赖

# 克隆仓库
git clone <repository-url>
cd financial-report-parser

# 安装 Poetry
pip install poetry

# 安装依赖
poetry install

运行测试

python financial_report_parser/test.py

许可证

MIT License

作者

贡献

欢迎提交 Issue 和 Pull Request!

更新日志

v0.1.1

  • 增强字段标准化功能
    • 支持中文数字前缀去除(如"(一)基本每股收益" → "基本每股收益")
    • 支持括号内容去除(如"汇兑收益(损失以"-"号填列)" → "汇兑收益")
    • 改进引号类型处理,支持中英文引号统一
  • 优化表格类型识别
    • 添加往前推断逻辑,通过表格上方文本验证表类型
    • 提高利润表、资产负债表、现金流量表的识别准确性
  • 完善字段映射
    • 扩展现金流量表和资产负债表字段映射
    • 增加银行类金融机构特有字段支持
    • 确保字段标准化映射与 indicators.py 保持一致
  • 改进输出格式
    • 分离资产负债表、利润表、现金流量表为独立对象
    • 添加表格位置信息(坐标、页码、边界框等)
    • 减少调试输出,优化用户体验
  • 性能优化
    • 修复内存使用效率问题
    • 优化多页表格合并逻辑
    • 改进边界框搜索算法

v0.1.0

  • 初始版本发布
  • 支持 PDF 财务报表解析
  • 提供命令行工具和 Python API
  • 内置数据校验功能

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

financial_report_parser-0.1.1.tar.gz (927.4 kB view details)

Uploaded Source

Built Distribution

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

financial_report_parser-0.1.1-py3-none-any.whl (933.1 kB view details)

Uploaded Python 3

File details

Details for the file financial_report_parser-0.1.1.tar.gz.

File metadata

  • Download URL: financial_report_parser-0.1.1.tar.gz
  • Upload date:
  • Size: 927.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for financial_report_parser-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fcca4d158da0d55336fa8cabe9cd4aff906df8fb3276023bdf69cb337929f5a5
MD5 e25bc6ec8d283fe342d2b51fdc4a4117
BLAKE2b-256 42d1d01cd56782065279f4f471d0f4a8d8b9af4674609db551f61474e296d053

See more details on using hashes here.

File details

Details for the file financial_report_parser-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for financial_report_parser-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2c8ff099f2e81c1aa4ef7e2d8966c9f4edfd63970fc2ddae620281cdd1b6b447
MD5 de6a6b338bd065741cd75a83fe4d5033
BLAKE2b-256 290de7e3004298d675b2255b3fffb3a7db31f5293f7022c1152bbaf48a838da9

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