To use this feature, you’ll need to install the beta version of the Go, JS, or Python SDK:
Go
JavaScript
Python
go get github.com/1password/onepassword-sdk-go@v0.4.1-beta.1
npm install @1password/sdk@0.4.1-beta.1
pip install onepassword-sdk==0.4.1b1
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:
Go
JavaScript
Python
package mainimport ( "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}
ES Modules
CommonJS
import sdk from "@1password/sdk";async function main() { const client = await sdk.createClient({ // TODO: Initialize client using your preferred authentication method (see Overview > Get started) }); // Your code here}main().catch(console.error);
const sdk = require("@1password/sdk");async function main() { const client = await sdk.createClient({ // TODO: Initialize client using your preferred authentication method (see Overview > Get started) }); // Your code here}main().catch(console.error);
import asynciofrom onepassword import Client # Also import DesktopAuth for desktop app authentication.async def main(): # TODO: Initialize client using your preferred authentication method (see Overview > Get started) client = await Client.authenticate(...) # Your code hereasyncio.run(main())
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"`}
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 statetype 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"`}
To read environment variables stored in an Environment, use the getVariables() method. Replace <your-environment-id> with the Environment’s ID.
const res = await client.environments.getVariables("<your-environment-id>");for (const env of res.variables) { console.log(`Variable ${env.name}: ${env.value} (hidden: ${env.masked})`);}
The method returns a GetVariablesResponse object that contains a list of the environment variables stored in the Environment.
/** Response containing the full set of environment variables from an Environment. */interface GetVariablesResponse { /** List of environment variables. */ variables: EnvironmentVariable[];}
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 */export interface EnvironmentVariable { /** An environment variable's name */ name: string; /** An environment variable's value */ value: string; /** An environment variable's masked state */ masked: boolean;}
To read environment variables stored in an Environment, use the get_variables() method. Replace ENVIRONMENT_ID with the Environment’s ID.
The method returns a GetVariablesResponse object that contains a list of the environment variables stored in the Environment.
class GetVariablesResponse(BaseModel): """ Response containing the full set of environment variables from an Environment. """ variables: List[EnvironmentVariable] """ List of environment variables. """
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.
class EnvironmentVariable(BaseModel): """ Represents an environment variable (name:value pair) and its masked state """ name: str """ An environment variable's name """ value: str """ An environment variable's value """ masked: bool """ An environment variable's masked state """
1Password Environment variables are masked by default. To change this:
Open and unlock the 1Password desktop app.
Select Developer > View Environments.
Choose the Environment, select Edit, then select the vertical ellipsis next to the variable and select Show value by default.