keyringrs
A Python binding for keyring-rs.
While keyring is a great tool, it doesn't fully meet our general requirements due to the following reasons:
- Native Linux Keyutils Support: We need seamless integration with keyutils on Linux.
- Proper Memory Management on macOS: We perform numerous key queries, and keyring has known memory management issues on macOS (see issue jaraco/keyring #670).
- Headless Linux without dbus-x11: In CI, we test the secret-service on a headless linux (GitHub CI), the workaround starts the Gnome keyring unlocked with a known password from kering-rs CI works without
dbus-x11required.
The keyringrs is not plan as the alternative of keyring.
For CLI tool and more generic use cases I recommend to go to keyring.
Aside from our specific requirements with macOS and Linux keyutils, this library can serve as a backup solution if there are unresolved issues. While it doesn't guarantee a fix for the problems encountered, it can be a helpful tool to distinguish whether the issue stems from the library itself or from system configuration.
This library aims to maintain API compatibility with keyring-rs as closely as possible.
It therefore provide built-in support following platform-specific credential stores inherited from keyring-rs:
- Linux: The DBus-based Secret Service, the kernel keyutils, and a combo of the two (see below for example on how to control to use only
keyutils). - FreeBSD, OpenBSD: The DBus-based Secret Service.
- macOS, iOS: The local keychain.
- Windows: The Windows Credential Manager.
Installation
To install the package, simply run:
pip install keyringrs
Usage
Here's a quick example of how to use keyringrs.
For all platforms service-name and key-name are required fields to create a key entry to distinguish from other keys.
The target field is optional and depends on target platforms, please check docs from keyring-rs for particular cases:
from keyringrs import Entry
# Create an entry for the given service and username
# Or `entry = Entry("my-service-name", "my-key-name", target="my-target-name")`
entry = Entry("my-service-name", "my-key-name")
# Set a password
entry.set_password("0Xl$$K6o2bBwDe")
# Retrieve the password
password = entry.get_password()
print(f"My password is '{password}'")
# Delete the credential
entry.delete_credential()
In linux, by default it assume it used in a desktop distro with libdbus installed.
For the fallback support to use only keyutils, the key stored will disappear after reboot.
from keyringrs import Entry, CredentialType
# Create an entry use only keyutils in linux
entry = Entry("my-service-name", "my-key-name", credential_type=CredentialType.KeyUtils)
This interface follows the same logic as keyring-rs to ensure consistency and ease of use.
Checking keys on different platforms
tree layout
The repo organized using mixed rust/python layout.
.
├── Cargo.lock
├── Cargo.toml
├── README.md
├── keyringrs
│ └── __init__.py
├── pyproject.toml
├── src
│ └── lib.rs
├── tests
│ └── test_base.py
└── uv.lock
Ack
There was an effort five years ago with pyrust-keyring.
However, over the years, keyring-rs has gained more features, become more robust, and slightly diverged from the original keyring library.
It would be beneficial to have a proper wrapper for it.
Additionally, pyo3 has significantly improved, making it much easier to create wrappers and distribute the library on PyPI.
There is also a python wrapper python-linux-keyutils for linux-keyutils crate, which may provide more keyutils related APIs and error messages.
License
- Apache License, Version 2.0 (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or https://opensource.org/licenses/MIT)
Contributions
Unless you explicitly state otherwise, any contribution that you intentionally submit for inclusion in the Work, as defined in the Apache License, Version 2.0, shall be dual-licensed as described above, without additional terms or conditions.
Metadata
Release files for keyringrs 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| keyringrs-0.4.1.tar.gz | 37.9 kB | Details |
Built distributions (wheels)
Total release size: 9.6 MB
Release files / keyringrs-0.4.1.tar.gz
| Download URL | keyringrs-0.4.1.tar.gz |
|---|---|
| Size | 37.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6684e3d0ac70d2c3f0397b1295ae4b1f3bfe2fe889d0d61a0f980122ee0b534d
|
|
BLAKE2b-256 checksum How to use checksums |
0b19168f782a55f541ee236840b3ee95c82e7ec7a5fdeea3656ab8600ac66bb8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-win_amd64.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 155.3 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
986c823c4a3cbb68e50c1292a2d9820eaff0592c8b285059fac43fe331154508
|
|
BLAKE2b-256 checksum How to use checksums |
17700a9296ae475923970cfe46fba5324a0c3a5f0dcb639df05d8ad30f43756d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-win32.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-win32.whl |
|---|---|
| Size | 146.7 kB |
| Tags | CPython 3.9 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
8aa48dd24adb9affad3a8b92b1e679a6d9842521dfd80e4c650048dfb869af8e
|
|
BLAKE2b-256 checksum How to use checksums |
acbb0bfd7f6433dcca6bce126443eff6f5d827aa9de8ac32ef67b55b1af90bac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-musllinux_1_2_x86_64.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 979.9 kB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
d45d8a986f406805a5b9248563b9bf9ee32cbb7ef0d2aea412382b5c22bf7b2a
|
|
BLAKE2b-256 checksum How to use checksums |
7c173b761410ea15f84f99161f9aac0650298ad64e28364e4f4b7d3aa7f40ffd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-musllinux_1_2_i686.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-musllinux_1_2_i686.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
7d02f042ade096e110cb08d76a7802c241eb10fa3542cdfa2a3253d3081c1d4d
|
|
BLAKE2b-256 checksum How to use checksums |
af565a326b6ee923b69688aa0f7049d1e848de776ece6da984fe6f88da8448d0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-musllinux_1_2_armv7l.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 1.0 MB |
| Tags | CPython 3.9 Linux musl 1.2+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
cf33f9b5b3c0c75f2e0c648b495159d0ca7d0505c3822c71b2b01763d8ab74c0
|
|
BLAKE2b-256 checksum How to use checksums |
3cf7429944494a28cafe91949cc5b0bff123266b0717c70f3e8545df0e2b2927
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-musllinux_1_2_aarch64.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 938.1 kB |
| Tags | CPython 3.9 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
83e367c5a673508f697105b4f4e9808ec9f6d3e358c46e8704e8af4f30ce1a9f
|
|
BLAKE2b-256 checksum How to use checksums |
f752cb30fefae83a746f1892a4f0db00fa29aebbf57e7bb32e04e30213657d95
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 764.4 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
b04b7097bc655c8eaf6ed3f7ef95b2d246325c521016ae8963782be42ac29a6f
|
|
BLAKE2b-256 checksum How to use checksums |
45232c400e06434ece2a4cdc71f72b468d3a3065380a769a250caf9106b348d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 800.2 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
0a1499f1b1bbecd37a8cbe190b8c947807b83ccfaec1a46b0f2da0305e2c64ff
|
|
BLAKE2b-256 checksum How to use checksums |
9687d815b40e5daf641c7cc1cf77ccc6bee1d886d66f36cffe20b31da86aacf1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 933.9 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
9a0b01b4eeb6f1a572c13a94983263999af92a0d63337e02c8d9a3c1ed5d9a78
|
|
BLAKE2b-256 checksum How to use checksums |
856706b28ccc03b1281f572398755a69fe414ff1abaa2771ff2ac58c4aa055c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 736.8 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
a63d6b6f613b8ab3d0aa398912d6654c825512e0189707b4274479844c59d3ab
|
|
BLAKE2b-256 checksum How to use checksums |
da38eba7a0f9752cb46b142f613ebb424de36db64b4954712d5ef2cbe2fb9287
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 747.9 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
4aa20de874fa743f18522a013cc976498bb2b0c9039d80e4d7e65238c4d950a8
|
|
BLAKE2b-256 checksum How to use checksums |
8af4481c830210be0322ecf366738ad8ece05a90bcb2a4458b0e79650b8a49ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-manylinux_2_5_i686.manylinux1_i686.whl |
|---|---|
| Size | 829.0 kB |
| Tags | CPython 3.9 Linux glibc 2.5+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
28a51808722ae90ee2abbbb1e503a80f3ef448fb82fe051444611fbc288817cc
|
|
BLAKE2b-256 checksum How to use checksums |
3571e38f1419e68cfcf082001d56952e0d2c8474537c7a6b321b9f0165369140
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 259.8 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f71e2941f8c49d5b06e1b4601c858248ad2e78ec1f986828c70a435e5b4ef09f
|
|
BLAKE2b-256 checksum How to use checksums |
5e37dfe7d320943882c81e491b65fbeff5d61cdbd0ccc6f140e09e5a0e38b534
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / keyringrs-0.4.1-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | keyringrs-0.4.1-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 258.8 kB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
8353c2c0f1116733c6f54f83f590e1028eda0d3ebf3d9f9f43bea46611f168d3
|
|
BLAKE2b-256 checksum How to use checksums |
9670b2a124796acc418e67fc981cb2fde77f394ebfa5862333300a7f80a075c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|