从PostgreSQL密码文件获取密码的库
pgpasslib的Python项目详细描述
pgpasslib是从postgresql密码检索密码的库 文件,从PGPASSFILE环境中指定的位置 变量或在当前用户主目录中的.pgpass文件中。
安装
pgpasslib可以使用以下工具通过python包索引安装 你的选择。我更喜欢p i p:
pip install pgpasslib
要求
python标准库之外没有任何需求。
示例
以下示例将尝试获取PostgreSQL运行时的密码 作为postgres用户在localhost:5432到postgres数据库。
importpgpasslibpassword=pgpasslib.getpass('localhost',5432,'postgres','postgres')ifnotpassword:raiseValueError('Did not find a password in the .pgpass file')