Skip to main content

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.

Release files for phase-dev 2.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for phase-dev 2.1.2
File Size Uploaded
phase_dev-2.1.2.tar.gz 21.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for phase-dev 2.1.2
File Interpreter ABI Platform
phase_dev-2.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 40.3 kB

Release files / phase_dev-2.1.2.tar.gz

Download URL phase_dev-2.1.2.tar.gz
Size 21.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a5f01c9eb102c497c54117d1080c675d4c6199586228340cab5f67623506d1e6
BLAKE2b-256 checksum
How to use checksums
5d31a2aeba2b3e72cfa405fa935a4eb58dcae84b81672810a01c7c9a776334eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release files / phase_dev-2.1.2-py3-none-any.whl

Download URL phase_dev-2.1.2-py3-none-any.whl
Size 19.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0fea83d7e3f57fa8903ae5d4af2820a9c91778caf242bc9b25e200b4a65c5de5
BLAKE2b-256 checksum
How to use checksums
10e2fea9f20df8191a86b0b2d20e8173bca0e1b6d2555d35afee77f2dc479c66
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

2.1.2 This release

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page