I have an IBM Quantum account. How can I save the IBM Quantum API token to local environment so that I can access services including real quantum systems, simulators and Qiskit Runtime programs on my local machine using Qiskit?
Create an IBM Quantum account or log in to your existing account by visiting the IBM Quantum login page.
Copy (and/or optionally regenerate) your API token from your IBM Quantum account page.
Take your token from step 2, here called
MY_API_TOKEN, and run:
from qiskit import IBMQ IBMQ.save_account('MY_API_TOKEN')
The command above stores your credentials locally in a configuration file called
qiskitrc. By default, this file is located in
$HOMEis your home directory. If you are still using
Qconfig.py, please delete that file and run the command above.
See more info here: https://github.com/Qiskit/qiskit-ibmq-provider#setting-up-the-ibm-quantum-provider
You can use python Keyring package for storing and retrieving the secrets on local OS. It leverages the OS provided security and supports mac, windows and linux. This avoids token leak into plain text and notebooks.
If you are on windows os, you can store the credentials into windows credential manager and retrieve it using the
Storing token: (One time)
import keyring keyring.set_password("IBMQ", "ibmq-token", "the-token-goes-here")
retrieved_token = keyring.get_password("IBMQ", "ibmq-token")
Then perform login: