用于keepasshttp与keepass凭据交互的python客户端
keepasshttp的Python项目详细描述
保持http
用于KeePassHTTP与KeePass的凭据交互的python客户端。
安装
$ pip install keepasshttp
用法
import keepasshttp
# get single credential
credential = keepasshttp.get("my_credential_name_or_url")
print(credential.login)
print(credential.password)
# find all credentials's name
credentials = keepasshttp.list()
# fetch all partiall matching credentials
credentials = keepasshttp.search("my_credential_name_or_url")
# create a new keepasshttp entry
keepasshttp.create("login", "password", "url")
# update a keepasshttp entry
credential.password = "new password"
# or
keepasshttp.update("login", "password", "url", "uuid")
命令行
keepasshttp也可以从命令行调用:
$ python -m keepasshttp --help
usage: keepasshttp [-h] [-c CONFIG_PATH] [-u URL]
[-f {python,text,table,json,csv}]
credential [credential ...]
Fetch credentials from keepass
positional arguments:
credential Url or name to match credentials from keepass database
optional arguments:
-h, --help show this help message and exit
-c CONFIG_PATH, --config CONFIG_PATH
alternative path for keepasshttp's AES exchange key
(default: ~/.python_keepass_http)
-u URL, --url URL alternative url for keepasshttp server (default:
'http://localhost:19455/')
-f {python,text,table,json,csv}, --format {python,text,table,json,csv}
output format for credentials
$ python -m keepathhttp my_credential_name_or_url
my_credential_name_or_url
- login: login
- password: password
- name: test
- url: my_credential_name_or_url
- id: ABCDEF1234567890ABCDEF1234567890
- fields: []
配置
默认情况下,此模块将把AES关联密钥写入~/.python_keepass_http
并使用http://localhost:19455/
连接到KeePassHTTP服务器。
要更改这些参数,请使用不同的值实例化keepasshttp.KeePassHTTP
类。
from keepasshttp import KeePassHTTP
kph = KeePassHTTP(
storage="./keepasshttp_key",
url="https://example.com:1337/")
kph.get("...")
...
测试
您只需使用:
python -m unittest discover
KeePassHTTP
调用是模拟的,要对真正的服务器运行测试,您需要:
- 在
KeePass
中打开tests/test_database.kdbx
密码是test
- 设置环境变量
TEST_WITH_KEEPASS
- 正常运行测试
覆盖范围
运行覆盖率测试:
pip install pytest-cov
pytest --cov