| title | Keyring Demo | |||
|---|---|---|---|---|
| description | Small Python demo showing how to store and retrieve secrets in the OS credential store using keyring. | |||
| author | Keyring Demo Team | |||
| ms.date | 2026-07-22 | |||
| ms.topic | how-to | |||
| keywords |
|
|||
| estimated_reading_time | 3 |
This project demonstrates how to store and retrieve credentials in the OS credential store (Windows Credential Manager on Windows) by using the keyring library.
- Python 3.11+
- Windows (recommended for the Credential Manager flow used in this demo)
Quick bootstrap (recommended):
powershell -ExecutionPolicy Bypass -File .\scripts\bootstrap.ps1The bootstrap script creates .venv if needed, installs dependencies, and runs tests.
Manual setup:
- Create and activate a virtual environment.
- Install dependencies.
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txtRun the setup script and enter your username and password when prompted.
python -m secure_store.setup_secretsAlternate form (also supported): python secure_store/setup_secrets.py
The script stores:
usernamepassword
under the service name Keyring_Demo in the OS credential store.
python -m app.mainAlternate form (also supported): python app/main.py
Expected behavior:
- Prints a startup message
- Prints the username
- Prints password length (not the password itself)
pytestRun a single test:
pytest tests/test_secrets.py::test_round_tripIf python secure_store/setup_secrets.py does not prompt for input:
- Verify you are running from the repository root.
- Confirm your virtual environment is active:
.\.venv\Scripts\Activate.ps1. - Run the script with the active interpreter:
python secure_store/setup_secrets.py.
If you see ModuleNotFoundError: No module named 'keyring':
- Install dependencies:
pip install -r requirements.txt.
If tests fail because imports are not resolved:
- Run tests from the repository root.
- Use the venv interpreter explicitly:
.\.venv\Scripts\python.exe -m pytest.
If PowerShell blocks script execution:
- Use process-scope policy for the current terminal only:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy RemoteSigned. - Re-run bootstrap:
powershell -ExecutionPolicy Bypass -File .\scripts\bootstrap.ps1.
app/
main.py
secure_store/
manager.py
setup_secrets.py
tests/
test_secrets.py
requirements.txt
- Secrets are never committed to source control.
- Credentials are stored in the OS credential store at runtime.
- Core APIs are implemented in
secure_store/manager.py:get_secretset_secretrequire_secret