Skip to main content

Documentation Index

Fetch the complete documentation index at: https://www.1password.dev/llms.txt

Use this file to discover all available pages before exploring further.

Beta You can use 1Password SDKs to programmatically read environment variables stored in 1Password Environments (beta) and use them in your applications.

Requirements

To use this feature, you’ll need to install the beta version of the Go, JS, or Python SDK:
go get github.com/1password/onepassword-sdk-go@v0.4.1-beta.1
Before you begin, follow the steps to get started with a 1Password SDK. The examples on this page assume you have an initialized client instance. For example:
package main

import (
	"context"

	"github.com/1password/onepassword-sdk-go"
)

func main() {
	// TODO: Initialize client using your preferred authentication method (see Overview > Get started)
	client, err := onepassword.NewClient(context.Background(),
	)
	if err != nil {
		panic(err)
	}

	// Your code here
}

Read environment variables

To read environment variables stored in an Environment, use the GetVariables() method. Replace <your-environment-id> with the Environment’s ID.
res, err := client.Environments().GetVariables(context.Background(), "<your-environment-id>")
if err != nil {
	panic(err)
}
for _, env := range res.Variables {
	fmt.Printf("Variable %s: %s (hidden: %t)\n", env.Name, env.Value, env.Masked)
}
The method returns a GetVariablesResponse struct that contains a list of the environment variables stored in the Environment.
// Response containing the full set of environment variables from an Environment.
type GetVariablesResponse struct {
	// List of environment variables.
	Variables []EnvironmentVariable `json:"variables"`
}
Each EnvironmentVariable struct in the response contains the following:
  • Name: The environment variable’s name (for example, DB_HOST).
  • Value: The environment variable’s value.
  • Masked: A boolean that indicates whether the value is hidden by default in the 1Password app.
// Represents an environment variable (name:value pair) and its masked state
type EnvironmentVariable struct {
	// An environment variable's name
	Name string `json:"name"`
	// An environment variable's value
	Value string `json:"value"`
	// An environment variable's masked state
	Masked bool `json:"masked"`
}
1Password Environment variables are masked by default. To change this:
  1. Open and unlock the 1Password desktop app.
  2. Select Developer > View Environments.
  3. Choose the Environment, select Edit, then select the vertical ellipsis next to the variable and select Show value by default.

Appendix: Get an Environment’s ID

To read environment variables from a 1Password Environment, you’ll need its unique identifier (ID). You can find this ID in the 1Password desktop app:
  1. Open and unlock the 1Password desktop app.
  2. Navigate to Developer > View Environments.
  3. Select View environment next to the Environment you want to fetch.
  4. Select Manage environment > Copy environment ID.