Python SDK for Piper Agent Credential Management with environment fallback.
Project description
🛡️ Pyper SDK: Simple & Secure Access to User-Approved Secrets
Empower your Python applications to securely use your users' API keys and credentials — without the risk or hassle of handling raw secrets directly.
✨ Why Pyper SDK?
-
🔐 Offload Secret Management
Let the Piper system handle user secrets like OpenAI keys, Notion tokens, and database credentials. No need to store or manage them yourself. -
🛡️ Enhance Trust & Security
Users explicitly grant your app permission via their Piper dashboard. Secrets are accessed securely with temporary tokens or encrypted raw secrets. -
💡 Clean Developer Experience
A simple and powerful API (PiperClientandget_secret()) makes integration a breeze. -
🔄 Smart Context Handling
Supports automatic local context detection via the Piper Link desktop app and external context IDs for remote services. -
🧩 Progressive Adoption
Built-in environment variable fallback ensures functionality for users not yet using Piper.
🔁 Core Flow
1. User Setup (Handled by Piper)
- Users store secrets in their Piper account.
- They grant your app ("Agent") permission to access specific secrets, mapped to logical names.
- For local usage, users run the Piper Link app to securely share context.
2. App Flow (Using Pyper SDK)
- Initialize
PiperClientwith yourclient_idandclient_secret. - Request secrets using logical variable names your app expects.
- Receive either:
- 🔁 STS token (
piper_sts) — secure, indirect access. - 🔓 Raw secret (
piper_raw_secret) — if explicitly requested.
- 🔁 STS token (
🚀 Installation
pip install pyper-sdk
Requires Python 3.8+
🛠️ Getting Started
1. Register Your App
Create an Agent on Piper Console. You'll receive:
AGENT_CLIENT_IDAGENT_CLIENT_SECRET(store securely)
2. Initialize PiperClient
import os
from piper_sdk.client import PiperClient, PiperConfigError
AGENT_CLIENT_ID = os.environ.get("MY_AGENT_CLIENT_ID")
AGENT_CLIENT_SECRET = os.environ.get("MY_AGENT_CLIENT_SECRET")
EXCHANGE_SECRET_URL = os.environ.get("PIPER_EXCHANGE_URL")
try:
piper_client = PiperClient(
client_id=AGENT_CLIENT_ID,
client_secret=AGENT_CLIENT_SECRET,
exchange_secret_url=EXCHANGE_SECRET_URL # Optional, for raw secrets
)
print("PiperClient ready.")
except PiperConfigError as e:
print(f"Configuration error: {e}")
except Exception as e:
print(f"Unexpected error: {e}")
3. Request Secrets
if piper_client:
try:
secret_info = piper_client.get_secret("DATABASE_PASSWORD", fetch_raw_secret=True)
if secret_info.get("source") == "piper_raw_secret":
db_password = secret_info["value"]
print("Retrieved raw secret via Piper.")
elif secret_info.get("source") == "environment_variable":
db_password = secret_info["value"]
print(f"Fallback to environment variable: {secret_info['env_var_name_found']}")
except PiperLinkNeededError:
print("⚠️ Piper Link is not running. Please start the desktop app.")
except PiperGrantNeededError as e:
print(f"Permission needed for secret: {e}")
except PiperRawSecretExchangeError as e:
print(f"Exchange error: {e}")
except PiperAuthError as e:
print(f"Auth error: {e}")
except PiperError as e:
print(f"Piper SDK error: {e}")
except Exception as e:
print(f"Unknown error: {e}")
🌐 User Context (instanceId)
- Local (Auto): Piper Link provides context automatically.
- Remote (Manual): Supply your own
instanceId:
piper_client = PiperClient(
client_id=AGENT_CLIENT_ID,
client_secret=AGENT_CLIENT_SECRET,
piper_link_instance_id="ctx_id_from_platform",
auto_discover_instance_id=False,
exchange_secret_url=EXCHANGE_SECRET_URL
)
🌱 Environment Variable Fallback
If secrets can't be retrieved via Piper, the SDK will fall back to environment variables (enabled by default).
You can configure:
env_variable_prefixenv_variable_map- or use
fallback_env_var_nameinget_secret()
Return will include "source": "environment_variable".
🧯 Error Handling
Exception hierarchy:
PiperError(base)PiperConfigErrorPiperLinkNeededErrorPiperAuthErrorPiperGrantNeededErrorPiperForbiddenError
PiperRawSecretExchangeError
Use try...except to gracefully handle errors and guide users.
🎯 Our Mission
Pyper SDK is built to make secure, user-consented access to credentials effortless for developers — and safer for users — in a world of growing AI and data integrations.
🤝 Contributing
Found a bug or have a feature request?
Please open an issue or PR at GitHub → Pyper SDK
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyper_sdk-0.4.3.tar.gz.
File metadata
- Download URL: pyper_sdk-0.4.3.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7be4cea35822b69147a95c88a01df98e9f9b51eefb8ac5a0f23b3edbfa07af3
|
|
| MD5 |
530d2c52e71b033780e3a2485467159b
|
|
| BLAKE2b-256 |
35b9991e9dccc287e70a8e8cd4107bb1c57a782cfa20bf36dad806ed7b59b511
|
File details
Details for the file pyper_sdk-0.4.3-py3-none-any.whl.
File metadata
- Download URL: pyper_sdk-0.4.3-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1c37bf51ad1b137137a8802d420d810a1b64092f204f313482abbf5cade853f
|
|
| MD5 |
40ca5ec30ff90071f50c8053a4ba133a
|
|
| BLAKE2b-256 |
f8a05610d8f28a3f01e8c8c1417b4c25b33c87b07538b77d7004bbc0f494b1de
|