### Installing Python Dependencies (Fish) Source: https://github.com/phasehq/python-sdk/blob/main/CONTRIBUTING.md This command installs all Python packages listed in the `requirements.txt` file into the active virtual environment. It ensures all necessary project dependencies are met for the SDK. ```fish pip install -r requirements.txt ``` -------------------------------- ### Installing Phase Python SDK Source: https://github.com/phasehq/python-sdk/blob/main/README.md This command installs the Phase Python SDK using pip, the Python package installer. It's the first step to integrate Phase into your Python application. ```bash pip install phase-dev ``` -------------------------------- ### Creating a Virtual Environment (Fish) Source: https://github.com/phasehq/python-sdk/blob/main/CONTRIBUTING.md This command creates a new Python virtual environment named `.venv` in the current directory. Virtual environments help isolate project dependencies and ensure a clean development environment. ```fish python3 -m venv.venv ``` -------------------------------- ### Running Python Tests (Fish) Source: https://github.com/phasehq/python-sdk/blob/main/CONTRIBUTING.md This command executes the test suite for the project using `pytest`. The `-v` flag enables verbose output, showing detailed results for each test run. ```fish python -m pytest -v tests/ ``` -------------------------------- ### Importing Phase SDK Modules in Python Source: https://github.com/phasehq/python-sdk/blob/main/README.md This snippet imports the main `Phase` class and various options classes required for interacting with the Phase SDK, enabling operations like creating, getting, updating, and deleting secrets. ```python from phase import Phase, CreateSecretsOptions, GetAllSecretsOptions, GetSecretOptions, UpdateSecretOptions, DeleteSecretOptions ``` -------------------------------- ### Handling Errors with Phase SDK in Python Source: https://github.com/phasehq/python-sdk/blob/main/README.md This example shows how to implement basic error handling for Phase SDK calls using a `try-except` block. It catches `ValueError` exceptions, which may be raised by SDK methods for various error conditions, and prints the error message. ```python 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}") ``` -------------------------------- ### Managing PhaseHQ Secrets with Python SDK Source: https://github.com/phasehq/python-sdk/blob/main/CONTRIBUTING.md This comprehensive Python script demonstrates how to interact with the PhaseHQ API using the Python SDK to perform Create, Read, Update, and Delete (CRUD) operations on secrets. It initializes the `Phase` object, creates secrets with nested references, resolves those references, updates an existing secret, and deletes a secret. Constants for `CONSOLE_HOST`, `APP_NAME`, `ENV_NAME`, and `TOKEN` must be updated before execution. ```python from src.phase import Phase, CreateSecretsOptions, GetAllSecretsOptions, UpdateSecretOptions, DeleteSecretOptions CONSOLE_HOST = 'https://console.phase.dev' APP_NAME = '' ENV_NAME = "" TOKEN = '' # Initialize the Phase object with host and service token phase = Phase(init=False, pss=TOKEN, host=CONSOLE_HOST) # Create secrets with references create_options = CreateSecretsOptions( env_name=ENV_NAME, app_name=APP_NAME, key_value_pairs=[ {"BASE_URL": "https://api.example.com"}, {"API_ENDPOINT": "${BASE_URL}/v1/data"}, {"NESTED_REF": "Nested ${API_ENDPOINT}"} ] ) create_result = phase.create_secrets(create_options) print(f"Create secrets result: {create_result}") # Read and resolve references get_options = GetAllSecretsOptions( env_name=ENV_NAME, app_name=APP_NAME ) secrets = phase.get_all_secrets(get_options) resolved_secrets = phase.resolve_references(secrets, ENV_NAME, APP_NAME) print("\nResolved Secrets:") print("----------------") for secret in resolved_secrets: print(f"{secret.key}: {secret.value}") # Update secrets update_options = UpdateSecretOptions( env_name=ENV_NAME, app_name=APP_NAME, key="BASE_URL", value="https://api.acme.com", secret_path="/", destination_path="/", # Optional: move secret to a new path override=False, # Optional: create a personal override toggle_override=False # Optional: toggle personal override ) update_result = phase.update_secret(update_options) print(f"\nUpdate secrets result: {update_result}") print("----------------") ## Refetch secrets secrets = phase.get_all_secrets(get_options) resolved_secrets = phase.resolve_references(secrets, ENV_NAME, APP_NAME) print("\nResolved Secrets:") print("----------------") for secret in resolved_secrets: print(f"{secret.key}: {secret.value}") # Delete secrets delete_options = DeleteSecretOptions( env_name=ENV_NAME, app_name=APP_NAME, key_to_delete="BASE_URL", secret_path="/" ) result = phase.delete_secret(delete_options) print(f"Delete result: {result}") ## Refetch secrets secrets = phase.get_all_secrets(get_options) resolved_secrets = phase.resolve_references(secrets, ENV_NAME, APP_NAME) print("\nResolved Secrets:") print("----------------") for secret in resolved_secrets: print(f"{secret.key}: {secret.value}") ``` -------------------------------- ### Initializing Phase SDK in Python Source: https://github.com/phasehq/python-sdk/blob/main/README.md This code initializes the Phase SDK instance. It requires a `host` URL for the Phase platform and a `PHASE_SERVICE_TOKEN` for authentication. The `init=False` parameter indicates that the SDK should not automatically initialize, allowing for manual configuration. ```python phase = Phase( init=False, host='https://your-phase-host.com', pss=PHASE_SERVICE_TOKEN ) ``` -------------------------------- ### Creating Multiple Secrets with Phase SDK in Python Source: https://github.com/phasehq/python-sdk/blob/main/README.md This snippet demonstrates how to create one or more secrets using the `create_secrets` method. It requires specifying the environment name, application name, and a list of key-value pairs for the secrets. An optional `secret_path` can be provided to organize secrets within a specific path. ```python 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}") ``` -------------------------------- ### Retrieving All Secrets with Phase SDK in Python Source: https://github.com/phasehq/python-sdk/blob/main/README.md This code fetches all secrets for a specified application and environment using `get_all_secrets`. It supports optional filtering by `tag` and `secret_path` to narrow down the results. The retrieved secrets are then iterated and printed. ```python 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}") ``` -------------------------------- ### Retrieving a Specific Secret with Phase SDK in Python Source: https://github.com/phasehq/python-sdk/blob/main/README.md This snippet demonstrates how to retrieve a single secret by its key using the `get_secret` method. It requires the environment name, application name, and the `key_to_find`. An optional `secret_path` can be provided if the secret is located within a specific path. ```python 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}") ``` -------------------------------- ### Updating an Existing Secret with Phase SDK in Python Source: https://github.com/phasehq/python-sdk/blob/main/README.md This code updates an existing secret using the `update_secret` method. It requires the environment, application, key, and new value. Optional parameters include `secret_path` for the current location, `destination_path` to move the secret, and flags for personal overrides. ```python 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}") ``` -------------------------------- ### Deleting a Secret with Phase SDK in Python Source: https://github.com/phasehq/python-sdk/blob/main/README.md This snippet demonstrates how to delete a specific secret using the `delete_secret` method. It requires the environment name, application name, and the `key_to_delete`. An optional `secret_path` can be provided if the secret is located within a specific path. ```python 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}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.