2024.08.22

Golang & Python SDKs

Securely manage your application secrets programmatically with our new Golang and Python SDKs

We're excited to announce the release of native Golang and Python SDKs for Phase. These SDKs allow you to programmatically manage your application secrets with end-to-end encryption straight from your code.


SDK Features

Both SDKs offer a comprehensive set of features for managing secrets:

  • Create, read, update, and delete (CRUD) operations for secrets
  • End-to-end encryption
  • Full secret referencing
  • Bulk operations

Let's dive into some code examples to see these SDKs in action.

Golang SDK

Installation

First, install the SDK using go get:

go get github.com/phasehq/golang-sdk/phase

Usage Examples

Initialize the SDK:

phaseClient := phase.Init(serviceToken, "https://console.phase.dev", debug=false)

Create a secret:

opts := phase.CreateSecretsOptions{
    KeyValuePairs: []map[string]string{
        {"API_KEY": "my_secret_api_key"},
    },
    EnvName:    "Production",
    AppName:    "MyApp",
    SecretPath: map[string]string{"API_KEY": "/api/keys"},
}

err := phaseClient.Create(opts)

Retrieve a secret:

getOpts := phase.GetSecretOptions{
    EnvName:   "Production",
    AppName:   "MyApp",
    KeyToFind: "API_KEY",
}

secret, err := phaseClient.Get(getOpts)

Delete a secret:

deleteOpts := phase.DeleteSecretOptions{
    EnvName:     "Production",
    AppName:     "MyApp",
    KeyToDelete: "API_KEY",
    SecretPath:  "/api/keys",
}

err := phaseClient.Delete(deleteOpts)

Python SDK

Installation

Install the SDK using pip:

pip install phase-dev

Usage Examples

Initialize the SDK:

from phase import Phase

phase = Phase(
    host='https://console.phase.dev',
    pss=PHASE_SERVICE_TOKEN
)

Create secrets (bulk operation):

from phase import CreateSecretsOptions

create_options = CreateSecretsOptions(
    env_name="Development",
    app_name="MyApp",
    key_value_pairs=[
        {"API_KEY": "my_secret_api_key"},
        {"DB_PASSWORD": "super_secret_password"}
    ],
    secret_path="/api"
)
result = phase.create_secrets(create_options)

Retrieve all secrets:

from phase import GetAllSecretsOptions

get_options = GetAllSecretsOptions(
    env_name="Development",
    app_name="MyApp",
    tag="api",  # Optional: filter by tag
    secret_path="/api"
)
secrets = phase.get_all_secrets(get_options)

Delete a secret:

from phase import DeleteSecretOptions

delete_options = DeleteSecretOptions(
    env_name="Development",
    app_name="MyApp",
    key_to_delete="API_KEY",
    secret_path="/api"
)
result = phase.delete_secret(delete_options)

Secret Referencing

Both SDKs support secret referencing, allowing you to set the value of one secret to that of another. This is particularly useful for maintaining consistency across environments and avoiding repetition.


These new SDKs provide a powerful and flexible way to manage your application secrets programmatically. Whether you're working with Go or Python, you can now easily integrate Phase into your development workflow, ensuring that your secrets are always securely stored and easily accessible.

For more detailed information and additional features, please refer to the full documentation for the Golang SDK and Python SDK.

As always, we welcome your feedback and contributions. If you encounter any issues or have suggestions for improvements, please don't hesitate to reach out on our GitHub repository or Slack community.

Roadmap
Request a feature

We build features based on community requests and feedback. Looking for a specific feature or have a use-case in mind? Reach out to us.

Feature request
Deployment
Get started

Keep your secrets

Self-host or start on fully managed Cloud in under a minute.

Self-hosted

Run Phase on your own infrastructure. Free and open source.

AI agent deployment skill
$ npx skills add phasehq/ai
Cloud

Fully managed. From signup to your first secret in 60 seconds.

Sign up with