Skip to main content

AI-friendly secrets management CLI using OS-native keyring encryption

Project description

ai-secrets

AI-friendly secrets management CLI using OS-native encryption.

Supported Backends:
Windows Credential Manager • macOS Keychain • Linux Secret Service

Features

  • 🔒 Secure — OS-native keyring encryption
  • 🤖 AI-friendly — Consistent JSON with success flags, --reveal mode
  • 📊 Flexible — JSON, Table, and Bash output formats
  • 🎯 Type-safe — Full type hints and validation
  • Tested — 34 passing tests
  • 🚀 Simple — Clean API with proper error handling

Installation

# From PyPI
pip install ai-secrets

# Or with uv
uv pip install ai-secrets

# Development install
git clone https://github.com/BjornBethge/ai-secrets.git
cd ai-secrets
uv pip install -e .

Quick Start

# Store a secret
ai-secrets set HF_TOKEN "hf_your_token_here"

# Check if secret exists
ai-secrets get HF_TOKEN

# List all secrets (names only)
ai-secrets list

# AI-friendly: Get secret value in JSON
ai-secrets get HF_TOKEN --reveal -f json

# Delete secret
ai-secrets delete HF_TOKEN --yes

Note: The command secrets is also available as an alias for ai-secrets.

Commands

set — Store secret

ai-secrets set API_KEY "sk-1234" -f json
# {"success": true, "name": "API_KEY", "message": "..."}

get — Retrieve secret

# Check existence only
ai-secrets get API_KEY
# ✓ Secret 'API_KEY' exists

# For AI workflows (returns value in JSON)
ai-secrets get API_KEY --reveal -f json
# {"success": true, "name": "API_KEY", "exists": true, "value": "sk-1234"}

# For humans (prints to terminal)
ai-secrets get API_KEY --print

list — List all secrets

ai-secrets list -f json
# {"success": true, "secrets": ["API_KEY", "HF_TOKEN"], "count": 2}

delete — Delete secret

ai-secrets delete API_KEY --yes -f json
# {"success": true, "name": "API_KEY", "deleted": true}

status — Show manager status

ai-secrets status -f json
# {"success": true, "service_name": "ai-secrets", "secret_count": 3, ...}

export — Export as environment variables

# Bash format (prints export statements)
ai-secrets export -f bash
# export API_KEY=sk-1234
# export HF_TOKEN=hf_xxx

# JSON format
ai-secrets export -f json
# {"success": true, "secrets": {"API_KEY": "sk-1234", ...}, "count": 2}

AI-Friendly JSON

All JSON responses follow a consistent structure:

Success:

{
  "success": true,
  "name": "API_KEY",
  ...
}

Error:

{
  "success": false,
  "error": "Secret 'MISSING' not found",
  "name": "MISSING"
}

The --reveal flag:

  • Works only with -f json
  • Returns actual secret value
  • Designed for AI workflows where value is needed programmatically

Multi-Project Support

Use --service-name to isolate secrets per project:

# Production secrets
ai-secrets --service-name myapp-prod set DB_PASSWORD "secret"

# Development secrets  
ai-secrets --service-name myapp-dev set DB_PASSWORD "dev123"

# Custom metadata location
ai-secrets --service-name myapp --base-dir .secrets set API_KEY "key"

Python API:

from ai_secrets.storage import SecretsStore
from pathlib import Path

# Per-environment stores
prod_store = SecretsStore(service_name="myapp-prod")
dev_store = SecretsStore(service_name="myapp-dev", base_dir=Path(".secrets"))

# Set and get secrets
prod_store.set("API_KEY", "sk-prod-xxx")
print(prod_store.get("API_KEY"))  # "sk-prod-xxx"

# List all secret names
secrets = prod_store.list_names()  # ["API_KEY", ...]

# Export as dict
env_vars = prod_store.export_env()  # {"API_KEY": "sk-prod-xxx", ...}

# Delete a secret
prod_store.delete("API_KEY")

Direct keyring usage:

import keyring

# Store secret (basic keyring API)
keyring.set_password("myapp", "API_KEY", "secret-value")

# Get secret
value = keyring.get_password("myapp", "API_KEY")

# Delete secret
keyring.delete_password("myapp", "API_KEY")

Why use ai-secrets instead of raw keyring?

  • ✅ Secret name management (list all secrets)
  • ✅ Metadata tracking (knows what secrets exist)
  • ✅ Multi-environment support (--service-name)
  • ✅ JSON export for AI workflows
  • ✅ CLI convenience

Development

# Install dependencies
uv sync

# Run tests
uv run pytest tests/ -v

# Install in dev mode
uv pip install -e .

Notes

  • Default service name: ai-secrets (before v0.1.0: ai-keys)
  • Metadata stored in: ~/.secrets/metadata_<service-name>.json (only names, not values)
  • Secret values stored in: OS keyring (encrypted)
  • Each service has its own metadata file to avoid conflicts
  • export -f bash prints warning to stderr
  • Linux/KeePassXC: May prompt for database unlock

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ai_secrets-0.1.0.tar.gz (46.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ai_secrets-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file ai_secrets-0.1.0.tar.gz.

File metadata

  • Download URL: ai_secrets-0.1.0.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for ai_secrets-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5bb86123a3608ef1221c58d0cf88ed6508150720e272823c54341fc74b20772f
MD5 6799b53dabf5b2f7c664e7b189bb9ad3
BLAKE2b-256 e5a51b39d617f0ee8e7421be87b753f7ce9f73bde3bf779b0bd1d029e302c181

See more details on using hashes here.

File details

Details for the file ai_secrets-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ai_secrets-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for ai_secrets-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4cff5bda9ee7ccd3e5c7c68599bfe10b8663f2951cb5a23b077c827ac51f3ada
MD5 92ed48a2b57740d5f3a1a1ac21b99d9b
BLAKE2b-256 6a78d2949bf55bcead8c0894f3e639e1891eb9c45444e5dd814a89ba74c9be23

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page