Skip to main content

Python SDK for Phase secrets manager

Project description

Python SDK for Phase

SDK to integrate Phase in server-side applications running Python. This SDK allows you to manage secrets securely using the Phase platform.

Install

pip install phase-dev

Import

from phase import Phase, CreateSecretsOptions, GetAllSecretsOptions, GetSecretOptions, UpdateSecretOptions, DeleteSecretOptions

Initialize

Initialize the SDK with your host and token:

phase = Phase(
    init=False,
    host='https://your-phase-host.com',
    pss=PHASE_SERVICE_TOKEN

)

Usage

Create Secrets

Create one or more secrets in a specified application and environment:

create_options = CreateSecretsOptions(
    env_name="Development",
    app_name="Your App Name",
    key_value_pairs=[
        {"API_KEY": "your-api-key"},
        {"DB_PASSWORD": "your-db-password"}
    ],
    secret_path="/api"
)
result = phase.create_secrets(create_options)
print(f"Create secrets result: {result}")

Get Secrets

Fetch one or more secrets from a specified application and environment:

get_options = GetAllSecretsOptions(
    env_name="Development",
    app_name="Your App Name",
    tag="api",  # Optional: filter by tag
    secret_path="/api"  # Optional: specify path
)
secrets = phase.get_all_secrets(get_options)
for secret in secrets:
    print(f"Key: {secret.key}, Value: {secret.value}")

To get a specific secret:

get_options = GetSecretOptions(
    env_name="Development",
    app_name="Your App Name",
    key_to_find="API_KEY",
    secret_path="/api"
)
secret = phase.get_secret(get_options)
if secret:
    print(f"Key: {secret.key}, Value: {secret.value}")

Update Secrets

Update an existing secret in a specified application and environment:

update_options = UpdateSecretOptions(
    env_name="Development",
    app_name="Your App Name",
    key="API_KEY",
    value="new-api-key-value",
    secret_path="/api",
    destination_path="/new-api",  # Optional: move secret to a new path
    override=False,  # Optional: create a personal override
    toggle_override=False  # Optional: toggle personal override
)
result = phase.update_secret(update_options)
print(f"Update result: {result}")

Delete Secrets

Delete a secret from a specified application and environment:

delete_options = DeleteSecretOptions(
    env_name="Development",
    app_name="Your App Name",
    key_to_delete="API_KEY",
    secret_path="/api"
)
result = phase.delete_secret(delete_options)
print(f"Delete result: {result}")

Error Handling

The SDK methods may raise exceptions for various error conditions. It's recommended to wrap SDK calls in try-except blocks to handle potential errors:

try:
    get_options = GetAllSecretsOptions(env_name="Development", app_name="Your App Name")
    secrets = phase.get_all_secrets(get_options)
except ValueError as e:
    print(f"An error occurred: {e}")

Note on Security

Never hard-code sensitive information like tokens or secrets directly in your code. Always use environment variables or secure configuration management to provide these values to your application.

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

phase_dev-2.1.1.tar.gz (21.5 kB view details)

Uploaded Source

Built Distribution

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

phase_dev-2.1.1-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

Details for the file phase_dev-2.1.1.tar.gz.

File metadata

  • Download URL: phase_dev-2.1.1.tar.gz
  • Upload date:
  • Size: 21.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for phase_dev-2.1.1.tar.gz
Algorithm Hash digest
SHA256 d3bccc7bf41d1542bcecf5c4ff87f5b4b2142ce331872b0e2348c691130d69ec
MD5 9b0da37946bf0f1d1ae623465d4f08c0
BLAKE2b-256 c21650a16219f883266d09d66dd8e95f27bf3ccca6899e50fe2d8aefb2671f15

See more details on using hashes here.

File details

Details for the file phase_dev-2.1.1-py3-none-any.whl.

File metadata

  • Download URL: phase_dev-2.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for phase_dev-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1c188c962263a2de182df32166669f71e2e3f8af43755f35e2b71385c5bc7a48
MD5 596ecf26b65d8b8faf8c7173984f3401
BLAKE2b-256 8513465abfa710be81c0acba7cb1afefe1a4c566d8340cfc0bd8c9f4b05a45fd

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