Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
2a741f6
Added example README. Edited example.py to resolve secret reference w…
moward98 Jan 30, 2025
4f142ab
Fixed yaml syntax error in validate.yml
moward98 Jan 30, 2025
a56053b
added installation of current directory before running example/exampl…
moward98 Jan 30, 2025
1433c45
Enforcing only one matrix combination runs at a time to avoid 409 Err…
moward98 Jan 31, 2025
03e4e6e
Edited README to better reflect what is actually happening in the exa…
moward98 Mar 3, 2025
5b39ca9
removed successful strings being printed by pipeline.
moward98 Mar 3, 2025
17f2110
fixed typo in readme
moward98 Mar 3, 2025
bd4355e
Updated to only run example file on ubuntu OS instead of all OS
moward98 Mar 4, 2025
2c82e55
Merge branch 'main' into morgan/150/example-test
moward98 Mar 4, 2025
154b71d
Updated example/README.md to capture example changes after latest rel…
moward98 Mar 4, 2025
df7cc3e
added requirements file to install packages that the example code req…
moward98 Mar 5, 2025
beb6293
Removed hardcoded instances of vault_id and replaced with vault_id va…
moward98 Mar 5, 2025
50b1b84
Merge branch 'main' into morgan/150/example-test
moward98 Mar 19, 2025
98a4ed6
removed max-parallel
moward98 Apr 11, 2025
c5f892c
Both instances of Example Test only run on ubuntu-latest
moward98 Apr 11, 2025
9a95f61
remove requrieement.txt and add python 3.13 and install right into th…
MOmarMiraj Apr 11, 2025
ac3b0f4
Merge remote-tracking branch 'origin' into morgan/150/example-test
MOmarMiraj Apr 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
max-parallel: 1
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
Expand All @@ -35,7 +36,13 @@ jobs:
pip install pytest-asyncio &&
pip install pydantic &&
python -m pytest src/onepassword/test_client.py

- name: Example Test
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.EXAMPLE_TESTS_OP_SERVICE_ACCOUNT_TOKEN }}
OP_VAULT_ID: ${{ secrets.EXAMPLE_TESTS_OP_VAULT_ID }}
run: |
pip install . &&
python example/example.py
lint:
name: Lint
runs-on: ubuntu-latest
Expand Down Expand Up @@ -97,6 +104,17 @@ jobs:
- run: |
echo "Integration tests completed successfully!"

- name: Example Test
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.TEST_SERVICE_ACCOUNT_TOKEN }}
OP_VAULT_ID: ${{ secrets.TEST_SERVICE_ACCOUNT_VAULT_ID }}
run: |
pip install . &&
python example/example.py

- run: |
echo "Example file ran successfully!"

# Update check run called "integration-fork" on the forked PR
- uses: actions/github-script@v6
id: update-check-run
Expand Down
15 changes: 15 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Examples

This folder contains a code snippet that demonstrates how to use the 1Password Python SDK to retrieve a secret from 1Password and export it as an environment variable.

## Prerequisites

1. Clone the repository and follow the steps to [get started](https://github.com/1Password/onepassword-sdk-python/blob/main/README.md).
2. Make sure to export a valid service account token. For example:
```bash
export OP_SERVICE_ACCOUNT_TOKEN="<your token>"
```
3. Make sure to export a valid vault uuid. For example:
```bash
export OP_VAULT_ID="<your vault uuid>"
```
16 changes: 10 additions & 6 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,16 @@ async def main():
print(error)
# [developer-docs.sdk.python.validate-secret-reference]-end

# [developer-docs.sdk.python.resolve-secret]-start
# 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)
# [developer-docs.sdk.python.resolve-secret]-end
vault_id= os.getenv("OP_VAULT_ID")
if vault_id is None:
raise Exception("OP_VAULT_ID environment variable is not set")

# [developer-docs.sdk.python.create-item]-start
# Create an Item and add it to your vault.
to_create = ItemCreateParams(
title="MyName",
category=ItemCategory.LOGIN,
vault_id="7turaasywpymt3jecxoxk5roli",
vault_id=vault_id,
fields=[
ItemField(
id="username",
Expand Down Expand Up @@ -91,6 +89,12 @@ async def main():

print(dict(created_item))

# [developer-docs.sdk.python.resolve-secret]-start
# Retrieves a secret from 1Password. Takes a secret reference as input and returns the secret to which it points.
value = await client.secrets.resolve(f"op://{created_item.vault_id}/{created_item.id}/username")
print(value)
# [developer-docs.sdk.python.resolve-secret]-end

# [developer-docs.sdk.python.resolve-totp-code]-start
# Retrieves a secret from 1Password. Takes a secret reference as input and returns the secret to which it points.
code = await client.secrets.resolve(
Expand Down
Loading