diff --git a/example/README.md b/example/README.md new file mode 100644 index 00000000..bd8e45d2 --- /dev/null +++ b/example/README.md @@ -0,0 +1,11 @@ +# Examples + +This folder contains a code snippet that demonstrates how to use the 1Password Python SDK to retrieve a secret from 1Password. + +## Prerequisites + +1. Clone the repository and follow the steps to [get started](https://github.com/1Password/onepassword-sdk-python?tab=readme-ov-file#get-started). +2. Make sure to export a valid service account token. For example: + ```bash + export OP_SERVICE_ACCOUNT_TOKEN="" + ``` diff --git a/example/example.py b/example/example.py index 6be65087..8c35df33 100644 --- a/example/example.py +++ b/example/example.py @@ -6,10 +6,11 @@ async def main(): # Gets your service account token from the OP_SERVICE_ACCOUNT_TOKEN environment variable. token = os.getenv("OP_SERVICE_ACCOUNT_TOKEN") - # Connects to 1Password. + # Authenticates with your token and connects to 1Password. client = await Client.authenticate(auth=token, integration_name="My 1Password Integration", integration_version="v1.0.0") - # Retrieves a secret from 1Password. Takes a secret reference as input and returns the secret to which it points. + # Retrieves a secret from 1Password. + # Takes a secret reference as input and returns the secret to which it points. value = await client.secrets.resolve("op://vault/item/field") print(value)