Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
python
keyring
windows credential manager
estimated_reading_time 3

CI Python Tests

Overview

This project demonstrates how to store and retrieve credentials in the OS credential store (Windows Credential Manager on Windows) by using the keyring library.

Prerequisites

  • Python 3.11+
  • Windows (recommended for the Credential Manager flow used in this demo)

Setup

Quick bootstrap (recommended):

powershell -ExecutionPolicy Bypass -File .\scripts\bootstrap.ps1

The bootstrap script creates .venv if needed, installs dependencies, and runs tests.

Manual setup:

  1. Create and activate a virtual environment.
  2. Install dependencies.
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt

Configure Secrets

Run the setup script and enter your username and password when prompted.

python -m secure_store.setup_secrets

Alternate form (also supported): python secure_store/setup_secrets.py

The script stores:

  • username
  • password

under the service name Keyring_Demo in the OS credential store.

Run the App

python -m app.main

Alternate form (also supported): python app/main.py

Expected behavior:

  • Prints a startup message
  • Prints the username
  • Prints password length (not the password itself)

Run Tests

pytest

Run a single test:

pytest tests/test_secrets.py::test_round_trip

Troubleshooting

If 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.

Project Structure

app/
  main.py
secure_store/
  manager.py
  setup_secrets.py
tests/
  test_secrets.py
requirements.txt

Notes

  • 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_secret
    • set_secret
    • require_secret

About

Demonstrates how to use keyring in python instead of a .env file for secrets

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages