跳转到主要内容

读写 .netrc 文件。

项目描述

pypi badge travis-ci status

使用Python读写 .netrc 文件。

tinynetrc 使用标准库中的 netrc 模块,并增加了一些改进

  • 增加了写功能。

  • 修复了 std lib bug,用于格式化 .netrc 文件。

  • 将 .netrc 解析为字典值而不是元组。

*此 bug 已在 Python 的新版本中修复。

立即获取

pip install tinynetrc

tinynetrc 支持 Python >= 2.7 或 >= 3.5。

用法

from tinynetrc import Netrc

netrc = Netrc()  # parse ~/.netrc
# Get credentials
netrc['api.heroku.com']['login']
netrc['api.heroku.com']['password']

# Modify an existing entry
netrc['api.heroku.com']['password'] = 'newpassword'
netrc.save()  # writes to ~/.netrc

# Add a new entry
netrc['surge.surge.sh'] = {
    'login': 'sloria1@gmail.com',
    'password': 'secret'
}
netrc.save()

# Removing an new entry
del netrc['surge.surge.sh']
netrc.save()

您还可以使用 Netrc 作为上下文管理器,它将自动保存 ~/.netrc

from tinynetrc import Netrc
with Netrc() as netrc:
    netrc['api.heroku.com']['password'] = 'newpassword'
    assert netrc.is_dirty is True
# saved!

许可证

MIT 许可。有关详细信息,请参阅捆绑的 LICENSE 文件。

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面