Metadata-Version: 2.4
Name: azure-keyvault-helper
Version: 0.1.0
Summary: A helper library for retrieving secrets from Azure Key Vault
Home-page: https://github.com/yourusername/azure-keyvault-helper
Author: Your Name
Author-email: your.email@example.com
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: azure-identity>=1.12.0
Requires-Dist: azure-keyvault-secrets>=4.5.0
Requires-Dist: python-dotenv>=0.19.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: black>=23.0.0; extra == "dev"
Requires-Dist: flake8>=6.0.0; extra == "dev"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# Azure Key Vault Helper

A Python helper library for easily retrieving secrets from Azure Key Vault with support for development and production environments.

## Features

- Simple interface for retrieving secrets from Azure Key Vault
- Automatic authentication using Azure Default Credentials
- Environment-aware: different behavior for development and production
- Fallback to environment variables when needed
- Batch secret retrieval support

## Installation

```bash
pip install azure-keyvault-helper
```

## Prerequisites

### For Local Development
- Azure CLI installed and logged in (`az login`)
- Or set environment variables:
  - `AZURE_CLIENT_ID`
  - `AZURE_TENANT_ID`
  - `AZURE_CLIENT_SECRET` (if using service principal)

### For Production
- Managed Identity enabled (when running in Azure)
- Or Service Principal configured with appropriate environment variables

## Configuration

Set the following environment variables:

- `KEYVAULT_URL`: The URL of your Azure Key Vault (e.g., `https://myvault.vault.azure.net/`)
- `ENVIRONMENT`: Set to `development` or `production` (defaults to `production`)

## Usage

### Basic Usage

```python
from azure_keyvault_helper import AzureKeyVaultHelper

# Initialize the helper
helper = AzureKeyVaultHelper()

# Get a single secret
secret_value = helper.get_secret("my-secret-name")
print(secret_value)
```

### Using Global Helper

```python
from azure_keyvault_helper import get_secret

# Automatically uses Key Vault or environment variables based on ENVIRONMENT
api_key = get_secret("api-key", fallback_env_var="API_KEY")
```

### Batch Retrieval

```python
from azure_keyvault_helper import AzureKeyVaultHelper

helper = AzureKeyVaultHelper()
secrets = helper.get_secrets_batch(["secret1", "secret2", "secret3"])
print(secrets)
```

### Environment-Aware Usage

The library behaves differently based on the `ENVIRONMENT` variable:

**Development Mode** (`ENVIRONMENT=development`):
- Prefers environment variables over Key Vault
- Useful for local development without Key Vault access

**Production Mode** (`ENVIRONMENT=production` or unset):
- Uses Azure Key Vault primarily
- Falls back to environment variables if Key Vault is unavailable

```python
import os
os.environ["ENVIRONMENT"] = "development"

from azure_keyvault_helper import get_secret

# In development: uses API_KEY env var if available
# In production: uses Key Vault secret "api-key", falls back to API_KEY env var
api_key = get_secret("api-key", fallback_env_var="API_KEY")
```

## Authentication

The library uses `DefaultAzureCredential` which tries multiple authentication methods in order:

1. **Environment variables** (for service principal)
2. **Managed Identity** (when running in Azure)
3. **Azure CLI** (when running locally and logged in)
4. **Visual Studio Code** (if using VS Code Azure extension)
5. **Azure PowerShell** (if authenticated)

## License

MIT

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

