Skip to main content

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 (PiperClient and get_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 PiperClient with your client_id and client_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.

🚀 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_ID
  • AGENT_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_prefix
  • env_variable_map
  • or use fallback_env_var_name in get_secret()

Return will include "source": "environment_variable".


🧯 Error Handling

Exception hierarchy:

  • PiperError (base)
    • PiperConfigError
    • PiperLinkNeededError
    • PiperAuthError
      • PiperGrantNeededError
      • PiperForbiddenError
    • 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


Download files

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

Source Distribution

pyper_sdk-0.4.0.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

pyper_sdk-0.4.0-py3-none-any.whl (20.5 kB view details)

Uploaded Python 3

File details

Details for the file pyper_sdk-0.4.0.tar.gz.

File metadata

  • Download URL: pyper_sdk-0.4.0.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pyper_sdk-0.4.0.tar.gz
Algorithm Hash digest
SHA256 80a2aec1267f7e505741a3489a11d758c330e34538c241bec651c6d62e413918
MD5 62320f246fbb9967c4f5bd6238aed32b
BLAKE2b-256 7e0d8f25b75476692253de56932a8223a782e99e0f7f20a924ff307763e5a835

See more details on using hashes here.

File details

Details for the file pyper_sdk-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: pyper_sdk-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 20.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for pyper_sdk-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9a7673f8e66baf0aa96865df2244df18587af3ba59f276ce1c3f8a64538d3e0
MD5 c6469d704acf97ae3d9e120ff94b5c1f
BLAKE2b-256 1c269ddaf73a9c54767a36446393189a4ec2bae52a24416619ab210c75bf7020

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