Skip to content

Instantly share code, notes, and snippets.

@at-wr
Created August 23, 2023 07:57
Show Gist options
  • Select an option

  • Save at-wr/ac3282475a8761e866712bf9dfa53ea0 to your computer and use it in GitHub Desktop.

Select an option

Save at-wr/ac3282475a8761e866712bf9dfa53ea0 to your computer and use it in GitHub Desktop.
Connect 1Password CLI with Python
#!/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