处理OFX(开放金融交换)文件格式的工具
项目描述
ofxparse
ofxparse是用于解析开放金融交换(.ofx)格式文件的解析器。几乎任何在线银行网站都提供OFX文件,因此如果您想要从多个来源汇总您的财务信息,它们效果很好。在线交易账户也提供OFX格式的账户报表。
有三种不同类型的OFX文件,称为BankAccount、CreditAccount和InvestmentAccount文件。这个库已用所有三种类型的真实世界样本进行测试。如果您发现一个与该库不兼容的文件,请考虑贡献该文件,以便ofxparse可以得到改进。有关如何操作的说明,请参阅下面的“帮助!”部分。
示例用法
以下是一个示例程序
from ofxparse import OfxParser
with codecs.open('file.ofx') as fileobj:
ofx = OfxParser.parse(fileobj)
# The OFX object
ofx.account # An Account object
# AccountType
# (Unknown, Bank, CreditCard, Investment)
# Account
account = ofx.account
account.account_id # The account number
account.number # The account number (deprecated -- returns account_id)
account.routing_number # The bank routing number
account.branch_id # Transit ID / branch number
account.type # An AccountType object
account.statement # A Statement object
account.institution # An Institution object
# InvestmentAccount(Account)
account.brokerid # Investment broker ID
account.statement # An InvestmentStatement object
# Institution
institution = account.institution
institution.organization
institution.fid
# Statement
statement = account.statement
statement.start_date # The start date of the transactions
statement.end_date # The end date of the transactions
statement.balance # The money in the account as of the statement date
statement.available_balance # The money available from the account as of the statement date
statement.transactions # A list of Transaction objects
# InvestmentStatement
statement = account.statement
statement.positions # A list of Position objects
statement.transactions # A list of InvestmentTransaction objects
# Transaction
for transaction in statement.transactions:
transaction.payee
transaction.type
transaction.date
transaction.user_date
transaction.amount
transaction.id
transaction.memo
transaction.sic
transaction.mcc
transaction.checknum
# InvestmentTransaction
for transaction in statement.transactions:
transaction.type
transaction.tradeDate
transaction.settleDate
transaction.memo
transaction.security # A Security object
transaction.income_type
transaction.units
transaction.unit_price
transaction.comission
transaction.fees
transaction.total
transaction.tferaction
# Positions
for position in statement.positions:
position.security # A Security object
position.units
position.unit_price
position.market_value
# Security
security = transaction.security
# or
security = position.security
security.uniqueid
security.name
security.ticker
security.memo
帮助!
示例.ofx和.qfx文件非常有用。如果您想帮助我们,请从文件中编辑所有识别信息,然后将其通过电子邮件发送到jseutter dot ofxparse at gmail dot com。
开发
- 先决条件:
在Ubuntu上使用sudo apt-get install python-beautifulsoup python-nose python-coverage-test-runner安装BeautifulSoup4、six和lxml(Python 3,pip)。使用pip install BeautifulSoup4 six nose coverage安装BeautifulSoup4、six、nose和coverage(Python 2,pip)。
six包是Python 2.X兼容性所必需的。
测试:只需运行nosetests命令即可运行测试。
nosetests
如果您未安装nose,以下命令也可能有效。
python -m unittest tests.test_parse
测试覆盖率报告
coverage run -m unittest tests.test_parse
# text report
coverage report
# html report
coverage html
firefox htmlcov/index.html
主页
许可证
ofxparse遵循MIT许可协议。有关实际许可文本,请参阅LICENSE文件。基本想法是,如果您可以使用Python完成您的工作,您也可以使用这个库。
项目详情
ofxparse-0.21.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 057ab68d31270dece4d1a47662096aa76341968aaee145ffc711cb44cbd5c4a7 |
|
MD5 | defa68c6734b6121b4ea17f2ecf6b503 |
|
BLAKE2b-256 | 45ae98a2acfd06d15869c4b1be7fb74849c8a67cf15b65181f1fe879547e7494 |