Created
August 23, 2023 07:57
-
-
Save at-wr/ac3282475a8761e866712bf9dfa53ea0 to your computer and use it in GitHub Desktop.
Connect 1Password CLI with Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| import subprocess | |
| # Replace with 1Password Secret Reference (op://) | |
| username = "op://Your-Vault/Your-Item/Your-Username-Section" | |
| password = "op://Your-Vault/Your-Item/Your-Credential-Section" | |
| # Fetch with 1Password-CLI | |
| op_credentials = subprocess.check_output(f"op read {username} && op read {password}", shell=True, text=True) | |
| username = op_credentials.split('\n')[0] | |
| password = op_credentials.split('\n')[1] | |
| # Output | |
| print(f"Username: {username}\nPassword: {password}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment